blob: 822dbbfdcd1176b89ee1351b85da27ca2b7d4745 [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"
48 "${INTERFACE_DIR}/src/tfm_sst_svc_handler.c"
Antonio de Angeliscc657b32018-02-05 15:56:47 +000049 "${INTERFACE_DIR}/src/tfm_log_api.c"
50 "${INTERFACE_DIR}/src/tfm_log_svc_handler.c"
Gyorgy Szing30fa9872017-12-05 01:08:47 +000051 "${INTERFACE_DIR}/src/tfm_id_mngr_dummy.c"
52 "${INTERFACE_DIR}/src/tfm_ns_lock_rtx.c"
53 )
54
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000055set(BUILD_CMSIS_CORE On)
56set(BUILD_RETARGET On)
57set(BUILD_NATIVE_DRIVERS On)
58set(BUILD_TIME Off)
59set(BUILD_STARTUP On)
60set(BUILD_TARGET_CFG Off)
61set(BUILD_TARGET_HARDWARE_KEYS Off)
62set(BUILD_CMSIS_DRIVERS On)
63set(BUILD_UART_STDOUT Off)
64set(BUILD_FLASH Off)
65if(NOT DEFINED PLATFORM_CMAKE_FILE)
66 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
67elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
68 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
69else()
70 include(${PLATFORM_CMAKE_FILE})
71endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000072
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010073if(NOT DEFINED NS_SCATTER_FILE_NAME)
74 message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
75endif()
Gabor Kerteszd7d7d742018-07-04 11:50:05 +020076embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${NS_SCATTER_FILE_NAME}")
77
Tamas Bandb69d522018-03-01 10:04:41 +000078#Create an object library to avoid compiling all source files twice, when two executables
79#with different memory map need to be linked(BL2 non-swapping)
80set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib)
81add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
82
83#Set common compiler flags
84config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB})
85
86#Set macro definitions
87target_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 +010088
Gyorgy Szing30fa9872017-12-05 01:08:47 +000089#Set include directories.
Tamas Bandb69d522018-03-01 10:04:41 +000090embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TEST_INTERFACE_DIR}/include ABSOLUTE APPEND)
91embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
92embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
93embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE APPEND)
94embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE APPEND)
95embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE APPEND)
96embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE APPEND)
97embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config ABSOLUTE APPEND)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000098
99if (NOT DEFINED CORE_TEST)
100 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
101elseif(CORE_TEST)
Tamas Bandb69d522018-03-01 10:04:41 +0000102 target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE CORE_TEST)
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000103endif()
104
Tamas Bandb69d522018-03-01 10:04:41 +0000105# For the non-swapping BL2 configuration two executables need to be built.
106# One can be executed from flash partition slot_0 and other from slot_1.
107# Only the linking phase is different. This function captures common settings
108# and eliminates copy-paste.
109function(set_up_app_build)
110 set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE)
111 set( _ONE_VALUE_ARGS NS_TARGET S_TARGET FULL_BIN SIGN_BIN VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
112 set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX)
113 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000114
Tamas Bandb69d522018-03-01 10:04:41 +0000115 if (NOT DEFINED _MY_PARAMS_NS_TARGET)
116 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'NS_TARGET' missing.")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000117 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000118
119 if (NOT DEFINED _MY_PARAMS_S_TARGET)
120 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'S_TARGET' missing.")
121 endif()
122
123 if (NOT DEFINED _MY_PARAMS_FULL_BIN)
124 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'FULL_BIN' missing.")
125 endif()
126
127 if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
128 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'SIGN_BIN' missing.")
129 endif()
130
131 if (NOT DEFINED _MY_PARAMS_VENEER_NAME)
132 message(FATAL_ERROR "set_up_app_build(): mandatory parameter 'VENEER_NAME' missing.")
133 endif()
134
135 set(EXE_NAME ${_MY_PARAMS_NS_TARGET}${_MY_PARAMS_POSTFIX})
136 set(S_BIN ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX})
137 set(FULL_NAME ${_MY_PARAMS_FULL_BIN}${_MY_PARAMS_POSTFIX})
138 set(SIGN_NAME ${_MY_PARAMS_SIGN_BIN}${_MY_PARAMS_POSTFIX})
139 set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
140
141 #Create linker target: add object library to executable
142 add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
143
144 #Set common linker flags
145 config_setting_shared_linker_flags(${EXE_NAME})
146
147 #Set individual linker flags per linker target/executable
148 foreach(flag ${_MY_PARAMS_LINK_DEFINES})
149 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}")
150 endforeach(flag)
151
152 embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${NS_SCATTER_FILE_NAME}")
153
154 #Add the RTX library
155 if(NOT DEFINED RTX_LIB_PATH)
156 message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
157 endif()
158 target_link_libraries(${EXE_NAME} "${RTX_LIB_PATH}")
159
160 if(NOT DEFINED PLATFORM_LINK_INCLUDES)
161 message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
162 endif()
163 embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
164
165 #Generate binary file from axf
166 compiler_generate_binary_output(${EXE_NAME})
167
168 #Generate MCUBoot compatible payload
169 if (BL2)
170 mcuboot_create_boot_payload(S_BIN ${S_BIN}
171 NS_BIN ${EXE_NAME}
172 FULL_BIN ${FULL_NAME}
173 SIGN_BIN ${SIGN_NAME}
174 POSTFIX ${_MY_PARAMS_POSTFIX})
175 endif()
176
177 if (NOT DEFINED TFM_PARTITION_TEST_CORE)
178 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
179 elseif (TFM_PARTITION_TEST_CORE)
180 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
181 endif()
182
183 if (NOT DEFINED TFM_PARTITION_TEST_SST)
184 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined. ")
185 elseif (TFM_PARTITION_TEST_SST)
186 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SST")
187 endif()
188
189 if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
190 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
191 elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
192 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
193 endif()
194
195 #Set BL2 specific settings.
196 if (BL2)
197 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2")
198 endif()
199
200 #We depend on the non secure tests. See if the library target is available.
201 if(TARGET tfm_non_secure_tests)
202 #If yes, then use the library.
203 target_link_libraries(${EXE_NAME} tfm_non_secure_tests)
204 #Ensure library is built first.
205 add_dependencies(${EXE_NAME} tfm_non_secure_tests)
206 endif()
207
208 #Ensure secure_fw is built before our executable.
209 add_dependencies(${EXE_NAME} ${S_BIN})
210
211 #Add the veneers to the executable.
212 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${VENEER_NAME}")
213 set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_LIBRARIES ${S_VENEER_FILE})
214
215 #Collect executables to common location: build/install/outputs/
216 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
217 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
218 DESTINATION outputs/${TARGET_PLATFORM}/)
219
220 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.axf
221 ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin
222 DESTINATION outputs/fvp/)
223endfunction()
224
225if (NOT TARGET_TFM_S_EXISTED)
226 set(S_VENEER_FILE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000227 add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
228endif()
229
Tamas Bandb69d522018-03-01 10:04:41 +0000230if (LINK_TO_BOTH_MEMORY_REGION)
231 #Link to primary memory region
232 set_up_app_build(NS_TARGET ${PROJECT_NAME}
233 S_TARGET tfm_s
234 FULL_BIN tfm_full
235 SIGN_BIN tfm_sign
236 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100237 POSTFIX "_0")
Tamas Bandb69d522018-03-01 10:04:41 +0000238
239 #Link to secondary memory region(add extra linker flag)
240 set_up_app_build(NS_TARGET ${PROJECT_NAME}
241 LINK_DEFINES "LINK_TO_SECONDARY_PARTITION"
242 S_TARGET tfm_s
243 FULL_BIN tfm_full
244 SIGN_BIN tfm_sign
245 VENEER_NAME s_veneers
Tamas Ban57bfa432018-04-13 16:05:49 +0100246 POSTFIX "_1")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000247else()
Tamas Bandb69d522018-03-01 10:04:41 +0000248 #Link to primary memory region only
249 set_up_app_build(NS_TARGET ${PROJECT_NAME}
250 S_TARGET tfm_s
251 FULL_BIN tfm_full
252 SIGN_BIN tfm_sign
253 VENEER_NAME s_veneers)
254endif()
255
256#If the tfm_non_secure_tests target is not available
257if(NOT TARGET tfm_non_secure_tests)
258 #Add the test source to the build.
259 #As of today since secure_fw is built as a sub-project this code will never execute.
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000260 option(ENABLE_INVERT_SERVICE_TESTS "" TRUE)
261 option(ENABLE_SECURE_STORAGE_SERVICE_TESTS "" TRUE)
262 include(../test/CMakeLists.inc)
Tamas Bandb69d522018-03-01 10:04:41 +0000263 target_sources(${PROJECT_OBJ_LIB} PUBLIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000264endif()
265
Tamas Bandb69d522018-03-01 10:04:41 +0000266#Finally let CMake system apply changes after the whole project is defined.
267if (TARGET ${PROJECT_NAME})
268 embedded_project_end(${PROJECT_NAME})
269endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000270
Tamas Bandb69d522018-03-01 10:04:41 +0000271if (TARGET ${PROJECT_NAME}_0)
272 embedded_project_end(${PROJECT_NAME}_0)
273endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000274
Tamas Bandb69d522018-03-01 10:04:41 +0000275if (TARGET ${PROJECT_NAME}_1)
276 embedded_project_end(${PROJECT_NAME}_1)
277endif()
278
279embedded_project_end(${PROJECT_OBJ_LIB})