Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------ |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 2 | # Copyright (c) 2017-2020, Arm Limited. All rights reserved. |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------ |
| 7 | |
| 8 | cmake_minimum_required(VERSION 3.7) |
| 9 | |
David Hu | 857bfa5 | 2019-05-21 13:54:50 +0800 | [diff] [blame] | 10 | set(TFM_BUILD_IN_SPE ON) |
| 11 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 12 | #Tell cmake where our modules can be found |
| 13 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../cmake) |
| 14 | |
| 15 | #Include common stuff to control cmake. |
| 16 | include("Common/BuildSys") |
| 17 | |
| 18 | #Start an embedded project. |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 19 | get_filename_component(TFM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) |
Ken Liu | e40f9a2 | 2019-06-03 16:42:47 +0800 | [diff] [blame] | 20 | embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake") |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 21 | project(mcuboot LANGUAGES ASM C) |
| 22 | embedded_project_fixup() |
| 23 | |
Raymond Ngun | e3593c6 | 2020-06-25 09:47:36 -0700 | [diff] [blame^] | 24 | #Check input variables |
| 25 | if (NOT DEFINED BL2) |
| 26 | message(FATAL ERROR "Incomplete build configuration: BL2 is undefined.") |
| 27 | elseif(NOT BL2) |
| 28 | #If mcuboot is not need to be built then stop further processing. |
| 29 | return() |
| 30 | endif() |
| 31 | |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 32 | #Set the appropriate MCUBoot path |
| 33 | if (MCUBOOT_REPO STREQUAL "TF-M") |
| 34 | get_filename_component(MCUBOOT_DIR ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE) |
| 35 | else() |
| 36 | get_filename_component(MCUBOOT_DIR "${TFM_ROOT_DIR}/../mcuboot/boot" ABSOLUTE) |
| 37 | if (NOT EXISTS ${MCUBOOT_DIR}) |
| 38 | message(FATAL_ERROR "Missing MCUBoot. Please clone the MCUBoot repo to directory \"${MCUBOOT_DIR}\".") |
| 39 | endif() |
| 40 | endif() |
| 41 | |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 42 | if (NOT DEFINED MBEDCRYPTO_C_FLAGS_BL2) |
| 43 | message(FATAL_ERROR "Incomplete build configuration: MBEDCRYPTO_C_FLAGS_BL2 is undefined.") |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 44 | endif() |
| 45 | |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 46 | set(BUILD_CMSIS_CORE On) |
| 47 | set(BUILD_RETARGET On) |
| 48 | set(BUILD_NATIVE_DRIVERS On) |
| 49 | set(BUILD_STARTUP On) |
| 50 | set(BUILD_TARGET_CFG Off) |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 51 | set(BUILD_TARGET_NV_COUNTERS On) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 52 | set(BUILD_CMSIS_DRIVERS On) |
| 53 | set(BUILD_TIME Off) |
| 54 | set(BUILD_UART_STDOUT On) |
| 55 | set(BUILD_FLASH On) |
Mate Toth-Pal | d3c7766 | 2019-02-20 16:23:00 +0100 | [diff] [blame] | 56 | set(BUILD_PLAT_TEST Off) |
Tamas Ban | d4bf347 | 2019-09-06 12:59:56 +0100 | [diff] [blame] | 57 | set(BUILD_BOOT_HAL On) |
Tamas Ban | d0f4e1d | 2019-07-11 09:39:03 +0100 | [diff] [blame] | 58 | |
| 59 | if (MCUBOOT_HW_KEY) |
| 60 | set(BUILD_TARGET_HARDWARE_KEYS On) |
| 61 | else() |
| 62 | set(BUILD_TARGET_HARDWARE_KEYS Off) |
| 63 | endif() |
| 64 | |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 65 | if(NOT DEFINED PLATFORM_CMAKE_FILE) |
| 66 | message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") |
| 67 | elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) |
| 68 | message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") |
| 69 | else() |
| 70 | include(${PLATFORM_CMAKE_FILE}) |
| 71 | endif() |
| 72 | |
David Hu | 857bfa5 | 2019-05-21 13:54:50 +0800 | [diff] [blame] | 73 | #Add platform specific definitions in SPE |
| 74 | if (DEFINED TFM_PLATFORM_SECURE_DEFS) |
| 75 | embedded_set_target_compile_defines(TARGET ${PROJECT_NAME} LANGUAGE C DEFINES ${TFM_PLATFORM_SECURE_DEFS} APPEND) |
| 76 | embedded_set_target_compile_defines(TARGET ${PROJECT_NAME} LANGUAGE ASM DEFINES ${TFM_PLATFORM_SECURE_DEFS} APPEND) |
| 77 | endif() |
| 78 | |
Mate Toth-Pal | 8f17a71 | 2020-03-02 16:22:19 +0100 | [diff] [blame] | 79 | if (DEFINED CMSE_FLAGS) |
| 80 | embedded_set_target_compile_flags(TARGET ${PROJECT_NAME} LANGUAGE C APPEND FLAGS ${CMSE_FLAGS}) |
| 81 | endif() |
| 82 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 83 | #Append all our source files to global lists. |
Tamas Ban | a9de4a6 | 2018-09-18 08:09:45 +0100 | [diff] [blame] | 84 | list(APPEND ALL_SRC_C |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 85 | "${TFM_ROOT_DIR}/bl2/ext/mcuboot/bl2_main.c" |
| 86 | "${TFM_ROOT_DIR}/bl2/ext/mcuboot/flash_map_extended.c" |
| 87 | "${TFM_ROOT_DIR}/bl2/ext/mcuboot/flash_map_legacy.c" |
| 88 | "${TFM_ROOT_DIR}/bl2/ext/mcuboot/keys.c" |
| 89 | "${TFM_ROOT_DIR}/bl2/src/flash_map.c" |
David Vincze | abb527c | 2020-01-10 11:19:05 +0100 | [diff] [blame] | 90 | "${TFM_ROOT_DIR}/bl2/src/security_cnt.c" |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 91 | "${MCUBOOT_DIR}/bootutil/src/loader.c" |
| 92 | "${MCUBOOT_DIR}/bootutil/src/bootutil_misc.c" |
| 93 | "${MCUBOOT_DIR}/bootutil/src/image_validate.c" |
| 94 | "${MCUBOOT_DIR}/bootutil/src/image_rsa.c" |
David Vincze | 07706a4 | 2019-12-12 18:20:12 +0100 | [diff] [blame] | 95 | "${MCUBOOT_DIR}/bootutil/src/tlv.c" |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 96 | ) |
| 97 | |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 98 | if (MCUBOOT_REPO STREQUAL "TF-M") |
| 99 | list(APPEND ALL_SRC_C |
| 100 | "${TFM_ROOT_DIR}/bl2/src/boot_record.c" |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 101 | ) |
Balint Matyi | 761ebaf | 2020-03-16 09:12:12 +0100 | [diff] [blame] | 102 | else() |
| 103 | list(APPEND ALL_SRC_C |
David Vincze | 141f215 | 2020-02-19 09:42:07 +0100 | [diff] [blame] | 104 | "${MCUBOOT_DIR}/bootutil/src/boot_record.c" |
Balint Matyi | 761ebaf | 2020-03-16 09:12:12 +0100 | [diff] [blame] | 105 | "${MCUBOOT_DIR}/bootutil/src/swap_scratch.c" |
| 106 | "${MCUBOOT_DIR}/bootutil/src/swap_move.c" |
| 107 | "${MCUBOOT_DIR}/bootutil/src/swap_misc.c" |
| 108 | ) |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 109 | endif() |
| 110 | |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 111 | #Define location of Mbed Crypto source, build, and installation directory. |
David Vincze | cea8b59 | 2019-10-29 16:09:51 +0100 | [diff] [blame] | 112 | set(MBEDTLS_CONFIG_FILE "config-rsa.h") |
Raef Coles | 0e82adc | 2019-10-17 15:06:26 +0100 | [diff] [blame] | 113 | set(MBEDTLS_CONFIG_PATH "${TFM_ROOT_DIR}/bl2/ext/mcuboot/include") |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 114 | get_filename_component(MBEDCRYPTO_SOURCE_DIR "${TFM_ROOT_DIR}/../mbed-crypto" ABSOLUTE) |
| 115 | if(NOT EXISTS ${MBEDCRYPTO_SOURCE_DIR}) |
| 116 | message(FATAL_ERROR "Missing mbed-crypto. Please clone the mbed-crypto repo to directory \"${MBEDCRYPTO_SOURCE_DIR}\".") |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 117 | endif() |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 118 | set (MBEDCRYPTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbed-crypto/build") |
| 119 | set (MBEDCRYPTO_INSTALL_DIR ${MBEDCRYPTO_BINARY_DIR}/../install) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 120 | |
Tamas Ban | f824e74 | 2019-10-25 21:22:26 +0100 | [diff] [blame] | 121 | if (CRYPTO_HW_ACCELERATOR OR CRYPTO_HW_ACCELERATOR_OTP_STATE STREQUAL "PROVISIONING") |
Raef Coles | 0e82adc | 2019-10-17 15:06:26 +0100 | [diff] [blame] | 122 | if(NOT DEFINED CRYPTO_HW_ACCELERATOR_CMAKE_BUILD) |
| 123 | message(FATAL_ERROR "CRYPTO_HW_ACCELERATOR_CMAKE_BUILD not defined.") |
| 124 | endif() |
| 125 | include(${CRYPTO_HW_ACCELERATOR_CMAKE_BUILD}) |
| 126 | endif() |
| 127 | |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 128 | #Build Mbed Crypto as external project. |
| 129 | #This ensures Mbed Crypto is built with exactly defined settings. |
Raef Coles | 0e82adc | 2019-10-17 15:06:26 +0100 | [diff] [blame] | 130 | #Mbed Crypto will be used from its install location |
| 131 | string(APPEND MBEDCRYPTO_C_FLAGS " ${MBEDCRYPTO_C_FLAGS_BL2}") |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 132 | set(MBEDCRYPTO_TARGET_NAME "mbedcrypto_mcuboot_lib") |
| 133 | include(${TFM_ROOT_DIR}/BuildMbedCrypto.cmake) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 134 | |
| 135 | #Setting include directories |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 136 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
Raef Coles | 4d6ea2f | 2019-10-15 14:30:40 +0100 | [diff] [blame] | 137 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE APPEND) |
Tamas Ban | a9de4a6 | 2018-09-18 08:09:45 +0100 | [diff] [blame] | 138 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/bl2/include ABSOLUTE APPEND) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 139 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/bl2/ext/mcuboot/include ABSOLUTE APPEND) |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 140 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${MCUBOOT_DIR}/bootutil/include ABSOLUTE APPEND) |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 141 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${MBEDCRYPTO_INSTALL_DIR}/include ABSOLUTE APPEND) |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 142 | embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${CMAKE_CURRENT_BINARY_DIR} ABSOLUTE APPEND) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 143 | |
| 144 | #Define linker file |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 145 | if(NOT DEFINED BL2_LINKER_CONFIG) |
| 146 | message(FATAL_ERROR "ERROR: Incomplete Configuration: BL2_LINKER_CONFIG is not defined.") |
| 147 | endif() |
Gabor Kertesz | d7d7d74 | 2018-07-04 11:50:05 +0200 | [diff] [blame] | 148 | embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${BL2_LINKER_CONFIG}") |
| 149 | |
| 150 | if(NOT DEFINED PLATFORM_LINK_INCLUDES) |
| 151 | message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.") |
| 152 | endif() |
| 153 | embedded_set_target_link_includes(TARGET ${PROJECT_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}") |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 154 | |
David Hu | 857bfa5 | 2019-05-21 13:54:50 +0800 | [diff] [blame] | 155 | add_executable(${PROJECT_NAME} ${ALL_SRC_ASM} ${ALL_SRC_C_BL2} ${ALL_SRC_ASM_BL2} ${ALL_SRC_C} ${ALL_SRC_CXX}) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 156 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 157 | #Set common compiler and linker flags |
| 158 | config_setting_shared_compiler_flags(${PROJECT_NAME}) |
| 159 | config_setting_shared_linker_flags(${PROJECT_NAME}) |
| 160 | |
David Vincze | 63eda7a | 2019-08-09 17:42:51 +0200 | [diff] [blame] | 161 | #Add BL2 and MCUBOOT_IMAGE_NUMBER defines to linker to resolve symbols in region_defs.h and flash_layout.h |
| 162 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2" "MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}") |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 163 | |
Marc Moreno Berengue | cae2c53 | 2018-10-09 12:58:46 +0100 | [diff] [blame] | 164 | if(NOT DEFINED TEST_FRAMEWORK_S) |
| 165 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.") |
| 166 | elseif(TEST_FRAMEWORK_S) |
| 167 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TEST_FRAMEWORK_S") |
| 168 | endif() |
| 169 | |
| 170 | if(NOT DEFINED TEST_FRAMEWORK_NS) |
| 171 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.") |
| 172 | elseif(TEST_FRAMEWORK_NS) |
| 173 | embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TEST_FRAMEWORK_NS") |
| 174 | endif() |
| 175 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 176 | #Link mbedcrypto library to project |
Raef Coles | 1bb168e | 2019-10-17 09:04:55 +0100 | [diff] [blame] | 177 | target_link_libraries(${PROJECT_NAME} "${MBEDCRYPTO_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX_C}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX_C}") |
| 178 | add_dependencies(${PROJECT_NAME} ${MBEDCRYPTO_TARGET_NAME}_install) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 179 | |
Raef Coles | 0e82adc | 2019-10-17 15:06:26 +0100 | [diff] [blame] | 180 | #Link crypto accelerator libraries if applicable |
Tamas Ban | f824e74 | 2019-10-25 21:22:26 +0100 | [diff] [blame] | 181 | if (CRYPTO_HW_ACCELERATOR OR CRYPTO_HW_ACCELERATOR_OTP_STATE STREQUAL "PROVISIONING") |
Raef Coles | 0e82adc | 2019-10-17 15:06:26 +0100 | [diff] [blame] | 182 | if(NOT DEFINED CRYPTO_HW_ACCELERATOR_CMAKE_LINK) |
| 183 | message(FATAL_ERROR "CRYPTO_HW_ACCELERATOR_CMAKE_LINK not defined.") |
| 184 | endif() |
| 185 | include(${CRYPTO_HW_ACCELERATOR_CMAKE_LINK}) |
| 186 | endif() |
| 187 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 188 | #Generate binary file from axf |
| 189 | compiler_generate_binary_output(${PROJECT_NAME}) |
| 190 | |
Øyvind Rønningstad | 762415c | 2020-04-02 15:34:50 +0200 | [diff] [blame] | 191 | #Generate intel hex file from axf |
| 192 | compiler_generate_hex_output(${PROJECT_NAME}) |
| 193 | |
| 194 | #Generate elf file from axf |
| 195 | compiler_generate_elf_output(${PROJECT_NAME}) |
| 196 | |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 197 | message("- MCUBOOT_REPO: '${MCUBOOT_REPO}'.") |
David Vincze | 73dfbc5 | 2019-10-11 13:54:58 +0200 | [diff] [blame] | 198 | message("- MCUBOOT_IMAGE_NUMBER: '${MCUBOOT_IMAGE_NUMBER}'.") |
| 199 | message("- MCUBOOT_UPGRADE_STRATEGY: '${MCUBOOT_UPGRADE_STRATEGY}'.") |
| 200 | message("- MCUBOOT_SIGNATURE_TYPE: '${MCUBOOT_SIGNATURE_TYPE}'.") |
| 201 | message("- MCUBOOT_HW_KEY: '${MCUBOOT_HW_KEY}'.") |
| 202 | message("- MCUBOOT_LOG_LEVEL: '${MCUBOOT_LOG_LEVEL}'.") |
David Vincze | 54d0555 | 2019-08-05 12:58:47 +0200 | [diff] [blame] | 203 | |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 204 | get_property(_log_levels CACHE MCUBOOT_LOG_LEVEL PROPERTY STRINGS) |
| 205 | list(FIND _log_levels ${MCUBOOT_LOG_LEVEL} LOG_LEVEL_ID) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 206 | |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 207 | if (MCUBOOT_REPO STREQUAL "UPSTREAM") |
David Vincze | abb527c | 2020-01-10 11:19:05 +0100 | [diff] [blame] | 208 | set(MCUBOOT_HW_ROLLBACK_PROT On) |
David Vincze | 141f215 | 2020-02-19 09:42:07 +0100 | [diff] [blame] | 209 | set(MCUBOOT_MEASURED_BOOT On) |
David Vincze | f5c1e06 | 2020-03-31 17:05:34 +0200 | [diff] [blame] | 210 | |
| 211 | #FixMe: This becomes unnecessary and can be deleted once the sign_key.c file |
| 212 | #in upstream MCUboot includes the mcuboot_config.h file and starts "reading" |
| 213 | #the configuration macros from there. |
| 214 | if (MCUBOOT_HW_KEY) |
| 215 | target_compile_definitions(${PROJECT_NAME} PRIVATE MCUBOOT_HW_KEY) |
| 216 | endif() |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 217 | endif() |
| 218 | |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 219 | if(MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072") |
| 220 | set(MCUBOOT_SIGN_RSA On) |
| 221 | set(MCUBOOT_SIGN_RSA_LEN 3072) |
Tamas Ban | 7801ed4 | 2019-05-20 13:21:53 +0100 | [diff] [blame] | 222 | elseif(MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-2048") |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 223 | set(MCUBOOT_SIGN_RSA On) |
| 224 | set(MCUBOOT_SIGN_RSA_LEN 2048) |
Tamas Ban | 7801ed4 | 2019-05-20 13:21:53 +0100 | [diff] [blame] | 225 | endif() |
| 226 | |
David Vincze | 4638b2a | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 227 | if (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "OVERWRITE_ONLY") |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 228 | set(MCUBOOT_OVERWRITE_ONLY On) |
| 229 | elseif(${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP") |
| 230 | set(MCUBOOT_NO_SWAP On) |
David Vincze | 4638b2a | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 231 | elseif (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "RAM_LOADING") |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 232 | set(MCUBOOT_RAM_LOADING On) |
Tamas Ban | d0f4e1d | 2019-07-11 09:39:03 +0100 | [diff] [blame] | 233 | endif() |
| 234 | |
David Vincze | f5c1e06 | 2020-03-31 17:05:34 +0200 | [diff] [blame] | 235 | #FixMe: This becomes unnecessary and can be deleted once the sign_key.c file |
| 236 | #in upstream MCUboot includes the mcuboot_config.h file and starts "reading" |
| 237 | #the configuration macros from there. |
| 238 | if (MCUBOOT_REPO STREQUAL "UPSTREAM" AND MCUBOOT_HW_KEY) |
| 239 | set(MCUBOOT_HW_KEY Off) |
| 240 | configure_file("${CMAKE_CURRENT_LIST_DIR}/include/mcuboot_config/mcuboot_config.h.in" |
| 241 | "${CMAKE_CURRENT_BINARY_DIR}/mcuboot_config/mcuboot_config.h" |
| 242 | @ONLY) |
| 243 | set(MCUBOOT_HW_KEY On) |
| 244 | else() |
| 245 | configure_file("${CMAKE_CURRENT_LIST_DIR}/include/mcuboot_config/mcuboot_config.h.in" |
| 246 | "${CMAKE_CURRENT_BINARY_DIR}/mcuboot_config/mcuboot_config.h" |
| 247 | @ONLY) |
| 248 | endif() |
Balint Matyi | 2fe0492 | 2020-02-18 12:27:38 +0000 | [diff] [blame] | 249 | |
| 250 | target_compile_definitions(${PROJECT_NAME} PRIVATE MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") |
| 251 | |
| 252 | if (NOT MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072" AND NOT MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-2048") |
| 253 | message(FATAL_ERROR "${MCUBOOT_SIGNATURE_TYPE} is not supported as firmware signing algorithm") |
| 254 | endif() |
| 255 | |
| 256 | validate_cache_value(MCUBOOT_UPGRADE_STRATEGY) |
| 257 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 258 | #Set install location. Keep original value to avoid overriding command line settings. |
| 259 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 260 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install location for MCUBoot." FORCE) |
| 261 | endif() |
| 262 | |
| 263 | #Collect executables to common location: build/install/outputs/ |
| 264 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.axf |
| 265 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin |
Øyvind Rønningstad | 762415c | 2020-04-02 15:34:50 +0200 | [diff] [blame] | 266 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.hex |
| 267 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.elf |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 268 | DESTINATION outputs/${TARGET_PLATFORM}/) |
| 269 | |
| 270 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.axf |
| 271 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin |
Øyvind Rønningstad | 762415c | 2020-04-02 15:34:50 +0200 | [diff] [blame] | 272 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.hex |
| 273 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.elf |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 274 | DESTINATION outputs/fvp/) |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 275 | |
| 276 | #Finally let cmake system apply changes after the whole project is defined. |
| 277 | embedded_project_end(${PROJECT_NAME}) |