Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2017-2020, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | cmake_minimum_required(VERSION 3.7) |
| 9 | |
| 10 | set(TFM_BUILD_IN_SPE OFF) |
| 11 | |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 12 | if (NOT DEFINED TFM_ROOT_DIR) |
Kevin Peng | 2ff05d5 | 2020-08-14 11:17:42 +0800 | [diff] [blame] | 13 | set(TFM_ROOT_DIR ${CMAKE_SOURCE_DIR}) |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 14 | endif() |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 15 | |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 16 | #Tell cmake where our modules can be found |
| 17 | list(APPEND CMAKE_MODULE_PATH ${TFM_ROOT_DIR}/cmake) |
| 18 | |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 19 | set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface) |
| 20 | |
| 21 | #Include common stuff to control cmake. |
| 22 | include("Common/BuildSys") |
| 23 | |
| 24 | #Start an embedded project. |
| 25 | embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake") |
| 26 | project(tfm_ns LANGUAGES ASM C) |
| 27 | embedded_project_fixup() |
| 28 | |
| 29 | #Include BL2 bootloader related functions |
| 30 | set(MCUBOOT_DIR "${TFM_ROOT_DIR}/bl2/ext/mcuboot") |
| 31 | include("${MCUBOOT_DIR}/MCUBoot.cmake") |
| 32 | |
| 33 | #CMSIS |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 34 | set(CMSIS_DIR ${CMAKE_CURRENT_LIST_DIR}/../CMSIS) |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 35 | |
| 36 | if (NOT DEFINED BL2) |
| 37 | message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ") |
| 38 | endif () |
| 39 | |
| 40 | if (NOT DEFINED TFM_PARTITION_AUDIT_LOG) |
| 41 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_AUDIT_LOG is undefined.") |
| 42 | endif() |
| 43 | |
| 44 | if (NOT DEFINED TFM_PARTITION_PLATFORM) |
| 45 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PLATFORM is undefined.") |
| 46 | endif() |
| 47 | |
| 48 | if (NOT DEFINED TFM_PARTITION_PROTECTED_STORAGE) |
| 49 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PROTECTED_STORAGE is undefined.") |
| 50 | endif() |
| 51 | |
| 52 | if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE) |
| 53 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INTERNAL_TRUSTED_STORAGE is undefined.") |
| 54 | endif() |
| 55 | |
| 56 | if (NOT DEFINED TFM_PARTITION_CRYPTO) |
| 57 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_CRYPTO is undefined.") |
| 58 | endif() |
| 59 | |
| 60 | if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION) |
| 61 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INITIAL_ATTESTATION is undefined.") |
| 62 | endif() |
| 63 | |
| 64 | if (NOT DEFINED TFM_PSA_API) |
| 65 | message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined.") |
| 66 | endif() |
| 67 | |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 68 | embedded_include_directories(PATH ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE) |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 69 | |
| 70 | set(NS_APP_SRC "${CMSIS_DIR}/RTOS2/RTX/Config/RTX_Config.c" |
| 71 | "${CMSIS_DIR}/RTOS2/RTX/Source/rtx_lib.c" |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 72 | "${CMAKE_CURRENT_LIST_DIR}/main_ns.c" |
| 73 | "${CMAKE_CURRENT_LIST_DIR}/tfm_integ_test.c" |
| 74 | "${CMAKE_CURRENT_LIST_DIR}/os_wrapper_cmsis_rtos_v2.c" |
Summer Qin | 7789423 | 2020-08-28 11:24:15 +0800 | [diff] [blame] | 75 | "${CMAKE_CURRENT_LIST_DIR}/../log/tfm_log_raw.c" |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 76 | ) |
| 77 | |
| 78 | if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY) |
| 79 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ns_interface.c") |
| 80 | endif() |
| 81 | |
| 82 | if (TFM_PARTITION_AUDIT_LOG) |
| 83 | if (TFM_PSA_API) |
| 84 | message(FATAL_ERROR "Audit log has not been supported in IPC model yet.") |
| 85 | else() |
| 86 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_audit_func_api.c") |
| 87 | endif() |
| 88 | endif() |
| 89 | |
| 90 | if (TFM_PARTITION_PLATFORM) |
| 91 | if (TFM_PSA_API) |
| 92 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_ipc_api.c") |
| 93 | else() |
| 94 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_func_api.c") |
| 95 | endif() |
| 96 | endif() |
| 97 | |
| 98 | if (TFM_PARTITION_PROTECTED_STORAGE) |
| 99 | if (TFM_PSA_API) |
| 100 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ps_ipc_api.c") |
| 101 | else() |
| 102 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ps_func_api.c") |
| 103 | endif() |
| 104 | endif() |
| 105 | |
| 106 | if (TFM_PARTITION_INTERNAL_TRUSTED_STORAGE) |
| 107 | if (TFM_PSA_API) |
| 108 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_its_ipc_api.c") |
| 109 | else() |
| 110 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_its_func_api.c") |
| 111 | endif() |
| 112 | endif() |
| 113 | |
| 114 | if (TFM_PARTITION_CRYPTO) |
| 115 | if (TFM_PSA_API) |
| 116 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_crypto_ipc_api.c") |
| 117 | else() |
| 118 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_crypto_func_api.c") |
| 119 | endif() |
| 120 | endif() |
| 121 | |
| 122 | if (TFM_PARTITION_INITIAL_ATTESTATION) |
| 123 | if (TFM_PSA_API) |
| 124 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_initial_attestation_ipc_api.c") |
| 125 | else() |
| 126 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_initial_attestation_func_api.c") |
| 127 | endif() |
| 128 | endif() |
| 129 | |
| 130 | if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION) |
| 131 | message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.") |
| 132 | elseif (TFM_NS_CLIENT_IDENTIFICATION) |
| 133 | list(APPEND NS_APP_SRC |
| 134 | "${INTERFACE_DIR}/src/tfm_nspm_svc_handler.c" |
| 135 | "${INTERFACE_DIR}/src/tfm_nspm_api.c" |
| 136 | ) |
| 137 | endif() |
| 138 | |
| 139 | if (PSA_API_TEST_NS) |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 140 | list(APPEND NS_APP_SRC "${CMAKE_CURRENT_LIST_DIR}/psa_api_test.c") |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 141 | endif() |
| 142 | |
| 143 | if (TFM_PSA_API) |
| 144 | if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY) |
| 145 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ns_mailbox.c" |
| 146 | "${INTERFACE_DIR}/src/tfm_multi_core_api.c" |
| 147 | "${INTERFACE_DIR}/src/tfm_multi_core_psa_ns_api.c" |
| 148 | ) |
| 149 | |
| 150 | if (TFM_MULTI_CORE_TEST) |
| 151 | add_definitions(-DTFM_MULTI_CORE_TEST) |
| 152 | endif() |
| 153 | else() |
| 154 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_psa_ns_api.c") |
| 155 | endif() |
| 156 | endif() |
| 157 | |
| 158 | set(BUILD_CMSIS_CORE On) |
| 159 | set(BUILD_RETARGET On) |
| 160 | set(BUILD_NATIVE_DRIVERS On) |
| 161 | set(BUILD_TIME On) |
| 162 | set(BUILD_STARTUP On) |
| 163 | set(BUILD_TARGET_CFG Off) |
| 164 | set(BUILD_TARGET_HARDWARE_KEYS Off) |
| 165 | set(BUILD_TARGET_NV_COUNTERS Off) |
| 166 | set(BUILD_CMSIS_DRIVERS On) |
| 167 | set(BUILD_UART_STDOUT On) |
| 168 | set(BUILD_FLASH Off) |
| 169 | if(CORE_TEST_POSITIVE) |
| 170 | set(BUILD_PLAT_TEST On) |
| 171 | set(BUILD_TIME On) |
| 172 | else() |
| 173 | set(BUILD_PLAT_TEST Off) |
| 174 | set(BUILD_TIME Off) |
| 175 | endif() |
| 176 | if(NOT DEFINED PLATFORM_CMAKE_FILE) |
| 177 | message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") |
| 178 | elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) |
| 179 | message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") |
| 180 | else() |
| 181 | include(${PLATFORM_CMAKE_FILE}) |
| 182 | endif() |
| 183 | |
| 184 | if(NOT DEFINED NS_SCATTER_FILE_NAME) |
| 185 | message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake") |
| 186 | endif() |
| 187 | embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}") |
| 188 | |
| 189 | #Create an object library to avoid compiling all source files twice, when two executables |
| 190 | #with different memory map need to be linked(BL2 non-swapping) |
| 191 | set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib) |
| 192 | add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM} ${ALL_SRC_ASM_NS} ${NS_APP_SRC}) |
| 193 | |
| 194 | #Set common compiler flags |
| 195 | config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB}) |
| 196 | |
| 197 | #Set macro definitions |
| 198 | set(TARGET_COMPILE_DEFINITIONS __thumb2__ __DOMAIN_NS=1 DOMAIN_NS=__DOMAIN_NS) |
| 199 | target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE ${TARGET_COMPILE_DEFINITIONS}) |
| 200 | |
| 201 | #Set include directories. |
| 202 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 203 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 204 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
| 205 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND) |
| 206 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_DIR}/RTOS2/RTX/Include ABSOLUTE APPEND) |
| 207 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_DIR}/RTOS2/Include ABSOLUTE APPEND) |
| 208 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_DIR}/RTOS2/RTX/Config ABSOLUTE APPEND) |
Kevin Peng | ae997e4 | 2020-07-08 17:06:37 +0800 | [diff] [blame] | 209 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_DIR}/.. ABSOLUTE APPEND) |
Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame] | 210 | |
| 211 | if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION) |
| 212 | message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.") |
| 213 | elseif (TFM_NS_CLIENT_IDENTIFICATION) |
| 214 | target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION) |
| 215 | endif() |
| 216 | |
| 217 | add_subdirectory(${TEST_DIR} ${CMAKE_BINARY_DIR}/test/non_secure_test) |
| 218 | |
| 219 | # For the non-swapping BL2 configuration two executables need to be built. |
| 220 | # One can be executed from the primary slot flash partition and other from the |
| 221 | # secondary slot. Only the linking phase is different. This function captures |
| 222 | # common settings and eliminates copy-paste. |
| 223 | function(set_up_app_build) |
| 224 | set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE) |
| 225 | set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar") |
| 226 | set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX) |
| 227 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN}) |
| 228 | |
| 229 | if (NOT DEFINED _MY_PARAMS_NS_TARGET) |
| 230 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.") |
| 231 | endif() |
| 232 | |
| 233 | if (NOT DEFINED _MY_PARAMS_S_TARGET) |
| 234 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.") |
| 235 | endif() |
| 236 | |
| 237 | if (NOT DEFINED _MY_PARAMS_FULL_BIN) |
| 238 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.") |
| 239 | endif() |
| 240 | |
| 241 | if (NOT DEFINED _MY_PARAMS_SIGN_BIN) |
| 242 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.") |
| 243 | endif() |
| 244 | |
| 245 | if (NOT DEFINED _MY_PARAMS_VENEER_NAME) |
| 246 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.") |
| 247 | endif() |
| 248 | |
| 249 | set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX}) |
| 250 | set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX}) |
| 251 | set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX}) |
| 252 | set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX}) |
| 253 | set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o) |
| 254 | |
| 255 | #Create linker target: add object library to executable |
| 256 | add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>) |
| 257 | |
| 258 | #Set common linker flags |
| 259 | config_setting_shared_linker_flags(${EXE_NAME}) |
| 260 | |
| 261 | #Set individual linker flags per linker target/executable |
| 262 | foreach(flag ${_MY_PARAMS_LINK_DEFINES}) |
| 263 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}") |
| 264 | endforeach(flag) |
| 265 | |
| 266 | embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}") |
| 267 | |
| 268 | #Add the RTX library |
| 269 | if(NOT DEFINED RTX_LIB_PATH) |
| 270 | message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.") |
| 271 | endif() |
| 272 | |
| 273 | #Add the PSA API compliance test libraries |
| 274 | if(PSA_API_TEST_NS) |
| 275 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/val/val_nspe.a") |
| 276 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/platform/pal_nspe.a") |
| 277 | endif() |
| 278 | if(PSA_API_TEST_NS AND (PSA_API_TEST_INTERNAL_TRUSTED_STORAGE OR PSA_API_TEST_PROTECTED_STORAGE OR PSA_API_TEST_STORAGE)) |
| 279 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/storage/test_combine.a") |
| 280 | endif() |
| 281 | if(PSA_API_TEST_NS AND PSA_API_TEST_CRYPTO) |
| 282 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/crypto/test_combine.a") |
| 283 | endif() |
| 284 | if(PSA_API_TEST_NS AND PSA_API_TEST_INITIAL_ATTESTATION) |
| 285 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/initial_attestation/test_combine.a") |
| 286 | endif() |
| 287 | if(PSA_API_TEST_NS AND PSA_API_TEST_IPC) |
| 288 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/ff/ipc/test_combine.a") |
| 289 | endif() |
| 290 | |
| 291 | if(NOT DEFINED PLATFORM_LINK_INCLUDES) |
| 292 | message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.") |
| 293 | endif() |
| 294 | embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}") |
| 295 | |
| 296 | #Generate binary file from axf |
| 297 | compiler_generate_binary_output(${EXE_NAME}) |
| 298 | |
| 299 | #Generate intel hex file from axf |
| 300 | compiler_generate_hex_output(${EXE_NAME}) |
| 301 | |
| 302 | #Generate elf file from axf |
| 303 | compiler_generate_elf_output(${EXE_NAME}) |
| 304 | |
| 305 | #Generate MCUBoot compatible payload |
| 306 | if (BL2) |
| 307 | mcuboot_create_boot_payload(S_BIN ${S_BIN} |
| 308 | NS_BIN ${EXE_NAME} |
| 309 | FULL_BIN ${FULL_NAME} |
| 310 | SIGN_BIN ${SIGN_NAME} |
| 311 | POSTFIX ${_MY_PARAMS_POSTFIX}) |
| 312 | endif() |
| 313 | |
| 314 | if (NOT DEFINED TFM_PARTITION_TEST_CORE) |
| 315 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ") |
| 316 | elseif (TFM_PARTITION_TEST_CORE) |
| 317 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
| 318 | endif() |
| 319 | |
| 320 | if (NOT DEFINED TFM_PARTITION_TEST_CORE_IPC) |
| 321 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE_IPC is undefined.") |
| 322 | elseif (TFM_PARTITION_TEST_CORE_IPC) |
| 323 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE_IPC") |
| 324 | endif() |
| 325 | |
| 326 | if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES) |
| 327 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ") |
| 328 | elseif (TFM_PARTITION_TEST_SECURE_SERVICES) |
| 329 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES") |
| 330 | endif() |
| 331 | |
| 332 | if (NOT DEFINED TEST_FRAMEWORK_S) |
| 333 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.") |
| 334 | elseif (TEST_FRAMEWORK_S) |
| 335 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S") |
| 336 | endif() |
| 337 | |
| 338 | if (NOT DEFINED TEST_FRAMEWORK_NS) |
| 339 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.") |
| 340 | elseif (TEST_FRAMEWORK_NS) |
| 341 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS") |
| 342 | endif() |
| 343 | |
| 344 | #Set BL2 specific settings. |
| 345 | if (BL2) |
| 346 | #Add BL2 and MCUBOOT_IMAGE_NUMBER defines to linker to resolve symbols in region_defs.h and flash_layout.h |
| 347 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2" "MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}") |
| 348 | endif() |
| 349 | |
| 350 | #We depend on the non secure tests. See if the library target is available. |
| 351 | if(TARGET tfm_non_secure_tests) |
| 352 | #If yes, then use the library. |
| 353 | target_link_libraries(${EXE_NAME} tfm_non_secure_tests) |
| 354 | #Ensure library is built first. |
| 355 | add_dependencies(${EXE_NAME} tfm_non_secure_tests) |
| 356 | endif() |
| 357 | |
| 358 | target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}") |
| 359 | |
| 360 | #Ensure secure_fw is built before our executable. |
| 361 | add_dependencies(${EXE_NAME} ${S_BIN}) |
| 362 | |
| 363 | if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY) |
| 364 | if (NOT DEFINED S_VENEER_PATH) |
| 365 | if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/../secure_fw) |
| 366 | set (S_VENEER_PATH "${CMAKE_CURRENT_BINARY_DIR}/../secure_fw") |
| 367 | else() |
| 368 | message(FATAL_ERROR "No valid path for S_VENEER_PATH, secure_fw is built?") |
| 369 | endif() |
| 370 | endif() |
| 371 | |
| 372 | #Add the veneers to the executable. |
| 373 | set(S_VENEER_FILE "${S_VENEER_PATH}/${VENEER_NAME}") |
| 374 | set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE}) |
| 375 | endif() |
| 376 | |
| 377 | #Collect executables to common location: build/install/outputs/ |
| 378 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf |
| 379 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin |
| 380 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.hex |
| 381 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.elf |
| 382 | DESTINATION outputs/${TARGET_PLATFORM}/) |
| 383 | |
| 384 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf |
| 385 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin |
| 386 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.hex |
| 387 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.elf |
| 388 | DESTINATION outputs/fvp/) |
| 389 | endfunction() |
| 390 | |
| 391 | if (LINK_TO_BOTH_MEMORY_REGION) |
| 392 | #Link to primary memory region |
| 393 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
| 394 | S_TARGET tfm_s |
| 395 | FULL_BIN tfm_full |
| 396 | SIGN_BIN tfm_sign |
| 397 | VENEER_NAME s_veneers) |
| 398 | |
| 399 | #Link to secondary memory region(add extra linker flag) |
| 400 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
| 401 | LINK_DEFINES "LINK_TO_SECONDARY_PARTITION" |
| 402 | S_TARGET tfm_s |
| 403 | FULL_BIN tfm_full |
| 404 | SIGN_BIN tfm_sign |
| 405 | VENEER_NAME s_veneers |
| 406 | POSTFIX "_1") |
| 407 | else() |
| 408 | #Link to primary memory region only |
| 409 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
| 410 | S_TARGET tfm_s |
| 411 | FULL_BIN tfm_full |
| 412 | SIGN_BIN tfm_sign |
| 413 | VENEER_NAME s_veneers) |
| 414 | endif() |
| 415 | |
| 416 | #If the tfm_non_secure_tests target is not available |
| 417 | if(NOT TARGET tfm_non_secure_tests) |
| 418 | #Add the test source to the build. |
| 419 | #As of today since secure_fw is built as a sub-project this code will never execute. |
| 420 | option(ENABLE_PROTECTED_STORAGE_SERVICE_TESTS "" TRUE) |
| 421 | include(${TEST_DIR}/CMakeLists.inc) |
| 422 | target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS}) |
| 423 | endif() |
| 424 | |
| 425 | #Finally let CMake system apply changes after the whole project is defined. |
| 426 | if (TARGET ${PROJECT_NAME}) |
| 427 | embedded_project_end(${PROJECT_NAME}) |
| 428 | endif() |
| 429 | |
| 430 | if (TARGET ${PROJECT_NAME}_1) |
| 431 | embedded_project_end(${PROJECT_NAME}_1) |
| 432 | endif() |
| 433 | |
| 434 | embedded_project_end(${PROJECT_OBJ_LIB}) |