blob: 14ea7bbf16602164cbc1801a34f3cfc8b735124a [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 Angeliscc657b32018-02-05 15:56:47 +000048 "${INTERFACE_DIR}/src/tfm_log_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)
60set(BUILD_CMSIS_DRIVERS On)
61set(BUILD_UART_STDOUT Off)
62set(BUILD_FLASH Off)
63if(NOT DEFINED PLATFORM_CMAKE_FILE)
64 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
65elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
66 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
67else()
68 include(${PLATFORM_CMAKE_FILE})
69endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000070
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010071if(NOT DEFINED NS_SCATTER_FILE_NAME)
72 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
73endif()
Gabor Kerteszd7d7d742018-07-04 11:50:05 +020074embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}")
75
Tamas Bandb69d522018-03-01 10:04:41 +000076#Create an object library to avoid compiling all source files twice, when two executables
77#with different memory map need to be linked(BL2 non-swapping)
78set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib)
79add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
80
81#Set common compiler flags
82config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB})
83
84#Set macro definitions
85target_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 +010086
Gyorgy Szing30fa9872017-12-05 01:08:47 +000087#Set include directories.
Tamas Bandb69d522018-03-01 10:04:41 +000088embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
89embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
90embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
91embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
92embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
93embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
94embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
95embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000096
97if (NOT DEFINED CORE_TEST)
98 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
99elseif(CORE_TEST)
Tamas Bandb69d522018-03-01 10:04:41 +0000100 target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE CORE_TEST)
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000101endif()
102
Tamas Bandb69d522018-03-01 10:04:41 +0000103# For the non-swapping BL2 configuration two executables need to be built.
104# One can be executed from flash partition slot_0 and other from slot_1.
105# Only the linking phase is different. This function captures common settings
106# and eliminates copy-paste.
107function(set_up_app_build)
108 set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE)
109 set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
110 set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX)
111 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000112
Tamas Bandb69d522018-03-01 10:04:41 +0000113 if (NOT DEFINED _MY_PARAMS_NS_TARGET)
114 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000115 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000116
117 if (NOT DEFINED _MY_PARAMS_S_TARGET)
118 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.")
119 endif()
120
121 if (NOT DEFINED _MY_PARAMS_FULL_BIN)
122 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.")
123 endif()
124
125 if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
126 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.")
127 endif()
128
129 if (NOT DEFINED _MY_PARAMS_VENEER_NAME)
130 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.")
131 endif()
132
133 set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX})
134 set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX})
135 set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX})
136 set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX})
137 set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
138
139 #Create linker target: add object library to executable
140 add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
141
142 #Set common linker flags
143 config_setting_shared_linker_flags(${EXE_NAME})
144
145 #Set individual linker flags per linker target/executable
146 foreach(flag ${_MY_PARAMS_LINK_DEFINES})
147 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}")
148 endforeach(flag)
149
150 embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}")
151
152 #Add the RTX library
153 if(NOT DEFINED RTX_LIB_PATH)
154 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
155 endif()
156 target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}")
157
158 if(NOT DEFINED PLATFORM_LINK_INCLUDES)
159 message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
160 endif()
161 embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
162
163 #Generate binary file from axf
164 compiler_generate_binary_output(${EXE_NAME})
165
166 #Generate MCUBoot compatible payload
167 if (BL2)
168 mcuboot_create_boot_payload(S_BIN ${S_BIN}
169 NS_BIN ${EXE_NAME}
170 FULL_BIN ${FULL_NAME}
171 SIGN_BIN ${SIGN_NAME}
172 POSTFIX ${_MY_PARAMS_POSTFIX})
173 endif()
174
175 if (NOT DEFINED TFM_PARTITION_TEST_CORE)
176 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
177 elseif (TFM_PARTITION_TEST_CORE)
178 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
179 endif()
180
181 if (NOT DEFINED TFM_PARTITION_TEST_SST)
182 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
183 elseif (TFM_PARTITION_TEST_SST)
184 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SST")
185 endif()
186
187 if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
188 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
189 elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
190 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
191 endif()
192
193 #Set BL2 specific settings.
194 if (BL2)
195 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2")
196 endif()
197
198 #We depend on the non secure tests. See if the library target is available.
199 if(TARGET tfm_non_secure_tests)
200 #If yes, then use the library.
201 target_link_libraries(${EXE_NAME} tfm_non_secure_tests)
202 #Ensure library is built first.
203 add_dependencies(${EXE_NAME} tfm_non_secure_tests)
204 endif()
205
206 #Ensure secure_fw is built before our executable.
207 add_dependencies(${EXE_NAME} ${S_BIN})
208
209 #Add the veneers to the executable.
210 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${VENEER_NAME}")
211 set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
212
213 #Collect executables to common location: build/install/outputs/
214 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
215 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
216 DESTINATION outputs/${TARGET_PLATFORM}/)
217
218 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
219 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
220 DESTINATION outputs/fvp/)
221endfunction()
222
223if (NOT TARGET_TFM_S_EXISTED)
224 set(S_VENEER_FILE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000225 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
226endif()
227
Tamas Bandb69d522018-03-01 10:04:41 +0000228if (LINK_TO_BOTH_MEMORY_REGION)
229 #Link to primary memory region
230 set_up_app_build(NS_TARGET ${PROJECT_NAME}
231 S_TARGET tfm_s
232 FULL_BIN tfm_full
233 SIGN_BIN tfm_sign
234 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100235 POSTFIX "_0")
Tamas Bandb69d522018-03-01 10:04:41 +0000236
237 #Link to secondary memory region(add extra linker flag)
238 set_up_app_build(NS_TARGET ${PROJECT_NAME}
239 LINK_DEFINES "LINK_TO_SECONDARY_PARTITION"
240 S_TARGET tfm_s
241 FULL_BIN tfm_full
242 SIGN_BIN tfm_sign
243 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100244 POSTFIX "_1")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000245else()
Tamas Bandb69d522018-03-01 10:04:41 +0000246 #Link to primary memory region only
247 set_up_app_build(NS_TARGET ${PROJECT_NAME}
248 S_TARGET tfm_s
249 FULL_BIN tfm_full
250 SIGN_BIN tfm_sign
251 VENEER_NAME s_veneers)
252endif()
253
254#If the tfm_non_secure_tests target is not available
255if(NOT TARGET tfm_non_secure_tests)
256 #Add the test source to the build.
257 #As of today since secure_fw is built as a sub-project this code will never execute.
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000258 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
259 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
260 include(../test/CMakeLists.inc)
Tamas Bandb69d522018-03-01 10:04:41 +0000261 target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000262endif()
263
Tamas Bandb69d522018-03-01 10:04:41 +0000264#Finally let CMake system apply changes after the whole project is defined.
265if (TARGET ${PROJECT_NAME})
266 embedded_project_end(${PROJECT_NAME})
267endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000268
Tamas Bandb69d522018-03-01 10:04:41 +0000269if (TARGET ${PROJECT_NAME}_0)
270 embedded_project_end(${PROJECT_NAME}_0)
271endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000272
Tamas Bandb69d522018-03-01 10:04:41 +0000273if (TARGET ${PROJECT_NAME}_1)
274 embedded_project_end(${PROJECT_NAME}_1)
275endif()
276
277embedded_project_end(${PROJECT_OBJ_LIB})