blob: 285c0dffe3cc96434f60ed1b222c3c1541faf313 [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Mate Toth-Pal74684d92018-01-17 19:15:47 +01002# Copyright (c) 2017-2018, 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
10#Tell cmake where our modules can be found
11list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
12
13#Include common stuff to control cmake.
14include("Common/BuildSys")
15
16#Start an embedded project.
17embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../ConfigDefault.cmake")
18project(tfm_ns LANGUAGES ASM C)
19embedded_project_fixup()
20
21set(APP_DIR ${CMAKE_CURRENT_LIST_DIR})
22get_filename_component(TFM_ROOT_DIR ${APP_DIR}/.. ABSOLUTE)
23set(INTERFACE_DIR ${TFM_ROOT_DIR}/interface)
Antonio de Angelis8ad3d3812018-04-13 16:48:00 +010024set(TEST_INTERFACE_DIR ${TFM_ROOT_DIR}/test/interface)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000025
Tamas Bandb69d522018-03-01 10:04:41 +000026#Include BL2 bootloader related functions
27set(MCUBOOT_DIR "${TFM_ROOT_DIR}/bl2/ext/mcuboot")
28include("${MCUBOOT_DIR}/MCUBoot.cmake")
29
Gyorgy Szing30fa9872017-12-05 01:08:47 +000030#Set variables
31get_filename_component(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5 ABSOLUTE)
32
33if(NOT EXISTS ${CMSIS_5_DIR})
34 message(FATAL_ERROR "Missing CMSIS_5. Please clone the CMSIS_5 repo to directory \"${CMSIS_5_DIR}\".")
35endif()
36
Tamas Bandb69d522018-03-01 10:04:41 +000037if (NOT DEFINED BL2)
38 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
39endif ()
40
Gyorgy Szing30fa9872017-12-05 01:08:47 +000041set(NS_APP_SRC "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config/RTX_Config.c"
42 "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Source/rtx_lib.c"
43 "${APP_DIR}/main_ns.c"
44 "${APP_DIR}/ext/tz_context.c"
45 "${APP_DIR}/tfm_integ_test.c"
46 "${APP_DIR}/os_wrapper_rtx.c"
47 "${INTERFACE_DIR}/src/tfm_sst_api.c"
Antonio de Angelis2eeac642018-08-21 14:23:22 +010048 "${INTERFACE_DIR}/src/tfm_audit_api.c"
Gyorgy Szing30fa9872017-12-05 01:08:47 +000049 "${INTERFACE_DIR}/src/tfm_id_mngr_dummy.c"
50 "${INTERFACE_DIR}/src/tfm_ns_lock_rtx.c"
51 )
52
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000053set(BUILD_CMSIS_CORE On)
54set(BUILD_RETARGET On)
55set(BUILD_NATIVE_DRIVERS On)
56set(BUILD_TIME Off)
57set(BUILD_STARTUP On)
58set(BUILD_TARGET_CFG Off)
59set(BUILD_TARGET_HARDWARE_KEYS Off)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010060set(BUILD_TARGET_NV_COUNTERS Off)
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000061set(BUILD_CMSIS_DRIVERS On)
62set(BUILD_UART_STDOUT Off)
63set(BUILD_FLASH Off)
64if(NOT DEFINED PLATFORM_CMAKE_FILE)
65 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
66elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
67 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
68else()
69 include(${PLATFORM_CMAKE_FILE})
70endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000071
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010072if(NOT DEFINED NS_SCATTER_FILE_NAME)
73 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
74endif()
Gabor Kerteszd7d7d742018-07-04 11:50:05 +020075embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}")
76
Tamas Bandb69d522018-03-01 10:04:41 +000077#Create an object library to avoid compiling all source files twice, when two executables
78#with different memory map need to be linked(BL2 non-swapping)
79set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib)
80add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
81
82#Set common compiler flags
83config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB})
84
85#Set macro definitions
86target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010087
Gyorgy Szing30fa9872017-12-05 01:08:47 +000088#Set include directories.
Tamas Bandb69d522018-03-01 10:04:41 +000089embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
90embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
91embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
92embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
93embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
94embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
95embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
96embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000097
98if (NOT DEFINED CORE_TEST)
99 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
100elseif(CORE_TEST)
Tamas Bandb69d522018-03-01 10:04:41 +0000101 target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE CORE_TEST)
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000102endif()
103
Tamas Bandb69d522018-03-01 10:04:41 +0000104# For the non-swapping BL2 configuration two executables need to be built.
105# One can be executed from flash partition slot_0 and other from slot_1.
106# Only the linking phase is different. This function captures common settings
107# and eliminates copy-paste.
108function(set_up_app_build)
109 set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE)
110 set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
111 set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX)
112 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000113
Tamas Bandb69d522018-03-01 10:04:41 +0000114 if (NOT DEFINED _MY_PARAMS_NS_TARGET)
115 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000116 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000117
118 if (NOT DEFINED _MY_PARAMS_S_TARGET)
119 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.")
120 endif()
121
122 if (NOT DEFINED _MY_PARAMS_FULL_BIN)
123 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.")
124 endif()
125
126 if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
127 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.")
128 endif()
129
130 if (NOT DEFINED _MY_PARAMS_VENEER_NAME)
131 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.")
132 endif()
133
134 set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX})
135 set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX})
136 set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX})
137 set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX})
138 set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
139
140 #Create linker target: add object library to executable
141 add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
142
143 #Set common linker flags
144 config_setting_shared_linker_flags(${EXE_NAME})
145
146 #Set individual linker flags per linker target/executable
147 foreach(flag ${_MY_PARAMS_LINK_DEFINES})
148 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}")
149 endforeach(flag)
150
151 embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}")
152
153 #Add the RTX library
154 if(NOT DEFINED RTX_LIB_PATH)
155 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
156 endif()
157 target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}")
158
159 if(NOT DEFINED PLATFORM_LINK_INCLUDES)
160 message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
161 endif()
162 embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
163
164 #Generate binary file from axf
165 compiler_generate_binary_output(${EXE_NAME})
166
167 #Generate MCUBoot compatible payload
168 if (BL2)
169 mcuboot_create_boot_payload(S_BIN ${S_BIN}
170 NS_BIN ${EXE_NAME}
171 FULL_BIN ${FULL_NAME}
172 SIGN_BIN ${SIGN_NAME}
173 POSTFIX ${_MY_PARAMS_POSTFIX})
174 endif()
175
176 if (NOT DEFINED TFM_PARTITION_TEST_CORE)
177 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
178 elseif (TFM_PARTITION_TEST_CORE)
179 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
180 endif()
181
182 if (NOT DEFINED TFM_PARTITION_TEST_SST)
183 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
184 elseif (TFM_PARTITION_TEST_SST)
185 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SST")
186 endif()
187
188 if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
189 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
190 elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
191 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
192 endif()
193
194 #Set BL2 specific settings.
195 if (BL2)
196 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2")
197 endif()
198
199 #We depend on the non secure tests. See if the library target is available.
200 if(TARGET tfm_non_secure_tests)
201 #If yes, then use the library.
202 target_link_libraries(${EXE_NAME} tfm_non_secure_tests)
203 #Ensure library is built first.
204 add_dependencies(${EXE_NAME} tfm_non_secure_tests)
205 endif()
206
207 #Ensure secure_fw is built before our executable.
208 add_dependencies(${EXE_NAME} ${S_BIN})
209
210 #Add the veneers to the executable.
211 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${VENEER_NAME}")
212 set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
213
214 #Collect executables to common location: build/install/outputs/
215 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
216 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
217 DESTINATION outputs/${TARGET_PLATFORM}/)
218
219 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
220 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
221 DESTINATION outputs/fvp/)
222endfunction()
223
224if (NOT TARGET_TFM_S_EXISTED)
225 set(S_VENEER_FILE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000226 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
227endif()
228
Tamas Bandb69d522018-03-01 10:04:41 +0000229if (LINK_TO_BOTH_MEMORY_REGION)
230 #Link to primary memory region
231 set_up_app_build(NS_TARGET ${PROJECT_NAME}
232 S_TARGET tfm_s
233 FULL_BIN tfm_full
234 SIGN_BIN tfm_sign
235 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100236 POSTFIX "_0")
Tamas Bandb69d522018-03-01 10:04:41 +0000237
238 #Link to secondary memory region(add extra linker flag)
Oliver Swede21440442018-07-10 09:31:32 +0100239 set_up_app_build(NS_TARGET ${PROJECT_NAME}
Tamas Bandb69d522018-03-01 10:04:41 +0000240 LINK_DEFINES "LINK_TO_SECONDARY_PARTITION"
241 S_TARGET tfm_s
242 FULL_BIN tfm_full
243 SIGN_BIN tfm_sign
244 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100245 POSTFIX "_1")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000246else()
Tamas Bandb69d522018-03-01 10:04:41 +0000247 #Link to primary memory region only
Oliver Swede21440442018-07-10 09:31:32 +0100248 set_up_app_build(NS_TARGET ${PROJECT_NAME}
Tamas Bandb69d522018-03-01 10:04:41 +0000249 S_TARGET tfm_s
250 FULL_BIN tfm_full
251 SIGN_BIN tfm_sign
252 VENEER_NAME s_veneers)
253endif()
254
255#If the tfm_non_secure_tests target is not available
256if(NOT TARGET tfm_non_secure_tests)
257 #Add the test source to the build.
258 #As of today since secure_fw is built as a sub-project this code will never execute.
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000259 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
260 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
261 include(../test/CMakeLists.inc)
Tamas Bandb69d522018-03-01 10:04:41 +0000262 target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000263endif()
264
Tamas Bandb69d522018-03-01 10:04:41 +0000265#Finally let CMake system apply changes after the whole project is defined.
266if (TARGET ${PROJECT_NAME})
267 embedded_project_end(${PROJECT_NAME})
268endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000269
Tamas Bandb69d522018-03-01 10:04:41 +0000270if (TARGET ${PROJECT_NAME}_0)
271 embedded_project_end(${PROJECT_NAME}_0)
272endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000273
Tamas Bandb69d522018-03-01 10:04:41 +0000274if (TARGET ${PROJECT_NAME}_1)
275 embedded_project_end(${PROJECT_NAME}_1)
276endif()
277
278embedded_project_end(${PROJECT_OBJ_LIB})