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 | c73130f | 2019-10-22 17:27:18 +0800 | [diff] [blame^] | 51 | if (NOT DEFINED TFM_PARTITION_SECURE_STORAGE) |
| 52 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_SECURE_STORAGE is undefined.") |
| 53 | endif() |
| 54 | |
| 55 | if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE) |
| 56 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INTERNAL_TRUSTED_STORAGE is undefined.") |
| 57 | endif() |
| 58 | |
| 59 | if (NOT DEFINED TFM_PARTITION_CRYPTO) |
| 60 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_CRYPTO is undefined.") |
| 61 | endif() |
| 62 | |
| 63 | if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION) |
| 64 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INITIAL_ATTESTATION is undefined.") |
| 65 | endif() |
| 66 | |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 67 | if (NOT DEFINED TFM_PSA_API) |
| 68 | message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined.") |
| 69 | endif() |
| 70 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 71 | set(NS_APP_SRC "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config/RTX_Config.c" |
| 72 | "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Source/rtx_lib.c" |
| 73 | "${APP_DIR}/main_ns.c" |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 74 | "${APP_DIR}/tfm_integ_test.c" |
Kevin Peng | d36a7fc | 2019-07-22 16:01:10 +0800 | [diff] [blame] | 75 | "${APP_DIR}/os_wrapper_cmsis_rtos_v2.c" |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 76 | ) |
| 77 | |
David Hu | d87d12f | 2019-09-24 15:25:52 +0800 | [diff] [blame] | 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 | |
Jamie Fox | c78c62c | 2019-05-23 13:42:17 +0100 | [diff] [blame] | 82 | if (TFM_PARTITION_AUDIT_LOG) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 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() |
Jamie Fox | c78c62c | 2019-05-23 13:42:17 +0100 | [diff] [blame] | 88 | endif() |
| 89 | |
Mingyang Sun | 9511e5e | 2019-05-29 18:18:44 +0800 | [diff] [blame] | 90 | if (TFM_PARTITION_PLATFORM) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 91 | if (TFM_PSA_API) |
Mate Toth-Pal | 179a156 | 2019-11-08 11:40:27 +0100 | [diff] [blame] | 92 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_ipc_api.c") |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 93 | else() |
| 94 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_func_api.c") |
| 95 | endif() |
Mingyang Sun | 9511e5e | 2019-05-29 18:18:44 +0800 | [diff] [blame] | 96 | endif() |
| 97 | |
Kevin Peng | c73130f | 2019-10-22 17:27:18 +0800 | [diff] [blame^] | 98 | if (TFM_PARTITION_SECURE_STORAGE) |
| 99 | if (TFM_PSA_API) |
| 100 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_sst_ipc_api.c") |
| 101 | else() |
| 102 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_sst_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 | |
Miklos Balint | 16a9ffb | 2018-11-19 11:35:49 +0100 | [diff] [blame] | 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 | |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 139 | if (PSA_API_TEST_NS) |
| 140 | list(APPEND NS_APP_SRC "${APP_DIR}/psa_api_test.c") |
| 141 | endif() |
| 142 | |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 143 | if (TFM_PSA_API) |
David Hu | d2753b3 | 2019-09-23 18:46:15 +0800 | [diff] [blame] | 144 | if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY) |
David Hu | 3fac96a | 2019-09-24 14:40:11 +0800 | [diff] [blame] | 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 | ) |
David Hu | d2753b3 | 2019-09-23 18:46:15 +0800 | [diff] [blame] | 149 | else() |
| 150 | list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_psa_ns_api.c") |
| 151 | endif() |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 152 | endif() |
| 153 | |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 154 | set(BUILD_CMSIS_CORE On) |
| 155 | set(BUILD_RETARGET On) |
| 156 | set(BUILD_NATIVE_DRIVERS On) |
Mate Toth-Pal | a9f8e9e | 2019-03-05 16:11:14 +0100 | [diff] [blame] | 157 | set(BUILD_TIME On) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 158 | set(BUILD_STARTUP On) |
| 159 | set(BUILD_TARGET_CFG Off) |
| 160 | set(BUILD_TARGET_HARDWARE_KEYS Off) |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 161 | set(BUILD_TARGET_NV_COUNTERS Off) |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 162 | set(BUILD_CMSIS_DRIVERS On) |
| 163 | set(BUILD_UART_STDOUT Off) |
| 164 | set(BUILD_FLASH Off) |
Mate Toth-Pal | a9f8e9e | 2019-03-05 16:11:14 +0100 | [diff] [blame] | 165 | if(CORE_TEST_POSITIVE) |
| 166 | set(BUILD_PLAT_TEST On) |
| 167 | set(BUILD_TIME On) |
| 168 | else() |
| 169 | set(BUILD_PLAT_TEST Off) |
| 170 | set(BUILD_TIME Off) |
| 171 | endif() |
Marc Moreno Berengue | a1f296f | 2018-01-25 15:21:22 +0000 | [diff] [blame] | 172 | if(NOT DEFINED PLATFORM_CMAKE_FILE) |
| 173 | message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") |
| 174 | elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) |
| 175 | message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") |
| 176 | else() |
| 177 | include(${PLATFORM_CMAKE_FILE}) |
| 178 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 179 | |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 180 | if(NOT DEFINED NS_SCATTER_FILE_NAME) |
| 181 | message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake") |
| 182 | endif() |
Gabor Kertesz | d7d7d74 | 2018-07-04 11:50:05 +0200 | [diff] [blame] | 183 | embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}") |
| 184 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 185 | #Create an object library to avoid compiling all source files twice, when two executables |
| 186 | #with different memory map need to be linked(BL2 non-swapping) |
| 187 | set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib) |
Chris Brand | 7766066 | 2019-12-04 10:25:46 -0800 | [diff] [blame] | 188 | add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM} ${ALL_SRC_ASM_NS} ${NS_APP_SRC}) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 189 | |
| 190 | #Set common compiler flags |
| 191 | config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB}) |
| 192 | |
| 193 | #Set macro definitions |
David Hu | feae0f9 | 2019-06-17 13:42:20 +0800 | [diff] [blame] | 194 | 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] | 195 | target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE ${TARGET_COMPILE_DEFINITIONS}) |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 196 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 197 | #Set include directories. |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 198 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 199 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND) |
| 200 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND) |
| 201 | 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] | 202 | 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] | 203 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND) |
| 204 | embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND) |
| 205 | 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] | 206 | |
Mate Toth-Pal | 5313609 | 2018-09-19 09:34:01 +0200 | [diff] [blame] | 207 | if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION) |
| 208 | message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.") |
| 209 | elseif (TFM_NS_CLIENT_IDENTIFICATION) |
| 210 | target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION) |
| 211 | endif() |
| 212 | |
David Hu | 8526f16 | 2019-05-21 15:35:26 +0800 | [diff] [blame] | 213 | add_subdirectory(${TFM_ROOT_DIR}/test ${CMAKE_BINARY_DIR}/test/non_secure_test) |
| 214 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 215 | # For the non-swapping BL2 configuration two executables need to be built. |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 216 | # One can be executed from the primary slot flash partition and other from the |
| 217 | # secondary slot. Only the linking phase is different. This function captures |
| 218 | # common settings and eliminates copy-paste. |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 219 | function(set_up_app_build) |
| 220 | set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE) |
| 221 | set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar") |
| 222 | set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX) |
| 223 | 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] | 224 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 225 | if (NOT DEFINED _MY_PARAMS_NS_TARGET) |
| 226 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 227 | endif() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 228 | |
| 229 | if (NOT DEFINED _MY_PARAMS_S_TARGET) |
| 230 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.") |
| 231 | endif() |
| 232 | |
| 233 | if (NOT DEFINED _MY_PARAMS_FULL_BIN) |
| 234 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.") |
| 235 | endif() |
| 236 | |
| 237 | if (NOT DEFINED _MY_PARAMS_SIGN_BIN) |
| 238 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.") |
| 239 | endif() |
| 240 | |
| 241 | if (NOT DEFINED _MY_PARAMS_VENEER_NAME) |
| 242 | message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.") |
| 243 | endif() |
| 244 | |
| 245 | set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX}) |
| 246 | set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX}) |
| 247 | set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX}) |
| 248 | set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX}) |
| 249 | set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o) |
| 250 | |
| 251 | #Create linker target: add object library to executable |
Tamas Ban | a4574d9 | 2019-03-06 14:21:33 +0000 | [diff] [blame] | 252 | add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 253 | |
| 254 | #Set common linker flags |
| 255 | config_setting_shared_linker_flags(${EXE_NAME}) |
| 256 | |
| 257 | #Set individual linker flags per linker target/executable |
| 258 | foreach(flag ${_MY_PARAMS_LINK_DEFINES}) |
| 259 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}") |
| 260 | endforeach(flag) |
| 261 | |
| 262 | embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}") |
| 263 | |
| 264 | #Add the RTX library |
| 265 | if(NOT DEFINED RTX_LIB_PATH) |
| 266 | message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.") |
| 267 | endif() |
| 268 | target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}") |
| 269 | |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 270 | #Add the PSA API compliance test libraries |
| 271 | if(NOT DEFINED PSA_API_TEST_BUILD_PATH) |
| 272 | #If not specified, assume it's the default build folder checked out at the same level of TFM root dir |
| 273 | set(PSA_API_TEST_BUILD_PATH "${TFM_ROOT_DIR}/../psa-arch-tests/api-tests/BUILD") |
| 274 | endif() |
| 275 | if(PSA_API_TEST_NS) |
| 276 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/val/val_nspe.a") |
| 277 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/platform/pal_nspe.a") |
| 278 | endif() |
Jamie Fox | 6b6a19b | 2019-09-30 16:54:17 +0100 | [diff] [blame] | 279 | if(PSA_API_TEST_NS AND PSA_API_TEST_INTERNAL_TRUSTED_STORAGE) |
| 280 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/internal_trusted_storage/test_combine.a") |
| 281 | endif() |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 282 | if(PSA_API_TEST_NS AND PSA_API_TEST_SECURE_STORAGE) |
| 283 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/protected_storage/test_combine.a") |
| 284 | endif() |
| 285 | if(PSA_API_TEST_NS AND PSA_API_TEST_CRYPTO) |
| 286 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/crypto/test_combine.a") |
| 287 | endif() |
| 288 | if(PSA_API_TEST_NS AND PSA_API_TEST_ATTESTATION) |
| 289 | target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/initial_attestation/test_combine.a") |
| 290 | endif() |
| 291 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 292 | if(NOT DEFINED PLATFORM_LINK_INCLUDES) |
| 293 | message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.") |
| 294 | endif() |
| 295 | embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}") |
| 296 | |
| 297 | #Generate binary file from axf |
| 298 | compiler_generate_binary_output(${EXE_NAME}) |
| 299 | |
| 300 | #Generate MCUBoot compatible payload |
| 301 | if (BL2) |
| 302 | mcuboot_create_boot_payload(S_BIN ${S_BIN} |
| 303 | NS_BIN ${EXE_NAME} |
| 304 | FULL_BIN ${FULL_NAME} |
| 305 | SIGN_BIN ${SIGN_NAME} |
| 306 | POSTFIX ${_MY_PARAMS_POSTFIX}) |
| 307 | endif() |
| 308 | |
| 309 | if (NOT DEFINED TFM_PARTITION_TEST_CORE) |
| 310 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ") |
| 311 | elseif (TFM_PARTITION_TEST_CORE) |
| 312 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE") |
| 313 | endif() |
| 314 | |
Jamie Fox | adf0255 | 2019-05-16 17:44:52 +0100 | [diff] [blame] | 315 | if (NOT DEFINED TFM_PARTITION_TEST_CORE_IPC) |
| 316 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE_IPC is undefined.") |
| 317 | elseif (TFM_PARTITION_TEST_CORE_IPC) |
| 318 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE_IPC") |
| 319 | endif() |
| 320 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 321 | if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES) |
| 322 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ") |
| 323 | elseif (TFM_PARTITION_TEST_SECURE_SERVICES) |
| 324 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES") |
| 325 | endif() |
| 326 | |
Marc Moreno Berengue | cae2c53 | 2018-10-09 12:58:46 +0100 | [diff] [blame] | 327 | if (NOT DEFINED TEST_FRAMEWORK_S) |
| 328 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.") |
| 329 | elseif (TEST_FRAMEWORK_S) |
| 330 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S") |
| 331 | endif() |
| 332 | |
| 333 | if (NOT DEFINED TEST_FRAMEWORK_NS) |
| 334 | message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.") |
| 335 | elseif (TEST_FRAMEWORK_NS) |
| 336 | embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS") |
| 337 | endif() |
| 338 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 339 | #Set BL2 specific settings. |
| 340 | if (BL2) |
David Vincze | 63eda7a | 2019-08-09 17:42:51 +0200 | [diff] [blame] | 341 | #Add BL2 and MCUBOOT_IMAGE_NUMBER defines to linker to resolve symbols in region_defs.h and flash_layout.h |
| 342 | 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] | 343 | endif() |
| 344 | |
| 345 | #We depend on the non secure tests. See if the library target is available. |
| 346 | if(TARGET tfm_non_secure_tests) |
| 347 | #If yes, then use the library. |
| 348 | target_link_libraries(${EXE_NAME} tfm_non_secure_tests) |
| 349 | #Ensure library is built first. |
| 350 | add_dependencies(${EXE_NAME} tfm_non_secure_tests) |
| 351 | endif() |
| 352 | |
| 353 | #Ensure secure_fw is built before our executable. |
| 354 | add_dependencies(${EXE_NAME} ${S_BIN}) |
| 355 | |
David Hu | d87d12f | 2019-09-24 15:25:52 +0800 | [diff] [blame] | 356 | if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY) |
| 357 | if (NOT DEFINED S_VENEER_PATH) |
| 358 | if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/../secure_fw) |
| 359 | set (S_VENEER_PATH "${CMAKE_CURRENT_BINARY_DIR}/../secure_fw") |
| 360 | else() |
| 361 | message(FATAL_ERROR "No valid path for S_VENEER_PATH, secure_fw is built?") |
| 362 | endif() |
Ken Liu | d8e0b8c | 2019-08-01 13:43:16 +0800 | [diff] [blame] | 363 | endif() |
Ken Liu | d8e0b8c | 2019-08-01 13:43:16 +0800 | [diff] [blame] | 364 | |
David Hu | d87d12f | 2019-09-24 15:25:52 +0800 | [diff] [blame] | 365 | #Add the veneers to the executable. |
| 366 | set(S_VENEER_FILE "${S_VENEER_PATH}/${VENEER_NAME}") |
| 367 | set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE}) |
| 368 | endif() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 369 | |
| 370 | #Collect executables to common location: build/install/outputs/ |
| 371 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf |
| 372 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin |
| 373 | DESTINATION outputs/${TARGET_PLATFORM}/) |
| 374 | |
| 375 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf |
| 376 | ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin |
| 377 | DESTINATION outputs/fvp/) |
| 378 | endfunction() |
| 379 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 380 | if (LINK_TO_BOTH_MEMORY_REGION) |
| 381 | #Link to primary memory region |
| 382 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
| 383 | S_TARGET tfm_s |
| 384 | FULL_BIN tfm_full |
| 385 | SIGN_BIN tfm_sign |
Tamas Ban | bba8564 | 2019-06-06 09:31:59 +0100 | [diff] [blame] | 386 | VENEER_NAME s_veneers) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 387 | |
| 388 | #Link to secondary memory region(add extra linker flag) |
Oliver Swede | 2144044 | 2018-07-10 09:31:32 +0100 | [diff] [blame] | 389 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 390 | LINK_DEFINES "LINK_TO_SECONDARY_PARTITION" |
| 391 | S_TARGET tfm_s |
| 392 | FULL_BIN tfm_full |
| 393 | SIGN_BIN tfm_sign |
| 394 | VENEER_NAME s_veneers |
Tamas Ban | 57bfa43 | 2018-04-13 16:05:49 +0100 | [diff] [blame] | 395 | POSTFIX "_1") |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 396 | else() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 397 | #Link to primary memory region only |
Oliver Swede | 2144044 | 2018-07-10 09:31:32 +0100 | [diff] [blame] | 398 | set_up_app_build(NS_TARGET ${PROJECT_NAME} |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 399 | S_TARGET tfm_s |
| 400 | FULL_BIN tfm_full |
| 401 | SIGN_BIN tfm_sign |
| 402 | VENEER_NAME s_veneers) |
| 403 | endif() |
| 404 | |
| 405 | #If the tfm_non_secure_tests target is not available |
| 406 | if(NOT TARGET tfm_non_secure_tests) |
| 407 | #Add the test source to the build. |
| 408 | #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] | 409 | option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE) |
| 410 | include(../test/CMakeLists.inc) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 411 | 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] | 412 | endif() |
| 413 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 414 | #Finally let CMake system apply changes after the whole project is defined. |
| 415 | if (TARGET ${PROJECT_NAME}) |
| 416 | embedded_project_end(${PROJECT_NAME}) |
| 417 | endif() |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 418 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 419 | if (TARGET ${PROJECT_NAME}_1) |
| 420 | embedded_project_end(${PROJECT_NAME}_1) |
| 421 | endif() |
| 422 | |
| 423 | embedded_project_end(${PROJECT_OBJ_LIB}) |