Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Raef Coles | f77cc17 | 2022-01-07 11:05:47 +0000 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, 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 | aefbe08 | 2021-06-18 08:53:43 +0100 | [diff] [blame] | 17 | $<$<BOOL:${PLATFORM_DEFAULT_PROVISIONING}>:src/provisioning.c> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 18 | ) |
| 19 | |
| 20 | add_subdirectory(ext/mcuboot) |
| 21 | |
| 22 | set_target_properties(bl2 |
| 23 | PROPERTIES |
| 24 | SUFFIX ".axf" |
| 25 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" |
| 26 | ) |
| 27 | |
| 28 | target_include_directories(bl2 |
| 29 | PRIVATE |
| 30 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
Sherry Zhang | 6e0f324 | 2021-03-08 12:18:31 +0800 | [diff] [blame] | 31 | $<BUILD_INTERFACE:${MCUBOOT_PATH}/boot/bootutil/src> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | target_link_libraries(bl2 |
| 35 | PRIVATE |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 36 | tfm_boot_status |
Raef Coles | f77cc17 | 2022-01-07 11:05:47 +0000 | [diff] [blame] | 37 | $<$<BOOL:${TEST_BL2}>:mcuboot_tests> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 38 | ) |
| 39 | |
Feder Liang | d4dbaa9 | 2021-09-07 15:34:46 +0800 | [diff] [blame] | 40 | target_compile_options(bl2 |
| 41 | PRIVATE |
| 42 | ${BL2_COMPILER_CP_FLAG} |
| 43 | ) |
| 44 | |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 45 | target_link_options(bl2 |
| 46 | PRIVATE |
| 47 | $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/bl2.map> |
| 48 | $<$<C_COMPILER_ID:ARMClang>:--map> |
TTornblom | af19ae9 | 2020-09-29 13:26:29 +0200 | [diff] [blame] | 49 | $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/bl2.map> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 50 | ) |
| 51 | |
Mark Horvath | 8576e38 | 2021-03-12 10:24:55 +0100 | [diff] [blame] | 52 | target_compile_definitions(bl2 |
| 53 | PRIVATE |
| 54 | $<$<BOOL:${DEFAULT_MCUBOOT_FLASH_MAP}>:DEFAULT_MCUBOOT_FLASH_MAP> |
Satish Kumar | a5312fd | 2021-10-26 07:08:57 +0100 | [diff] [blame] | 55 | $<$<BOOL:${PLATFORM_PSA_ADAC_SECURE_DEBUG}>:PLATFORM_PSA_ADAC_SECURE_DEBUG> |
Raef Coles | f77cc17 | 2022-01-07 11:05:47 +0000 | [diff] [blame] | 56 | $<$<BOOL:${TEST_BL2}>:TEST_BL2> |
Mark Horvath | 8576e38 | 2021-03-12 10:24:55 +0100 | [diff] [blame] | 57 | ) |
| 58 | |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 59 | add_convert_to_bin_target(bl2) |
| 60 | |
| 61 | ############################### BOOT HAL # ##################################### |
| 62 | |
| 63 | add_library(bl2_hal INTERFACE) |
| 64 | |
| 65 | target_include_directories(bl2_hal |
| 66 | INTERFACE |
| 67 | include |
| 68 | ) |
| 69 | |
| 70 | ############################### MBEDCRYPTO ##################################### |
| 71 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 72 | add_library(bl2_mbedcrypto_config INTERFACE) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 73 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 74 | target_compile_definitions(bl2_mbedcrypto_config |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 75 | INTERFACE |
| 76 | $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA> |
| 77 | $<$<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] | 78 | MBEDTLS_CONFIG_FILE="${MCUBOOT_MBEDCRYPTO_CONFIG_FILEPATH}" |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 79 | # Workaround for https://github.com/ARMmbed/mbedtls/issues/1077 |
Gabor Abonyi | 866571c | 2021-10-07 13:56:19 +0200 | [diff] [blame] | 80 | $<$<OR:$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8-m.base>,$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv6-m>>:MULADDC_CANNOT_USE_R7> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 81 | ) |
| 82 | |
| 83 | cmake_policy(SET CMP0079 NEW) |
| 84 | |
| 85 | set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) |
| 86 | set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) |
| 87 | set(ENABLE_TESTING OFF) |
| 88 | set(ENABLE_PROGRAMS OFF) |
| 89 | set(MBEDTLS_FATAL_WARNINGS OFF) |
| 90 | set(ENABLE_DOCS OFF) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 91 | set(INSTALL_MBEDTLS_HEADERS OFF) |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 92 | set(LIB_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto/install) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 93 | |
Antonio de Angelis | 9e7e378 | 2021-10-21 11:39:04 +0100 | [diff] [blame] | 94 | # Set the prefix to be used by mbedTLS targets |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 95 | set(MBEDTLS_TARGET_PREFIX bl2_) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 96 | |
| 97 | # Mbedcrypto is quite a large lib, and it uses too much memory for it to be |
| 98 | # reasonable to build it in debug info. As a compromise, if `debug` build type |
| 99 | # is selected mbedcrypto will build under `relwithdebinfo` which preserved debug |
| 100 | # symbols whild optimizing space. |
| 101 | set(SAVED_BUILD_TYPE ${CMAKE_BUILD_TYPE}) |
| 102 | set(CMAKE_BUILD_TYPE ${MBEDCRYPTO_BUILD_TYPE}) |
Antonio de Angelis | 1598e47 | 2021-11-01 10:26:23 +0000 | [diff] [blame] | 103 | add_subdirectory(${MBEDCRYPTO_PATH} ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto EXCLUDE_FROM_ALL) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 104 | set(CMAKE_BUILD_TYPE ${SAVED_BUILD_TYPE} CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE) |
| 105 | |
Antonio de Angelis | 126122f | 2021-10-29 10:55:48 +0100 | [diff] [blame] | 106 | if(NOT TARGET ${MBEDTLS_TARGET_PREFIX}mbedcrypto) |
| 107 | message(FATAL_ERROR "Target ${MBEDTLS_TARGET_PREFIX}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] | 108 | Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") |
| 109 | endif() |
| 110 | |
Antonio de Angelis | 126122f | 2021-10-29 10:55:48 +0100 | [diff] [blame] | 111 | target_link_libraries(${MBEDTLS_TARGET_PREFIX}mbedcrypto |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 112 | PUBLIC |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 113 | bl2_mbedcrypto_config |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 114 | ) |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 115 | |
Antonio de Angelis | 126122f | 2021-10-29 10:55:48 +0100 | [diff] [blame] | 116 | target_include_directories(${MBEDTLS_TARGET_PREFIX}mbedcrypto |
Sherry Zhang | c7baf59 | 2021-07-15 14:54:17 +0800 | [diff] [blame] | 117 | PUBLIC |
| 118 | ${MBEDCRYPTO_PATH}/library |
| 119 | ) |
| 120 | |
Feder Liang | d4dbaa9 | 2021-09-07 15:34:46 +0800 | [diff] [blame] | 121 | target_compile_options(bl2_mbedcrypto |
| 122 | PRIVATE |
| 123 | ${BL2_COMPILER_CP_FLAG} |
| 124 | ) |
| 125 | |
| 126 | target_compile_options(bl2_mbedtls |
| 127 | PRIVATE |
| 128 | ${BL2_COMPILER_CP_FLAG} |
| 129 | ) |
| 130 | |
| 131 | target_compile_options(bl2_mbedx509 |
| 132 | PRIVATE |
| 133 | ${BL2_COMPILER_CP_FLAG} |
| 134 | ) |
| 135 | |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 136 | ############################### CODE SHARING ################################### |
| 137 | |
| 138 | if (TFM_CODE_SHARING) |
Raef Coles | 4351ec2 | 2021-04-26 09:20:50 +0100 | [diff] [blame] | 139 | target_share_symbols(bl2 ${CMAKE_CURRENT_SOURCE_DIR}/bl2_shared_symbols.txt) |
Tamas Ban | 4a5cc97 | 2020-10-27 09:03:56 +0000 | [diff] [blame] | 140 | |
| 141 | if (NOT EXISTS ${MBEDCRYPTO_PATH}/library/code_share.c) |
| 142 | message(FATAL_ERROR "File ${MBEDCRYPTO_PATH}/library/code_share.c does not exist. |
| 143 | Have the patch ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/0005-Enable-crypto-code-sharing-between-independent-binar.patch |
| 144 | been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH}? |
| 145 | Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") |
| 146 | endif() |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 147 | endif() |