Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Sherry Zhang | 6e0f324 | 2021-03-08 12:18:31 +0800 | [diff] [blame] | 2 | # Copyright (c) 2020-2021, Arm Limited. All rights reserved. |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 8 | cmake_minimum_required(VERSION 3.15) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 9 | |
| 10 | project("Bootloader" VERSION 0.1.0 LANGUAGES C ASM) |
| 11 | |
| 12 | add_executable(bl2 |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 13 | src/flash_map.c |
Mark Horvath | 8576e38 | 2021-03-12 10:24:55 +0100 | [diff] [blame^] | 14 | $<$<BOOL:${DEFAULT_MCUBOOT_SECURITY_COUNTERS}>:src/security_cnt.c> |
| 15 | $<$<BOOL:${DEFAULT_MCUBOOT_FLASH_MAP}>:src/default_flash_map.c> |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 16 | $<$<BOOL:${MCUBOOT_DATA_SHARING}>:src/shared_data.c> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 17 | ) |
| 18 | |
| 19 | add_subdirectory(ext/mcuboot) |
| 20 | |
| 21 | set_target_properties(bl2 |
| 22 | PROPERTIES |
| 23 | SUFFIX ".axf" |
| 24 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" |
| 25 | ) |
| 26 | |
| 27 | target_include_directories(bl2 |
| 28 | PRIVATE |
| 29 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
Sherry Zhang | 6e0f324 | 2021-03-08 12:18:31 +0800 | [diff] [blame] | 30 | $<BUILD_INTERFACE:${MCUBOOT_PATH}/boot/bootutil/src> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | target_link_libraries(bl2 |
| 34 | PRIVATE |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 35 | tfm_boot_status |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | target_link_options(bl2 |
| 39 | PRIVATE |
| 40 | $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/bl2.map> |
| 41 | $<$<C_COMPILER_ID:ARMClang>:--map> |
TTornblom | af19ae9 | 2020-09-29 13:26:29 +0200 | [diff] [blame] | 42 | $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/bl2.map> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 43 | ) |
| 44 | |
Mark Horvath | 8576e38 | 2021-03-12 10:24:55 +0100 | [diff] [blame^] | 45 | target_compile_definitions(bl2 |
| 46 | PRIVATE |
| 47 | $<$<BOOL:${DEFAULT_MCUBOOT_FLASH_MAP}>:DEFAULT_MCUBOOT_FLASH_MAP> |
| 48 | ) |
| 49 | |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 50 | add_convert_to_bin_target(bl2) |
| 51 | |
| 52 | ############################### BOOT HAL # ##################################### |
| 53 | |
| 54 | add_library(bl2_hal INTERFACE) |
| 55 | |
| 56 | target_include_directories(bl2_hal |
| 57 | INTERFACE |
| 58 | include |
| 59 | ) |
| 60 | |
| 61 | ############################### MBEDCRYPTO ##################################### |
| 62 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 63 | add_library(bl2_mbedcrypto_config INTERFACE) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 64 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 65 | target_compile_definitions(bl2_mbedcrypto_config |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 66 | INTERFACE |
| 67 | $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA> |
| 68 | $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA_LEN=${MCUBOOT_SIGNATURE_KEY_LEN}> |
Ioannis Glaropoulos | 855321a | 2021-05-11 12:44:39 +0200 | [diff] [blame] | 69 | MBEDTLS_CONFIG_FILE="${MCUBOOT_MBEDCRYPTO_CONFIG_FILEPATH}" |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 70 | # Workaround for https://github.com/ARMmbed/mbedtls/issues/1077 |
| 71 | $<$<OR:$<STREQUAL:${CMAKE_SYSTEM_ARCHITECTURE},armv8-m.base>,$<STREQUAL:${CMAKE_SYSTEM_ARCHITECTURE},armv6-m>>:MULADDC_CANNOT_USE_R7> |
| 72 | ) |
| 73 | |
| 74 | cmake_policy(SET CMP0079 NEW) |
| 75 | |
| 76 | set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) |
| 77 | set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) |
| 78 | set(ENABLE_TESTING OFF) |
| 79 | set(ENABLE_PROGRAMS OFF) |
| 80 | set(MBEDTLS_FATAL_WARNINGS OFF) |
| 81 | set(ENABLE_DOCS OFF) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 82 | set(INSTALL_MBEDTLS_HEADERS OFF) |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 83 | set(LIB_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto/install) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 84 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 85 | set(lib_target bl2_mbedcrypto_libs) |
| 86 | set(mbedcrypto_target bl2_mbedcrypto) |
| 87 | set(mbedtls_target bl2_mbedtls) |
| 88 | set(mbedx509_target bl2_mbedx509) |
| 89 | set(MBEDTLS_TARGET_PREFIX bl2_) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 90 | |
| 91 | # Mbedcrypto is quite a large lib, and it uses too much memory for it to be |
| 92 | # reasonable to build it in debug info. As a compromise, if `debug` build type |
| 93 | # is selected mbedcrypto will build under `relwithdebinfo` which preserved debug |
| 94 | # symbols whild optimizing space. |
| 95 | set(SAVED_BUILD_TYPE ${CMAKE_BUILD_TYPE}) |
| 96 | set(CMAKE_BUILD_TYPE ${MBEDCRYPTO_BUILD_TYPE}) |
| 97 | add_subdirectory(${MBEDCRYPTO_PATH} ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto) |
| 98 | set(CMAKE_BUILD_TYPE ${SAVED_BUILD_TYPE} CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE) |
| 99 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 100 | if(NOT TARGET bl2_mbedcrypto) |
| 101 | message(FATAL_ERROR "Target bl2_mbedcrypto does not exist. Have the patches in ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH} ? |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 102 | Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") |
| 103 | endif() |
| 104 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 105 | target_link_libraries(bl2_mbedcrypto |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 106 | PUBLIC |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 107 | bl2_mbedcrypto_config |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 108 | ) |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 109 | |
Sherry Zhang | c7baf59 | 2021-07-15 14:54:17 +0800 | [diff] [blame] | 110 | target_include_directories(bl2_mbedcrypto |
| 111 | PUBLIC |
| 112 | ${MBEDCRYPTO_PATH}/library |
| 113 | ) |
| 114 | |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 115 | ############################### CODE SHARING ################################### |
| 116 | |
| 117 | if (TFM_CODE_SHARING) |
| 118 | compiler_create_shared_code(bl2 ${CMAKE_CURRENT_SOURCE_DIR}/src/shared_symbol_template.txt) |
Tamas Ban | 4a5cc97 | 2020-10-27 09:03:56 +0000 | [diff] [blame] | 119 | |
| 120 | if (NOT EXISTS ${MBEDCRYPTO_PATH}/library/code_share.c) |
| 121 | message(FATAL_ERROR "File ${MBEDCRYPTO_PATH}/library/code_share.c does not exist. |
| 122 | Have the patch ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/0005-Enable-crypto-code-sharing-between-independent-binar.patch |
| 123 | been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH}? |
| 124 | Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") |
| 125 | endif() |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 126 | endif() |