blob: eadbb54aafba4a4e6f11ce644844f3f62de0fc35 [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
David Hu65cbfb82019-11-15 17:18:12 +08002# Copyright (c) 2017-2020, Arm Limited. All rights reserved.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8cmake_minimum_required(VERSION 3.7)
9
David Hu857bfa52019-05-21 13:54:50 +080010set(TFM_BUILD_IN_SPE OFF)
11
Gyorgy Szing30fa9872017-12-05 01:08:47 +000012#Tell cmake where our modules can be found
13list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
14
Gyorgy Szing30fa9872017-12-05 01:08:47 +000015set(APP_DIR ${CMAKE_CURRENT_LIST_DIR})
16get_filename_component(TFM_ROOT_DIR ${APP_DIR}/.. ABSOLUTE)
17set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface)
Mate Toth-Pal813e9d12019-01-17 15:51:29 +010018set(TEST_DIR ${TFM_ROOT_DIR}/test)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000019
Ken Liue40f9a22019-06-03 16:42:47 +080020#Include common stuff to control cmake.
21include("Common/BuildSys")
22
23#Start an embedded project.
24embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake")
25project(tfm_ns LANGUAGES ASM C)
26embedded_project_fixup()
27
Tamas Bandb69d522018-03-01 10:04:41 +000028#Include BL2 bootloader related functions
29set(MCUBOOT_DIR "${TFM_ROOT_DIR}/bl2/ext/mcuboot")
30include("${MCUBOOT_DIR}/MCUBoot.cmake")
31
Gyorgy Szing30fa9872017-12-05 01:08:47 +000032#Set variables
33get_filename_component(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5 ABSOLUTE)
34
35if(NOT EXISTS ${CMSIS_5_DIR})
36 message(FATAL_ERROR "Missing CMSIS_5. Please clone the CMSIS_5 repo to directory \"${CMSIS_5_DIR}\".")
37endif()
38
Tamas Bandb69d522018-03-01 10:04:41 +000039if (NOT DEFINED BL2)
40 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
41endif ()
42
Jamie Foxc78c62c2019-05-23 13:42:17 +010043if (NOT DEFINED TFM_PARTITION_AUDIT_LOG)
44 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_AUDIT_LOG is undefined.")
45endif()
46
Mingyang Sun9511e5e2019-05-29 18:18:44 +080047if (NOT DEFINED TFM_PARTITION_PLATFORM)
48 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PLATFORM is undefined.")
49endif()
50
Kevin Pengc73130f2019-10-22 17:27:18 +080051if (NOT DEFINED TFM_PARTITION_SECURE_STORAGE)
52 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_SECURE_STORAGE is undefined.")
53endif()
54
55if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
56 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INTERNAL_TRUSTED_STORAGE is undefined.")
57endif()
58
59if (NOT DEFINED TFM_PARTITION_CRYPTO)
60 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_CRYPTO is undefined.")
61endif()
62
63if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION)
64 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INITIAL_ATTESTATION is undefined.")
65endif()
66
Kevin Peng9449a362019-07-29 16:05:42 +080067if (NOT DEFINED TFM_PSA_API)
68 message(FATAL_ERROR "Incomplete build configuration: TFM_PSA_API is undefined.")
69endif()
70
Mingyang Sune5da4ad2019-12-19 15:15:48 +080071embedded_include_directories(PATH ${TFM_ROOT_DIR}/app ABSOLUTE)
72
Gyorgy Szing30fa9872017-12-05 01:08:47 +000073set(NS_APP_SRC "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config/RTX_Config.c"
74 "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Source/rtx_lib.c"
75 "${APP_DIR}/main_ns.c"
Gyorgy Szing30fa9872017-12-05 01:08:47 +000076 "${APP_DIR}/tfm_integ_test.c"
Kevin Pengd36a7fc2019-07-22 16:01:10 +080077 "${APP_DIR}/os_wrapper_cmsis_rtos_v2.c"
Mingyang Sune5da4ad2019-12-19 15:15:48 +080078 "${TFM_ROOT_DIR}/interface/src/log/tfm_log_raw.c"
Gyorgy Szing30fa9872017-12-05 01:08:47 +000079 )
80
David Hud87d12f2019-09-24 15:25:52 +080081if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY)
82 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ns_interface.c")
83endif()
84
Jamie Foxc78c62c2019-05-23 13:42:17 +010085if (TFM_PARTITION_AUDIT_LOG)
Kevin Peng9449a362019-07-29 16:05:42 +080086 if (TFM_PSA_API)
87 message(FATAL_ERROR "Audit log has not been supported in IPC model yet.")
88 else()
89 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_audit_func_api.c")
90 endif()
Jamie Foxc78c62c2019-05-23 13:42:17 +010091endif()
92
Mingyang Sun9511e5e2019-05-29 18:18:44 +080093if (TFM_PARTITION_PLATFORM)
Kevin Peng9449a362019-07-29 16:05:42 +080094 if (TFM_PSA_API)
Mate Toth-Pal179a1562019-11-08 11:40:27 +010095 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_ipc_api.c")
Kevin Peng9449a362019-07-29 16:05:42 +080096 else()
97 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_platform_func_api.c")
98 endif()
Mingyang Sun9511e5e2019-05-29 18:18:44 +080099endif()
100
Kevin Pengc73130f2019-10-22 17:27:18 +0800101if (TFM_PARTITION_SECURE_STORAGE)
102 if (TFM_PSA_API)
103 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_sst_ipc_api.c")
104 else()
105 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_sst_func_api.c")
106 endif()
107endif()
108
109if (TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
110 if (TFM_PSA_API)
111 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_its_ipc_api.c")
112 else()
113 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_its_func_api.c")
114 endif()
115endif()
116
117if (TFM_PARTITION_CRYPTO)
118 if (TFM_PSA_API)
119 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_crypto_ipc_api.c")
120 else()
121 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_crypto_func_api.c")
122 endif()
123endif()
124
125if (TFM_PARTITION_INITIAL_ATTESTATION)
126 if (TFM_PSA_API)
127 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_initial_attestation_ipc_api.c")
128 else()
129 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_initial_attestation_func_api.c")
130 endif()
131endif()
132
Miklos Balint16a9ffb2018-11-19 11:35:49 +0100133if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
134 message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
135elseif (TFM_NS_CLIENT_IDENTIFICATION)
136 list(APPEND NS_APP_SRC
137 "${INTERFACE_DIR}/src/tfm_nspm_svc_handler.c"
138 "${INTERFACE_DIR}/src/tfm_nspm_api.c"
139 )
140endif()
141
Jamie Fox17c30bb2019-01-10 13:39:33 +0000142if (PSA_API_TEST_NS)
143 list(APPEND NS_APP_SRC "${APP_DIR}/psa_api_test.c")
144endif()
145
Kevin Peng9449a362019-07-29 16:05:42 +0800146if (TFM_PSA_API)
David Hud2753b32019-09-23 18:46:15 +0800147 if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY)
David Hu3fac96a2019-09-24 14:40:11 +0800148 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_ns_mailbox.c"
149 "${INTERFACE_DIR}/src/tfm_multi_core_api.c"
150 "${INTERFACE_DIR}/src/tfm_multi_core_psa_ns_api.c"
151 )
David Hu65cbfb82019-11-15 17:18:12 +0800152
153 if (TFM_MULTI_CORE_TEST)
154 add_definitions(-DTFM_MULTI_CORE_TEST)
155 endif()
David Hud2753b32019-09-23 18:46:15 +0800156 else()
157 list(APPEND NS_APP_SRC "${INTERFACE_DIR}/src/tfm_psa_ns_api.c")
158 endif()
Miklos Balint87da2512018-04-19 13:45:50 +0200159endif()
160
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +0000161set(BUILD_CMSIS_CORE On)
162set(BUILD_RETARGET On)
163set(BUILD_NATIVE_DRIVERS On)
Mate Toth-Pala9f8e9e2019-03-05 16:11:14 +0100164set(BUILD_TIME On)
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +0000165set(BUILD_STARTUP On)
166set(BUILD_TARGET_CFG Off)
167set(BUILD_TARGET_HARDWARE_KEYS Off)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +0100168set(BUILD_TARGET_NV_COUNTERS Off)
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +0000169set(BUILD_CMSIS_DRIVERS On)
Kevin Peng524e3ec2020-05-29 10:28:26 +0800170set(BUILD_UART_STDOUT On)
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +0000171set(BUILD_FLASH Off)
Mate Toth-Pala9f8e9e2019-03-05 16:11:14 +0100172if(CORE_TEST_POSITIVE)
173 set(BUILD_PLAT_TEST On)
174 set(BUILD_TIME On)
175else()
176 set(BUILD_PLAT_TEST Off)
177 set(BUILD_TIME Off)
178endif()
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +0000179if(NOT DEFINED PLATFORM_CMAKE_FILE)
180 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
181elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
182 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
183else()
184 include(${PLATFORM_CMAKE_FILE})
185endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000186
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100187if(NOT DEFINED NS_SCATTER_FILE_NAME)
188 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
189endif()
Gabor Kerteszd7d7d742018-07-04 11:50:05 +0200190embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}")
191
Tamas Bandb69d522018-03-01 10:04:41 +0000192#Create an object library to avoid compiling all source files twice, when two executables
193#with different memory map need to be linked(BL2 non-swapping)
194set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib)
Chris Brand77660662019-12-04 10:25:46 -0800195add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
Tamas Bandb69d522018-03-01 10:04:41 +0000196
197#Set common compiler flags
198config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB})
199
200#Set macro definitions
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100201set(TARGET_COMPILE_DEFINITIONS __thumb2__ __DOMAIN_NS=1 DOMAIN_NS=__DOMAIN_NS)
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100202target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE ${TARGET_COMPILE_DEFINITIONS})
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100203
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000204#Set include directories.
Tamas Bandb69d522018-03-01 10:04:41 +0000205embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
206embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
207embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
208embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
Ken Liub8ed8ba2019-07-09 12:52:08 +0800209embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/core/include ABSOLUTE APPEND)
Tamas Bandb69d522018-03-01 10:04:41 +0000210embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
211embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
212embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000213
Mate Toth-Pal53136092018-09-19 09:34:01 +0200214if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
215 message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
216elseif (TFM_NS_CLIENT_IDENTIFICATION)
217 target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION)
218endif()
219
David Hu8526f162019-05-21 15:35:26 +0800220add_subdirectory(${TFM_ROOT_DIR}/test ${CMAKE_BINARY_DIR}/test/non_secure_test)
221
Tamas Bandb69d522018-03-01 10:04:41 +0000222# For the non-swapping BL2 configuration two executables need to be built.
David Vincze8bdfc2d2019-03-18 15:49:23 +0100223# One can be executed from the primary slot flash partition and other from the
224# secondary slot. Only the linking phase is different. This function captures
225# common settings and eliminates copy-paste.
Tamas Bandb69d522018-03-01 10:04:41 +0000226function(set_up_app_build)
227 set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE)
228 set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
229 set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX)
230 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000231
Tamas Bandb69d522018-03-01 10:04:41 +0000232 if (NOT DEFINED _MY_PARAMS_NS_TARGET)
233 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000234 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000235
236 if (NOT DEFINED _MY_PARAMS_S_TARGET)
237 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.")
238 endif()
239
240 if (NOT DEFINED _MY_PARAMS_FULL_BIN)
241 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.")
242 endif()
243
244 if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
245 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.")
246 endif()
247
248 if (NOT DEFINED _MY_PARAMS_VENEER_NAME)
249 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.")
250 endif()
251
252 set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX})
253 set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX})
254 set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX})
255 set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX})
256 set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
257
258 #Create linker target: add object library to executable
Tamas Bana4574d92019-03-06 14:21:33 +0000259 add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
Tamas Bandb69d522018-03-01 10:04:41 +0000260
261 #Set common linker flags
262 config_setting_shared_linker_flags(${EXE_NAME})
263
264 #Set individual linker flags per linker target/executable
265 foreach(flag ${_MY_PARAMS_LINK_DEFINES})
266 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}")
267 endforeach(flag)
268
269 embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}")
270
271 #Add the RTX library
272 if(NOT DEFINED RTX_LIB_PATH)
273 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
274 endif()
275 target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}")
276
Jamie Fox17c30bb2019-01-10 13:39:33 +0000277 #Add the PSA API compliance test libraries
Jamie Fox17c30bb2019-01-10 13:39:33 +0000278 if(PSA_API_TEST_NS)
279 target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/val/val_nspe.a")
280 target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/platform/pal_nspe.a")
281 endif()
Vinay Kumar Kotegowder75641062020-04-24 16:44:12 +0530282 if(PSA_API_TEST_NS AND (PSA_API_TEST_INTERNAL_TRUSTED_STORAGE OR PSA_API_TEST_PROTECTED_STORAGE OR PSA_API_TEST_STORAGE))
283 target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/storage/test_combine.a")
Jamie Fox17c30bb2019-01-10 13:39:33 +0000284 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()
Karl Zhang1895a2c2020-03-08 18:27:32 +0800288 if(PSA_API_TEST_NS AND PSA_API_TEST_INITIAL_ATTESTATION)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000289 target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/dev_apis/initial_attestation/test_combine.a")
290 endif()
Jaykumar Pitambarbhai Patel38e6db52020-01-09 16:35:41 +0530291 if(PSA_API_TEST_NS AND PSA_API_TEST_IPC)
292 target_link_libraries(${EXE_NAME} "${PSA_API_TEST_BUILD_PATH}/ff/ipc/test_combine.a")
293 endif()
Jamie Fox17c30bb2019-01-10 13:39:33 +0000294
Tamas Bandb69d522018-03-01 10:04:41 +0000295 if(NOT DEFINED PLATFORM_LINK_INCLUDES)
296 message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
297 endif()
298 embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
299
300 #Generate binary file from axf
301 compiler_generate_binary_output(${EXE_NAME})
302
303 #Generate MCUBoot compatible payload
304 if (BL2)
305 mcuboot_create_boot_payload(S_BIN ${S_BIN}
306 NS_BIN ${EXE_NAME}
307 FULL_BIN ${FULL_NAME}
308 SIGN_BIN ${SIGN_NAME}
309 POSTFIX ${_MY_PARAMS_POSTFIX})
310 endif()
311
312 if (NOT DEFINED TFM_PARTITION_TEST_CORE)
313 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
314 elseif (TFM_PARTITION_TEST_CORE)
315 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
316 endif()
317
Jamie Foxadf02552019-05-16 17:44:52 +0100318 if (NOT DEFINED TFM_PARTITION_TEST_CORE_IPC)
319 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE_IPC is undefined.")
320 elseif (TFM_PARTITION_TEST_CORE_IPC)
321 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE_IPC")
322 endif()
323
Tamas Bandb69d522018-03-01 10:04:41 +0000324 if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
325 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
326 elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
327 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
328 endif()
329
Marc Moreno Berenguecae2c532018-10-09 12:58:46 +0100330 if (NOT DEFINED TEST_FRAMEWORK_S)
331 message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.")
332 elseif (TEST_FRAMEWORK_S)
333 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S")
334 endif()
335
336 if (NOT DEFINED TEST_FRAMEWORK_NS)
337 message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.")
338 elseif (TEST_FRAMEWORK_NS)
339 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS")
340 endif()
341
Tamas Bandb69d522018-03-01 10:04:41 +0000342 #Set BL2 specific settings.
343 if (BL2)
David Vincze63eda7a2019-08-09 17:42:51 +0200344 #Add BL2 and MCUBOOT_IMAGE_NUMBER defines to linker to resolve symbols in region_defs.h and flash_layout.h
345 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2" "MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}")
Tamas Bandb69d522018-03-01 10:04:41 +0000346 endif()
347
348 #We depend on the non secure tests. See if the library target is available.
349 if(TARGET tfm_non_secure_tests)
350 #If yes, then use the library.
351 target_link_libraries(${EXE_NAME} tfm_non_secure_tests)
352 #Ensure library is built first.
353 add_dependencies(${EXE_NAME} tfm_non_secure_tests)
354 endif()
355
356 #Ensure secure_fw is built before our executable.
357 add_dependencies(${EXE_NAME} ${S_BIN})
358
David Hud87d12f2019-09-24 15:25:52 +0800359 if (NOT DEFINED TFM_MULTI_CORE_TOPOLOGY OR NOT TFM_MULTI_CORE_TOPOLOGY)
360 if (NOT DEFINED S_VENEER_PATH)
361 if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/../secure_fw)
362 set (S_VENEER_PATH "${CMAKE_CURRENT_BINARY_DIR}/../secure_fw")
363 else()
364 message(FATAL_ERROR "No valid path for S_VENEER_PATH, secure_fw is built?")
365 endif()
Ken Liud8e0b8c2019-08-01 13:43:16 +0800366 endif()
Ken Liud8e0b8c2019-08-01 13:43:16 +0800367
David Hud87d12f2019-09-24 15:25:52 +0800368 #Add the veneers to the executable.
369 set(S_VENEER_FILE "${S_VENEER_PATH}/${VENEER_NAME}")
370 set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
371 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000372
373 #Collect executables to common location: build/install/outputs/
374 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
375 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
376 DESTINATION outputs/${TARGET_PLATFORM}/)
377
378 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
379 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
380 DESTINATION outputs/fvp/)
381endfunction()
382
Tamas Bandb69d522018-03-01 10:04:41 +0000383if (LINK_TO_BOTH_MEMORY_REGION)
384 #Link to primary memory region
385 set_up_app_build(NS_TARGET ${PROJECT_NAME}
386 S_TARGET tfm_s
387 FULL_BIN tfm_full
388 SIGN_BIN tfm_sign
Tamas Banbba85642019-06-06 09:31:59 +0100389 VENEER_NAME s_veneers)
Tamas Bandb69d522018-03-01 10:04:41 +0000390
391 #Link to secondary memory region(add extra linker flag)
Oliver Swede21440442018-07-10 09:31:32 +0100392 set_up_app_build(NS_TARGET ${PROJECT_NAME}
Tamas Bandb69d522018-03-01 10:04:41 +0000393 LINK_DEFINES "LINK_TO_SECONDARY_PARTITION"
394 S_TARGET tfm_s
395 FULL_BIN tfm_full
396 SIGN_BIN tfm_sign
397 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100398 POSTFIX "_1")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000399else()
Tamas Bandb69d522018-03-01 10:04:41 +0000400 #Link to primary memory region only
Oliver Swede21440442018-07-10 09:31:32 +0100401 set_up_app_build(NS_TARGET ${PROJECT_NAME}
Tamas Bandb69d522018-03-01 10:04:41 +0000402 S_TARGET tfm_s
403 FULL_BIN tfm_full
404 SIGN_BIN tfm_sign
405 VENEER_NAME s_veneers)
406endif()
407
408#If the tfm_non_secure_tests target is not available
409if(NOT TARGET tfm_non_secure_tests)
410 #Add the test source to the build.
411 #As of today since secure_fw is built as a sub-project this code will never execute.
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000412 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
413 include(../test/CMakeLists.inc)
Tamas Bandb69d522018-03-01 10:04:41 +0000414 target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000415endif()
416
Tamas Bandb69d522018-03-01 10:04:41 +0000417#Finally let CMake system apply changes after the whole project is defined.
418if (TARGET ${PROJECT_NAME})
419 embedded_project_end(${PROJECT_NAME})
420endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000421
Tamas Bandb69d522018-03-01 10:04:41 +0000422if (TARGET ${PROJECT_NAME}_1)
423 embedded_project_end(${PROJECT_NAME}_1)
424endif()
425
426embedded_project_end(${PROJECT_OBJ_LIB})