blob: 6a608a89516875eee4abd01bf3ddafae5469237e [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Jamie Foxb93da8b2018-12-13 18:27:30 +00002# Copyright (c) 2017-2019, 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_s LANGUAGES ASM C)
19embedded_project_fixup()
20
Tamas Bandb69d522018-03-01 10:04:41 +000021set(SECURE_FW_DIR "${CMAKE_CURRENT_LIST_DIR}")
22set(TFM_ROOT_DIR "${SECURE_FW_DIR}/..")
23set(TEST_DIR "${TFM_ROOT_DIR}/test")
24set(INTERFACE_DIR "${TFM_ROOT_DIR}/interface")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000025
Tamas Ban3109b302018-08-15 14:51:58 +010026if (NOT DEFINED TFM_LVL)
27 message(FATAL_ERROR "Incomplete build configuration: TFM_LVL is undefined. ")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000028endif()
29
30include(${SECURE_FW_DIR}/spm/CMakeLists.inc)
31include(${SECURE_FW_DIR}/core/CMakeLists.inc)
32include(${SECURE_FW_DIR}/ns_callable/CMakeLists.inc)
33
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000034set(BUILD_CMSIS_CORE On)
35set(BUILD_RETARGET On)
36set(BUILD_NATIVE_DRIVERS On)
37set(BUILD_STARTUP On)
38set(BUILD_TARGET_CFG On)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010039# FIXME: The following TARGET flags are platform dependent.
40# It is required to add a mechanism to expose the
41# target capabilities and, based on them, set the
42# flags properly.
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000043set(BUILD_TARGET_HARDWARE_KEYS On)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010044set(BUILD_TARGET_NV_COUNTERS On)
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000045set(BUILD_CMSIS_DRIVERS On)
46set(BUILD_TIME Off)
47set(BUILD_UART_STDOUT On)
Marc Moreno Berengue792fc682018-02-20 11:53:30 +000048set(BUILD_FLASH On)
Tamas Ban3681ce02018-11-22 15:19:24 +000049set(BUILD_BOOT_SEED On)
Tamas Ban38e17312018-11-22 15:26:35 +000050set(BUILD_DEVICE_ID On)
Marc Moreno Berenguea1f296f2018-01-25 15:21:22 +000051if(NOT DEFINED PLATFORM_CMAKE_FILE)
52 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
53elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
54 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
55else()
56 include(${PLATFORM_CMAKE_FILE})
57endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000058
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010059if(NOT DEFINED S_SCATTER_FILE_NAME)
60 message(FATAL_ERROR "ERROR: Incomplete Configuration: S_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
61endif()
Gabor Kerteszd7d7d742018-07-04 11:50:05 +020062embedded_set_target_linker_file(TARGET ${PROJECT_NAME} PATH "${S_SCATTER_FILE_NAME}")
63
Gyorgy Szing30fa9872017-12-05 01:08:47 +000064embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
Tamas Bandb69d522018-03-01 10:04:41 +000065#Create an object library to avoid compiling all source files twice, when two executables
66#with different memory map need to be linked(BL2 non-swapping)
67set(PROJECT_OBJ_LIB ${PROJECT_NAME}_obj_lib)
68add_library(${PROJECT_OBJ_LIB} OBJECT ${ALL_SRC_C} ${ALL_SRC_C_S} ${ALL_SRC_ASM_S})
Gyorgy Szing30fa9872017-12-05 01:08:47 +000069
Tamas Bandb69d522018-03-01 10:04:41 +000070#Set common compiler flags
71config_setting_shared_compiler_flags(${PROJECT_OBJ_LIB})
72
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010073if(NOT DEFINED TARGET_NV_COUNTERS_ENABLE)
74 set(TARGET_NV_COUNTERS_ENABLE OFF)
75endif()
76
77if(TARGET_NV_COUNTERS_ENABLE)
78 embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES TFM_NVCOUNTERS_ENABLE APPEND)
79endif()
80
Miklos Balint16a9ffb2018-11-19 11:35:49 +010081if (NOT DEFINED CORE_TEST)
82 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined.")
83elseif(CORE_TEST)
Tamas Bandb69d522018-03-01 10:04:41 +000084 embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES TFM_CORE_DEBUG TFM_PARTITION_TEST_CORE APPEND)
85endif()
86
Miklos Balint16a9ffb2018-11-19 11:35:49 +010087if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
88 message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
89elseif (TFM_NS_CLIENT_IDENTIFICATION)
90 target_compile_definitions(${PROJECT_OBJ_LIB} PRIVATE TFM_NS_CLIENT_IDENTIFICATION)
91endif()
92
Tamas Bandb69d522018-03-01 10:04:41 +000093#Set include directories
94embedded_target_include_directories(TARGET ${PROJECT_OBJ_LIB} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
95
96# For the non-swapping BL2 configuration two executables need to be built.
97# One can be executed from flash partition slot_0 and other from slot_1.
98# Only the linking phase is different. This function captures common settings
99# and eliminates copy-paste.
100function(set_up_secure_fw_build)
101 set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE)
102 set( _ONE_VALUE_ARGS S_TARGET VENEER_NAME POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
103 set( _MULTI_VALUE_ARGS LINK_DEFINES) #List arguments (e.g. LANGUAGES C ASM CXX)
104 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
105
106 if (NOT DEFINED _MY_PARAMS_S_TARGET)
107 message(FATAL_ERROR "set_up_secure_fw_build(): mandatory parameter 'S_TARGET' missing.")
108 endif()
109
110 if (NOT DEFINED _MY_PARAMS_VENEER_NAME)
111 message(FATAL_ERROR "set_up_secure_fw_build(): mandatory parameter 'VENEER_NAME' missing.")
112 endif()
113
114 set(EXE_NAME ${_MY_PARAMS_S_TARGET}${_MY_PARAMS_POSTFIX})
115 set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
116
117 #Create linker target: add object library to executable
118 add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
119
120 #Set common linker flags
121 config_setting_shared_linker_flags(${EXE_NAME})
122
123 #Indicates to secure target(s) already created
124 set(TARGET_TFM_S_EXISTED True PARENT_SCOPE)
125
126 #Set individual linker flags per linker target/executable
127 foreach(flag ${_MY_PARAMS_LINK_DEFINES})
128 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "${flag}")
129 endforeach(flag)
130
Antonio de Angelis8908f472018-08-31 15:44:25 +0100131
Tamas Bandb69d522018-03-01 10:04:41 +0000132 embedded_set_target_linker_file(TARGET ${EXE_NAME} PATH "${S_SCATTER_FILE_NAME}")
133
Antonio de Angelis8908f472018-08-31 15:44:25 +0100134 add_dependencies(${EXE_NAME} tfm_crypto)
Tamas Bandb69d522018-03-01 10:04:41 +0000135 add_dependencies(${EXE_NAME} tfm_storage)
136 add_dependencies(${EXE_NAME} tfm_audit)
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100137 add_dependencies(${EXE_NAME} tfm_platform)
Tamas Bandb69d522018-03-01 10:04:41 +0000138 add_dependencies(${EXE_NAME} tfm_secure_tests)
Tamas Ban48a0eb52018-08-17 12:48:05 +0100139 add_dependencies(${EXE_NAME} tfm_attest)
Tamas Bandb69d522018-03-01 10:04:41 +0000140
141 #Set macro definitions for the project.
142 embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES __thumb2__ __ARM_FEATURE_CMSE=3 TFM_LVL=${TFM_LVL} DAUTH_CHIP_DEFAULT APPEND)
143
144 if (REGRESSION OR CORE_TEST)
Jamie Foxb93da8b2018-12-13 18:27:30 +0000145 if (DEFINED TFM_PARTITION_TEST_SECURE_SERVICES AND TFM_PARTITION_TEST_SECURE_SERVICES)
Mate Toth-Pal8d7f12b2018-06-18 17:40:09 +0200146 #The test service veneers in the tfm_secure_tests library may not be
147 #referenced in the secure binary so the veneer objects are explicitly loaded
148 #from the secure tests library. However by generating the veneer files from
149 #the manifests, all the iovec interfaced veneers are in a single file in the
150 #secure_fw directory. The core test partitions use the veneers with the
Jamie Foxb93da8b2018-12-13 18:27:30 +0000151 #iovec API, so we only need the explicit load in case the secure client test
152 #partition is present.
153 #FIXME Remove the explicit load and the above comment once the secure client
154 #test partition uses the generated veneers.
Mate Toth-Pal8d7f12b2018-06-18 17:40:09 +0200155 if(${COMPILER} STREQUAL "ARMCLANG")
Tamas Ban85c1c912019-02-14 13:25:51 +0000156 target_link_libraries(${EXE_NAME} tfm_attest tfm_secure_tests tfm_attest tfm_crypto tfm_storage tfm_audit tfm_platform $<TARGET_LINKER_FILE:tfm_secure_tests>\(*veneers.o\) tfm_attest)
Mate Toth-Pal8d7f12b2018-06-18 17:40:09 +0200157 elseif(${COMPILER} STREQUAL "GNUARM")
Tamas Ban85c1c912019-02-14 13:25:51 +0000158 target_link_libraries(${EXE_NAME} tfm_attest tfm_secure_tests tfm_attest tfm_crypto tfm_storage tfm_audit tfm_platform tfm_attest)
Mate Toth-Pal8d7f12b2018-06-18 17:40:09 +0200159 else()
160 message(FATAL_ERROR "unknown compiler" )
161 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000162 else()
Tamas Ban85c1c912019-02-14 13:25:51 +0000163 target_link_libraries(${EXE_NAME} tfm_attest tfm_crypto tfm_storage tfm_audit tfm_platform tfm_secure_tests tfm_attest)
Tamas Bandb69d522018-03-01 10:04:41 +0000164 endif()
165 else()
Tamas Ban85c1c912019-02-14 13:25:51 +0000166 target_link_libraries(${EXE_NAME} tfm_attest tfm_crypto tfm_storage tfm_audit tfm_platform tfm_attest)
Tamas Bandb69d522018-03-01 10:04:41 +0000167 endif()
168
Antonio de Angelis8908f472018-08-31 15:44:25 +0100169
Tamas Bandb69d522018-03-01 10:04:41 +0000170 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_LVL=${TFM_LVL}")
171
172 if (NOT DEFINED TFM_PARTITION_TEST_CORE)
173 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_CORE is undefined. ")
174 elseif (TFM_PARTITION_TEST_CORE)
175 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
176 endif()
177
Tamas Bandb69d522018-03-01 10:04:41 +0000178 if (NOT DEFINED TFM_PARTITION_TEST_SECURE_SERVICES)
179 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SECURE_SERVICES is undefined. ")
180 elseif (TFM_PARTITION_TEST_SECURE_SERVICES)
181 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
182 endif()
183
Marc Moreno Berenguecae2c532018-10-09 12:58:46 +0100184 if (NOT DEFINED TEST_FRAMEWORK_S)
185 message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.")
186 elseif (TEST_FRAMEWORK_S)
187 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S")
188 endif()
189
190 if (NOT DEFINED TEST_FRAMEWORK_NS)
191 message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.")
192 elseif (TEST_FRAMEWORK_NS)
193 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS")
194 endif()
195
Tamas Bandb69d522018-03-01 10:04:41 +0000196 if (NOT DEFINED BL2)
197 message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
198 elseif (BL2)
199 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2")
200 endif()
201
202 if(CORE_TEST)
203 set(SECURE_AXF_DIR_PREFIX "${CMAKE_BINARY_DIR}/unit_test/")
204 set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${SECURE_AXF_DIR_PREFIX})
205 embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_CORE")
206 endif()
207
208 if(NOT DEFINED PLATFORM_LINK_INCLUDES)
209 message(FATAL_ERROR "ERROR: Incomplete Configuration: PLATFORM_LINK_INCLUDES is not defined.")
210 endif()
211 embedded_set_target_link_includes(TARGET ${EXE_NAME} INCLUDES "${PLATFORM_LINK_INCLUDES}")
212
213 #Generate binary file from executable
214 compiler_generate_binary_output(${EXE_NAME})
215
216 #Configure where we put the CMSE veneers generated by the compiler.
217 if (DEFINED S_VENEER_FILE_LOCATION)
218 set(S_VENEER_FILE "${S_VENEER_FILE_LOCATION}/${VENEER_NAME}")
219 else()
220 set(S_VENEER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${VENEER_NAME}")
221 endif()
222 compiler_set_cmse_output(${EXE_NAME} "${S_VENEER_FILE}")
223
224 #Configure what file shall be installed.
225 #Set install location. Keep original value to avoid overriding command line settings.
226 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
227 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install location for secure_fw." FORCE)
228 endif()
229
Mate Toth-Pal8d7f12b2018-06-18 17:40:09 +0200230 #Export files needed to interface external applications at: <build_dir>/install/export/tfm/
Tamas Bandb69d522018-03-01 10:04:41 +0000231 install(DIRECTORY ${TFM_ROOT_DIR}/interface/include/
Tamas Ban57bfa432018-04-13 16:05:49 +0100232 DESTINATION export/tfm/inc)
Tamas Bandb69d522018-03-01 10:04:41 +0000233
234 install(DIRECTORY ${TFM_ROOT_DIR}/interface/src/
Tamas Ban57bfa432018-04-13 16:05:49 +0100235 DESTINATION export/tfm/src)
Tamas Bandb69d522018-03-01 10:04:41 +0000236
Tamas Ban57bfa432018-04-13 16:05:49 +0100237 install(FILES ${S_VENEER_FILE} DESTINATION export/tfm/veneers)
Tamas Bandb69d522018-03-01 10:04:41 +0000238
Tamas Ban57bfa432018-04-13 16:05:49 +0100239 #Collect executables to common location: <build_dir>/install/outputs/
Tamas Bandb69d522018-03-01 10:04:41 +0000240 if (DEFINED SECURE_AXF_DIR_PREFIX)
241 set(MY_BINARY_DIR ${SECURE_AXF_DIR_PREFIX})
242 else()
243 set(MY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
244 endif()
245
246 install(FILES ${MY_BINARY_DIR}/${EXE_NAME}.axf
247 ${MY_BINARY_DIR}/${EXE_NAME}.bin
248 DESTINATION outputs/${TARGET_PLATFORM}/)
249
250 install(FILES ${MY_BINARY_DIR}/${EXE_NAME}.axf
251 ${MY_BINARY_DIR}/${EXE_NAME}.bin
252 DESTINATION outputs/fvp/)
253endfunction()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000254
255#Adds the test directory
256add_subdirectory(${TFM_ROOT_DIR}/test ${CMAKE_BINARY_DIR}/test)
257
Antonio de Angelis8908f472018-08-31 15:44:25 +0100258#Add the crypto library target
259add_subdirectory(${SECURE_FW_DIR}/services/crypto)
260
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000261#Add the secure storage library target
262add_subdirectory(${SECURE_FW_DIR}/services/secure_storage)
Tamas Bandb69d522018-03-01 10:04:41 +0000263
Antonio de Angeliscc657b32018-02-05 15:56:47 +0000264#Add the audit logging library target
265add_subdirectory(${SECURE_FW_DIR}/services/audit_logging)
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000266
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +0100267#Add the platform service library target
268add_subdirectory(${SECURE_FW_DIR}/services/platform)
269
Tamas Ban48a0eb52018-08-17 12:48:05 +0100270#Add the initial attestation service library target
271add_subdirectory(${SECURE_FW_DIR}/services/initial_attestation)
272
Tamas Bandb69d522018-03-01 10:04:41 +0000273if (LINK_TO_BOTH_MEMORY_REGION)
274 #Link to primary memory region
275 set_up_secure_fw_build(S_TARGET ${PROJECT_NAME}
276 VENEER_NAME s_veneers
277 POSTFIX "_0")
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000278
Tamas Bandb69d522018-03-01 10:04:41 +0000279 #Link to secondary memory region(add extra linker flag)
280 set_up_secure_fw_build(S_TARGET ${PROJECT_NAME}
281 LINK_DEFINES "LINK_TO_SECONDARY_PARTITION"
282 VENEER_NAME s_veneers
283 POSTFIX "_1")
Jamie Fox5592db02017-12-18 16:48:29 +0000284else()
Tamas Bandb69d522018-03-01 10:04:41 +0000285 #Link to primary memory region only
286 set_up_secure_fw_build(S_TARGET ${PROJECT_NAME}
287 VENEER_NAME s_veneers)
Jamie Fox5592db02017-12-18 16:48:29 +0000288endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000289
Tamas Bandb69d522018-03-01 10:04:41 +0000290#Finally let CMake system apply changes after the whole project is defined.
291if (TARGET ${PROJECT_NAME})
292 embedded_project_end(${PROJECT_NAME})
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000293endif()
294
Tamas Bandb69d522018-03-01 10:04:41 +0000295if (TARGET ${PROJECT_NAME}_0)
296 embedded_project_end(${PROJECT_NAME}_0)
Jamie Fox5592db02017-12-18 16:48:29 +0000297endif()
298
Tamas Bandb69d522018-03-01 10:04:41 +0000299if (TARGET ${PROJECT_NAME}_1)
300 embedded_project_end(${PROJECT_NAME}_1)
Ben Davis6d7256b2018-04-18 14:16:53 +0100301endif()
302
Tamas Bandb69d522018-03-01 10:04:41 +0000303embedded_project_end(${PROJECT_OBJ_LIB})