Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 2 | # Copyright (c) 2017-2019, Arm Limited. All rights reserved. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +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 OFF) |
| 11 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 12 | #Tell cmake where our modules can be found |
| 13 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) |
| 14 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 15 | set(APP_DIR ${CMAKE_CURRENT_LIST_DIR}) |
| 16 | get_filename_component(TFM_ROOT_DIR ${APP_DIR}/.. ABSOLUTE) |
| 17 | set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface) |
Mate Toth-Pal | 813e9d1 | 2019-01-17 15:51:29 +0100 | [diff] [blame] | 18 | set(TEST_DIR ${TFM_ROOT_DIR}/test) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 19 | |
Ken Liu | e40f9a2 | 2019-06-03 16:42:47 +0800 | [diff] [blame] | 20 | #Include common stuff to control cmake. |
| 21 | include("Common/BuildSys") |
| 22 | |
| 23 | #Start an embedded project. |
| 24 | embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake") |
| 25 | project(tfm_ns LANGUAGES ASM C) |
| 26 | embedded_project_fixup() |
| 27 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 28 | #Include BL2 bootloader related functions |
| 29 | set(MCUBOOT_DIR "${TFM_ROOT_DIR}/bl2/ext/mcuboot") |
| 30 | include("${MCUBOOT_DIR}/MCUBoot.cmake") |
| 31 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 32 | #Set variables |
| 33 | get_filename_component(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5 ABSOLUTE) |
| 34 | |
| 35 | if(NOT EXISTS ${CMSIS_5_DIR}) |
| 36 | message(FATAL_ERROR "Missing CMSIS_5. Please clone the CMSIS_5 repo to directory \"${CMSIS_5_DIR}\".") |
| 37 | endif() |
| 38 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 39 | if (NOT DEFINED BL2) |
| 40 | message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ") |
| 41 | endif () |
| 42 | |
Jamie Fox | c78c62c | 2019-05-23 13:42:17 +0100 | [diff] [blame] | 43 | if (NOT DEFINED TFM_PARTITION_AUDIT_LOG) |
| 44 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_AUDIT_LOG is undefined.") |
| 45 | endif() |
| 46 | |
Mingyang Sun | 9511e5e | 2019-05-29 18:18:44 +0800 | [diff] [blame] | 47 | if (NOT DEFINED TFM_PARTITION_PLATFORM) |
| 48 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PLATFORM is undefined.") |
| 49 | endif() |
| 50 | |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 51 | if (NOT DEFINED TFM_PSA_API) |
| 52 | message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined.") |
| 53 | endif() |
| 54 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 55 | set(NS_APP_SRC "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config/RTX_Config.c" |
| 56 | "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Source/rtx_lib.c" |
| 57 | "${APP_DIR}/main_ns.c" |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 58 | "${APP_DIR}/tfm_integ_test.c" |
Kevin Peng | d36a7fc | 2019-07-22 16:01:10 +0800 | [diff] [blame] | 59 | "${APP_DIR}/os_wrapper_cmsis_rtos_v2.c" |
Kevin Peng | c86dec0 | 2019-07-23 16:15:57 +0800 | [diff] [blame] | 60 | "${INTERFACE_DIR}/src/tfm_ns_interface.c" |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 61 | ) |
| 62 | |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 63 | if (TFM_PSA_API) |
| 64 | list(APPEND NS_APP_SRC |
| 65 | "${INTERFACE_DIR}/src/tfm_sst_ipc_api.c" |
TudorCretu | fb182bc | 2019-07-05 17:34:12 +0100 | [diff] [blame] | 66 | "${INTERFACE_DIR}/src/tfm_its_ipc_api.c" |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 67 | "${INTERFACE_DIR}/src/tfm_crypto_ipc_api.c" |
| 68 | "${INTERFACE_DIR}/src/tfm_initial_attestation_ipc_api.c" |
| 69 | ) |
| 70 | else() |
| 71 | list(APPEND NS_APP_SRC |
| 72 | "${INTERFACE_DIR}/src/tfm_sst_func_api.c" |
TudorCretu | fb182bc | 2019-07-05 17:34:12 +0100 | [diff] [blame] | 73 | "${INTERFACE_DIR}/src/tfm_its_func_api.c" |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 74 | "${INTERFACE_DIR}/src/tfm_crypto_func_api.c" |
| 75 | "${INTERFACE_DIR}/src/tfm_initial_attestation_func_api.c" |
| 76 | ) |
| 77 | endif() |
| 78 | |
Jamie Fox | c78c62c | 2019-05-23 13:42:17 +0100 | [diff] [blame] | 79 | if (TFM_PARTITION_AUDIT_LOG) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 80 | if (TFM_PSA_API) |
| 81 | message(FATAL_ERROR "Audit log has not been supported in IPC model yet.") |
| 82 | else() |
| 83 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_audit_func_api.c") |
| 84 | endif() |
Jamie Fox | c78c62c | 2019-05-23 13:42:17 +0100 | [diff] [blame] | 85 | endif() |
| 86 | |
Mingyang Sun | 9511e5e | 2019-05-29 18:18:44 +0800 | [diff] [blame] | 87 | if (TFM_PARTITION_PLATFORM) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 88 | if (TFM_PSA_API) |
| 89 | message(FATAL_ERROR "Platform service has not been supported in IPC model yet.") |
| 90 | else() |
| 91 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_func_api.c") |
| 92 | endif() |
Mingyang Sun | 9511e5e | 2019-05-29 18:18:44 +0800 | [diff] [blame] | 93 | endif() |
| 94 | |
Miklos Balint | 16a9ffb | 2018-11-19 11:35:49 +0100 | [diff] [blame] | 95 | if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION) |
| 96 | message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.") |
| 97 | elseif (TFM_NS_CLIENT_IDENTIFICATION) |
| 98 | list(APPEND NS_APP_SRC |
| 99 | "${INTERFACE_DIR}/src/tfm_nspm_svc_handler.c" |
| 100 | "${INTERFACE_DIR}/src/tfm_nspm_api.c" |
| 101 | ) |
| 102 | endif() |
| 103 | |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 104 | if (PSA_API_TEST_NS) |
| 105 | list(APPEND NS_APP_SRC "${APP_DIR}/psa_api_test.c") |
| 106 | endif() |
| 107 | |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 108 | if (TFM_PSA_API) |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 109 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_psa_ns_api.c") |
| 110 | endif() |
| 111 | |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 112 | set(BUILD_CMSIS_CORE On) |
| 113 | set(BUILD_RETARGET On) |
| 114 | set(BUILD_NATIVE_DRIVERS On) |
Mate Toth-Pal | a9f8e9e | 2019-03-05 16:11:14 +0100 | [diff] [blame] | 115 | set(BUILD_TIME On) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 116 | set(BUILD_STARTUP On) |
| 117 | set(BUILD_TARGET_CFG Off) |
| 118 | set(BUILD_TARGET_HARDWARE_KEYS Off) |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 119 | set(BUILD_TARGET_NV_COUNTERS Off) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 120 | set(BUILD_CMSIS_DRIVERS On) |
| 121 | set(BUILD_UART_STDOUT Off) |
| 122 | set(BUILD_FLASH Off) |
Tamas Ban | 3681ce0 | 2018-11-22 15:19:24 +0000 | [diff] [blame] | 123 | set(BUILD_BOOT_SEED Off) |
Tamas Ban | 2318feb | 2019-01-02 16:50:51 +0000 | [diff] [blame] | 124 | set(BUILD_DEVICE_ID Off) |
Mate Toth-Pal | a9f8e9e | 2019-03-05 16:11:14 +0100 | [diff] [blame] | 125 | if(CORE_TEST_POSITIVE) |
| 126 | set(BUILD_PLAT_TEST On) |
| 127 | set(BUILD_TIME On) |
| 128 | else() |
| 129 | set(BUILD_PLAT_TEST Off) |
| 130 | set(BUILD_TIME Off) |
| 131 | endif() |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 132 | if(NOT DEFINED PLATFORM_CMAKE_FILE) |
| 133 | message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") |
| 134 | elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) |
| 135 | message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") |
| 136 | else() |
| 137 | include(${PLATFORM_CMAKE_FILE}) |
| 138 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 139 | |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 140 | if(NOT DEFINED NS_SCATTER_FILE_NAME) |
| 141 | message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake") |
| 142 | endif() |
Gabor Kertesz | d7d7d74 | 2018-07-04 11:50:05 +0200 | [diff] [blame] | 143 | embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}") |
| 144 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 145 | #Create an object library to avoid compiling all source files twice, when two executables |
| 146 | #with different memory map need to be linked(BL2 non-swapping) |
| 147 | set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib) |
| 148 | add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC}) |
| 149 | |
| 150 | #Set common compiler flags |
| 151 | config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB}) |
| 152 | |
| 153 | #Set macro definitions |
David Hu | feae0f9 | 2019-06-17 13:42:20 +0800 | [diff] [blame] | 154 | set(TARGET_COMPILE_DEFINITIONS __thumb2__ __DOMAIN_NS=1 DOMAIN_NS=__DOMAIN_NS __ARM_FEATURE_CMSE=${ARM_FEATURE_CMSE}) |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 155 | target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE ${TARGET_COMPILE_DEFINITIONS}) |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 156 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 157 | #Set include directories. |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 158 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 159 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 160 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
| 161 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND) |
Ken Liu | b8ed8ba | 2019-07-09 12:52:08 +0800 | [diff] [blame] | 162 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/core/include ABSOLUTE APPEND) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 163 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND) |
| 164 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND) |
| 165 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 166 | |
Mate Toth-Pal | 5313609 | 2018-09-19 09:34:01 +0200 | [diff] [blame] | 167 | if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION) |
| 168 | message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.") |
| 169 | elseif (TFM_NS_CLIENT_IDENTIFICATION) |
| 170 | target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION) |
| 171 | endif() |
| 172 | |
David Hu | 8526f16 | 2019-05-21 15:35:26 +0800 | [diff] [blame] | 173 | add_subdirectory(${TFM_ROOT_DIR}/test ${CMAKE_BINARY_DIR}/test/non_secure_test) |
| 174 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 175 | # For the non-swapping BL2 configuration two executables need to be built. |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 176 | # One can be executed from the primary slot flash partition and other from the |
| 177 | # secondary slot. Only the linking phase is different. This function captures |
| 178 | # common settings and eliminates copy-paste. |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 179 | function(set_up_app_build) |
| 180 | set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE) |
| 181 | set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar") |
| 182 | set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX) |
| 183 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN}) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 184 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 185 | if (NOT DEFINED _MY_PARAMS_NS_TARGET) |
| 186 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 187 | endif() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 188 | |
| 189 | if (NOT DEFINED _MY_PARAMS_S_TARGET) |
| 190 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.") |
| 191 | endif() |
| 192 | |
| 193 | if (NOT DEFINED _MY_PARAMS_FULL_BIN) |
| 194 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.") |
| 195 | endif() |
| 196 | |
| 197 | if (NOT DEFINED _MY_PARAMS_SIGN_BIN) |
| 198 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.") |
| 199 | endif() |
| 200 | |
| 201 | if (NOT DEFINED _MY_PARAMS_VENEER_NAME) |
| 202 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.") |
| 203 | endif() |
| 204 | |
| 205 | set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX}) |
| 206 | set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX}) |
| 207 | set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX}) |
| 208 | set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX}) |
| 209 | set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o) |
| 210 | |
| 211 | #Create linker target: add object library to executable |
Tamas Ban | a4574d9 | 2019-03-06 14:21:33 +0000 | [diff] [blame] | 212 | add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 213 | |
| 214 | #Set common linker flags |
| 215 | config_setting_shared_linker_flags(${EXE_NAME}) |
| 216 | |
| 217 | #Set individual linker flags per linker target/executable |
| 218 | foreach(flag ${_MY_PARAMS_LINK_DEFINES}) |
| 219 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}") |
| 220 | endforeach(flag) |
| 221 | |
| 222 | embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}") |
| 223 | |
| 224 | #Add the RTX library |
| 225 | if(NOT DEFINED RTX_LIB_PATH) |
| 226 | message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.") |
| 227 | endif() |
| 228 | target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}") |
| 229 | |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 230 | #Add the PSA API compliance test libraries |
| 231 | if(NOT DEFINED PSA_API_TEST_BUILD_PATH) |
| 232 | #If not specified, assume it's the default build folder checked out at the same level of TFM root dir |
| 233 | set(PSA_API_TEST_BUILD_PATH "${TFM_ROOT_DIR}/../psa-arch-tests/api-tests/BUILD") |
| 234 | endif() |
| 235 | if(PSA_API_TEST_NS) |
| 236 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/val/val_nspe.a") |
| 237 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/platform/pal_nspe.a") |
| 238 | endif() |
Jamie Fox | 6b6a19b | 2019-09-30 16:54:17 +0100 | [diff] [blame^] | 239 | if(PSA_API_TEST_NS AND PSA_API_TEST_INTERNAL_TRUSTED_STORAGE) |
| 240 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/internal_trusted_storage/test_combine.a") |
| 241 | endif() |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 242 | if(PSA_API_TEST_NS AND PSA_API_TEST_SECURE_STORAGE) |
| 243 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/protected_storage/test_combine.a") |
| 244 | endif() |
| 245 | if(PSA_API_TEST_NS AND PSA_API_TEST_CRYPTO) |
| 246 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/crypto/test_combine.a") |
| 247 | endif() |
| 248 | if(PSA_API_TEST_NS AND PSA_API_TEST_ATTESTATION) |
| 249 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/initial_attestation/test_combine.a") |
| 250 | endif() |
| 251 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 252 | if(NOT DEFINED PLATFORM_LINK_INCLUDES) |
| 253 | message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.") |
| 254 | endif() |
| 255 | embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}") |
| 256 | |
| 257 | #Generate binary file from axf |
| 258 | compiler_generate_binary_output(${EXE_NAME}) |
| 259 | |
| 260 | #Generate MCUBoot compatible payload |
| 261 | if (BL2) |
| 262 | mcuboot_create_boot_payload(S_BIN ${S_BIN} |
| 263 | NS_BIN ${EXE_NAME} |
| 264 | FULL_BIN ${FULL_NAME} |
| 265 | SIGN_BIN ${SIGN_NAME} |
| 266 | POSTFIX ${_MY_PARAMS_POSTFIX}) |
| 267 | endif() |
| 268 | |
| 269 | if (NOT DEFINED TFM_PARTITION_TEST_CORE) |
| 270 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ") |
| 271 | elseif (TFM_PARTITION_TEST_CORE) |
| 272 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
| 273 | endif() |
| 274 | |
Jamie Fox | adf0255 | 2019-05-16 17:44:52 +0100 | [diff] [blame] | 275 | if (NOT DEFINED TFM_PARTITION_TEST_CORE_IPC) |
| 276 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE_IPC is undefined.") |
| 277 | elseif (TFM_PARTITION_TEST_CORE_IPC) |
| 278 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE_IPC") |
| 279 | endif() |
| 280 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 281 | if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES) |
| 282 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ") |
| 283 | elseif (TFM_PARTITION_TEST_SECURE_SERVICES) |
| 284 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES") |
| 285 | endif() |
| 286 | |
Marc Moreno Berengue | cae2c53 | 2018-10-09 12:58:46 +0100 | [diff] [blame] | 287 | if (NOT DEFINED TEST_FRAMEWORK_S) |
| 288 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.") |
| 289 | elseif (TEST_FRAMEWORK_S) |
| 290 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S") |
| 291 | endif() |
| 292 | |
| 293 | if (NOT DEFINED TEST_FRAMEWORK_NS) |
| 294 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.") |
| 295 | elseif (TEST_FRAMEWORK_NS) |
| 296 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS") |
| 297 | endif() |
| 298 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 299 | #Set BL2 specific settings. |
| 300 | if (BL2) |
David Vincze | 63eda7a | 2019-08-09 17:42:51 +0200 | [diff] [blame] | 301 | #Add BL2 and MCUBOOT_IMAGE_NUMBER defines to linker to resolve symbols in region_defs.h and flash_layout.h |
| 302 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2" "MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}") |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 303 | endif() |
| 304 | |
| 305 | #We depend on the non secure tests. See if the library target is available. |
| 306 | if(TARGET tfm_non_secure_tests) |
| 307 | #If yes, then use the library. |
| 308 | target_link_libraries(${EXE_NAME} tfm_non_secure_tests) |
| 309 | #Ensure library is built first. |
| 310 | add_dependencies(${EXE_NAME} tfm_non_secure_tests) |
| 311 | endif() |
| 312 | |
| 313 | #Ensure secure_fw is built before our executable. |
| 314 | add_dependencies(${EXE_NAME} ${S_BIN}) |
| 315 | |
Ken Liu | d8e0b8c | 2019-08-01 13:43:16 +0800 | [diff] [blame] | 316 | if (NOT DEFINED S_VENEER_PATH) |
| 317 | if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/../secure_fw) |
| 318 | set (S_VENEER_PATH "${CMAKE_CURRENT_BINARY_DIR}/../secure_fw") |
| 319 | else() |
| 320 | message(FATAL_ERROR "No valid path for S_VENEER_PATH, secure_fw is built?") |
| 321 | endif() |
| 322 | endif() |
| 323 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 324 | #Add the veneers to the executable. |
Ken Liu | d8e0b8c | 2019-08-01 13:43:16 +0800 | [diff] [blame] | 325 | set(S_VENEER_FILE "${S_VENEER_PATH}/${VENEER_NAME}") |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 326 | set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE}) |
| 327 | |
| 328 | #Collect executables to common location: build/install/outputs/ |
| 329 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf |
| 330 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin |
| 331 | DESTINATION outputs/${TARGET_PLATFORM}/) |
| 332 | |
| 333 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf |
| 334 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin |
| 335 | DESTINATION outputs/fvp/) |
| 336 | endfunction() |
| 337 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 338 | if (LINK_TO_BOTH_MEMORY_REGION) |
| 339 | #Link to primary memory region |
| 340 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
| 341 | S_TARGET tfm_s |
| 342 | FULL_BIN tfm_full |
| 343 | SIGN_BIN tfm_sign |
Tamas Ban | bba8564 | 2019-06-06 09:31:59 +0100 | [diff] [blame] | 344 | VENEER_NAME s_veneers) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 345 | |
| 346 | #Link to secondary memory region(add extra linker flag) |
Oliver Swede | 2144044 | 2018-07-10 09:31:32 +0100 | [diff] [blame] | 347 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 348 | LINK_DEFINES "LINK_TO_SECONDARY_PARTITION" |
| 349 | S_TARGET tfm_s |
| 350 | FULL_BIN tfm_full |
| 351 | SIGN_BIN tfm_sign |
| 352 | VENEER_NAME s_veneers |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 353 | POSTFIX "_1") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 354 | else() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 355 | #Link to primary memory region only |
Oliver Swede | 2144044 | 2018-07-10 09:31:32 +0100 | [diff] [blame] | 356 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 357 | S_TARGET tfm_s |
| 358 | FULL_BIN tfm_full |
| 359 | SIGN_BIN tfm_sign |
| 360 | VENEER_NAME s_veneers) |
| 361 | endif() |
| 362 | |
| 363 | #If the tfm_non_secure_tests target is not available |
| 364 | if(NOT TARGET tfm_non_secure_tests) |
| 365 | #Add the test source to the build. |
| 366 | #As of today since secure_fw is built as a sub-project this code will never execute. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 367 | option(ENABLE_INVERT_SERVICE_TESTS "" TRUE) |
| 368 | option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE) |
| 369 | include(../test/CMakeLists.inc) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 370 | target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS}) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 371 | endif() |
| 372 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 373 | #Finally let CMake system apply changes after the whole project is defined. |
| 374 | if (TARGET ${PROJECT_NAME}) |
| 375 | embedded_project_end(${PROJECT_NAME}) |
| 376 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 377 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 378 | if (TARGET ${PROJECT_NAME}_1) |
| 379 | embedded_project_end(${PROJECT_NAME}_1) |
| 380 | endif() |
| 381 | |
| 382 | embedded_project_end(${PROJECT_OBJ_LIB}) |