blob: 679a0d38afab28de9ededaa6491e2ecb420dfc52 [file] [log] [blame]
Mate Toth-Pal65c935e2018-01-17 18:42:13 +01001#-------------------------------------------------------------------------------
Tamas Banabea89d2020-01-15 13:29:25 +00002# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Mate Toth-Pal65c935e2018-01-17 18:42:13 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8if(NOT DEFINED REGRESSION)
9 message(FATAL_ERROR "ERROR: Incomplete Configuration: REGRESSION not defined, Include this file from a Config*.cmake")
10elseif(NOT DEFINED CORE_TEST)
11 message(FATAL_ERROR "ERROR: Incomplete Configuration: CORE_TEST not defined, Include this file from a Config*.cmake")
Tamas Band90c81b2018-08-15 15:03:42 +010012elseif(NOT DEFINED TFM_LVL)
13 message(FATAL_ERROR "ERROR: Incomplete Configuration: TFM_LVL not defined, Include this file from a Config*.cmake")
David Huf2cfa122019-08-27 15:32:38 +080014elseif(NOT DEFINED CORE_IPC)
Tamas Banabea89d2020-01-15 13:29:25 +000015 message(FATAL_ERROR "ERROR: Incomplete Configuration: CORE_IPC not defined. Include this file from a Config*.cmake")
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010016endif()
17
Mate Toth-Palee551bc2018-06-12 16:40:45 +020018if(NOT DEFINED COMPILER)
19 message(FATAL_ERROR "ERROR: COMPILER is not set in command line")
TTornblom99f0be22019-12-17 16:22:38 +010020elseif((NOT ${COMPILER} STREQUAL "ARMCLANG") AND (NOT ${COMPILER} STREQUAL "GNUARM") AND (NOT ${COMPILER} STREQUAL "IARARM"))
Mate Toth-Palee551bc2018-06-12 16:40:45 +020021 message(FATAL_ERROR "ERROR: Compiler \"${COMPILER}\" is not supported.")
22endif()
23
Kevin Pengc5781482020-07-08 15:30:24 +080024set(TEST_DIR ${CMAKE_SOURCE_DIR}/test)
25
Tamas Bandd10fe52019-09-18 11:52:32 +010026#Configure the default build type
27set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (i.e. Debug)")
28
Raef Colesb321c0b2019-10-15 08:49:17 +010029#Ignore case on the cmake build types
30string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
31
Edison Aicb0ecf62019-07-10 18:43:51 +080032if(CORE_IPC)
33 if (TFM_LVL EQUAL 3)
34 message(FATAL_ERROR "ERROR: Invalid isolation level!")
35 endif()
36else()
37 if(NOT TFM_LVL EQUAL 1)
38 message(FATAL_ERROR "ERROR: Invalid isolation level!")
39 endif()
40endif()
41
David Vincze4638b2a2019-05-24 10:14:23 +020042#BL2 bootloader (MCUBoot) related settings
David Vincze54d05552019-08-05 12:58:47 +020043include(${CMAKE_CURRENT_LIST_DIR}/bl2/ext/mcuboot/MCUBootConfig.cmake)
David Vincze4638b2a2019-05-24 10:14:23 +020044
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010045set(BUILD_CMSIS_CORE Off)
46set(BUILD_RETARGET Off)
47set(BUILD_NATIVE_DRIVERS Off)
48set(BUILD_TIME Off)
49set(BUILD_STARTUP Off)
50set(BUILD_TARGET_CFG Off)
51set(BUILD_TARGET_HARDWARE_KEYS Off)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010052set(BUILD_TARGET_NV_COUNTERS Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010053set(BUILD_CMSIS_DRIVERS Off)
54set(BUILD_UART_STDOUT Off)
55set(BUILD_FLASH Off)
Mate Toth-Pald3c77662019-02-20 16:23:00 +010056set(BUILD_PLAT_TEST Off)
Tamas Band4bf3472019-09-06 12:59:56 +010057set(BUILD_BOOT_HAL Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010058if(NOT DEFINED PLATFORM_CMAKE_FILE)
59 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
60elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
61 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
62else()
63 include(${PLATFORM_CMAKE_FILE})
64endif()
65
David Hu857bfa52019-05-21 13:54:50 +080066# Select the corresponding CPU type and configuration according to current
67# building status in multi-core scenario.
68# The updated configuration will be used in following compiler setting.
69if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY)
David Hu104388f2019-11-18 14:37:32 +080070 if (NOT CORE_IPC)
71 message(FATAL_ERROR "CORE_IPC is OFF. Multi-core topology should work in IPC model.")
72 endif()
73
David Hu857bfa52019-05-21 13:54:50 +080074 include("Common/MultiCore")
75
76 if (NOT DEFINED TFM_BUILD_IN_SPE)
77 message(FATAL_ERROR "Flag of building in SPE is not specified. Please set TFM_BUILD_IN_SPE.")
78 else()
79 select_arm_cpu_type(${TFM_BUILD_IN_SPE})
80 endif()
David Hu857bfa52019-05-21 13:54:50 +080081
David Hufeae0f92019-06-17 13:42:20 +080082 # CMSE is unnecessary in multi-core scenarios.
83 # TODO: Need further discussion about if CMSE is required when an Armv8-M
84 # core acts as secure core in multi-core scenario.
Mate Toth-Pal8f17a712020-03-02 16:22:19 +010085 # leave CMSE_FLAGS undefined
David Hufeae0f92019-06-17 13:42:20 +080086else()
TTornblom99f0be22019-12-17 16:22:38 +010087 if(${COMPILER} STREQUAL "IARARM")
88 set (CMSE_FLAGS "--cmse")
89 else()
90 set (CMSE_FLAGS "-mcmse")
91 endif()
David Huaeaf2732019-10-10 14:32:53 +080092
93 # Clear multi-core test setting
94 set (TFM_MULTI_CORE_TEST OFF)
David Hufeae0f92019-06-17 13:42:20 +080095endif()
96
Mate Toth-Palee551bc2018-06-12 16:40:45 +020097if(${COMPILER} STREQUAL "ARMCLANG")
Mate Toth-Pal76867262018-03-09 13:15:36 +010098 #Use any ARMCLANG version found on PATH. Note: Only versions supported by the
99 #build system will work. A file cmake/Common/CompilerArmClangXY.cmake
100 #must be present with a matching version.
101 include("Common/FindArmClang")
102 include("Common/${ARMCLANG_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100103
Ken Liu8e7622b2020-04-16 17:05:56 +0800104 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -ffunction-sections -fdata-sections -fno-builtin -nostdlib)
Tamas Bandb69d522018-03-01 10:04:41 +0000105 ##Shared compiler settings.
106 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100107 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} -Wall -Werror)
Tamas Bandb69d522018-03-01 10:04:41 +0000108 endfunction()
109
110 ##Shared linker settings.
111 function(config_setting_shared_linker_flags tgt)
Antonio de Angelis3302f452019-07-19 10:36:33 +0100112 embedded_set_target_link_flags(TARGET ${tgt} FLAGS --strict --map --symbols --xref --entry=Reset_Handler --remove --info=summarysizes,sizes,totals,unused,veneers)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100113 endfunction()
114elseif(${COMPILER} STREQUAL "GNUARM")
115 #Use any GNUARM version found on PATH. Note: Only versions supported by the
116 #build system will work. A file cmake/Common/CompilerGNUARMXY.cmake
117 #must be present with a matching version.
118 include("Common/FindGNUARM")
119 include("Common/${GNUARM_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100120
Ken Liu8e7622b2020-04-16 17:05:56 +0800121 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -ffunction-sections -fdata-sections --specs=nano.specs -fno-builtin)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100122 ##Shared compiler and linker settings.
Tamas Bandb69d522018-03-01 10:04:41 +0000123 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100124 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} -Wall -Werror -Wno-format -Wno-return-type -Wno-unused-but-set-variable)
Tamas Bandb69d522018-03-01 10:04:41 +0000125 endfunction()
126
127 ##Shared linker settings.
128 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100129 #--no-wchar-size-warning flag is added because TF-M sources are compiled
130 #with short wchars, however the standard library is compiled with normal
131 #wchar, and this generates linker time warnings. TF-M code does not use
132 #wchar, so the warning can be suppressed.
Antonio de Angelis3302f452019-07-19 10:36:33 +0100133 embedded_set_target_link_flags(TARGET ${tgt} FLAGS -Wl,-check-sections,-fatal-warnings,--gc-sections,--no-wchar-size-warning,--print-memory-usage --entry=Reset_Handler --specs=nano.specs)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100134 endfunction()
TTornblom99f0be22019-12-17 16:22:38 +0100135elseif(${COMPILER} STREQUAL "IARARM")
136 #Use any IARARM version found on PATH. Note: Only versions supported by the
137 #build system will work. A file cmake/Common/CompilerIARARMXY.cmake
138 #must be present with a matching version.
139 include("Common/FindIARARM")
140 include("Common/${IARARM_MODULE}")
141
TTornblomae979882020-04-24 13:39:23 +0200142 set (COMMON_COMPILE_FLAGS -e --dlib_config=full --vla --silent -DNO_TYPEOF --diag_suppress Pe546,Pe940,Pa082,Pa084)
TTornblom99f0be22019-12-17 16:22:38 +0100143 ##Shared compiler and linker settings.
144 function(config_setting_shared_compiler_flags tgt)
TTornblomae979882020-04-24 13:39:23 +0200145 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS ${COMMON_COMPILE_FLAGS} "-DImage$$= " "-DLoad$$LR$$= " "-D$$ZI$$Base=$$Base" "-D$$ZI$$Limit=$$Limit" "-D$$RO$$Base=$$Base" "-D$$RO$$Limit=$$Limit" "-D$$RW$$Base=$$Base" "-D$$RW$$Limit=$$Limit" "-D_DATA$$RW$$Base=_DATA$$Base" "-D_DATA$$RW$$Limit=_DATA$$Limit" "-D_DATA$$ZI$$Base=_DATA$$Base" "-D_DATA$$ZI$$Limit=_DATA$$Limit" "-D_STACK$$ZI$$Base=_STACK$$Base" "-D_STACK$$ZI$$Limit=_STACK$$Limit" )
TTornblom99f0be22019-12-17 16:22:38 +0100146 endfunction()
147
148 ##Shared linker settings.
149 function(config_setting_shared_linker_flags tgt)
150 #--no-wchar-size-warning flag is added because TF-M sources are compiled
151 #with short wchars, however the standard library is compiled with normal
152 #wchar, and this generates linker time warnings. TF-M code does not use
153 #wchar, so the warning can be suppressed.
154 embedded_set_target_link_flags(TARGET ${tgt} FLAGS --silent --semihosting --redirect __write=__write_buffered)
155 endfunction()
Mate Toth-Pal76867262018-03-09 13:15:36 +0100156endif()
157
158#Create a string from the compile flags list, so that it can be used later
159#in this file to set mbedtls and BL2 flags
Tamas Bandb69d522018-03-01 10:04:41 +0000160list_to_string(COMMON_COMPILE_FLAGS_STR ${COMMON_COMPILE_FLAGS})
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100161
162#Settings which shall be set for all projects the same way based
163# on the variables above.
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100164set (TFM_PARTITION_TEST_CORE OFF)
Jamie Foxadf02552019-05-16 17:44:52 +0100165set (TFM_PARTITION_TEST_CORE_IPC OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100166set (CORE_TEST_POSITIVE OFF)
167set (CORE_TEST_INTERACTIVE OFF)
Ben Davis6d7256b2018-04-18 14:16:53 +0100168set (TFM_PARTITION_TEST_SECURE_SERVICES OFF)
Kevin Pengc6d74502020-03-04 16:55:37 +0800169set (TFM_PARTITION_TEST_PS OFF)
Tamas Band90c81b2018-08-15 15:03:42 +0100170set (SERVICES_TEST_ENABLED OFF)
Marc Moreno Berenguecae2c532018-10-09 12:58:46 +0100171set (TEST_FRAMEWORK_S OFF)
172set (TEST_FRAMEWORK_NS OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800173set (TFM_PSA_API OFF)
Miklos Balintf13ec022018-04-06 17:21:22 +0200174
David Hu60105382019-12-25 13:37:05 +0800175if (NOT DEFINED TFM_PARTITION_AUDIT_LOG)
176 # Enable the TF-M Audit Log partition
177 set(TFM_PARTITION_AUDIT_LOG ON)
178endif()
179if (NOT DEFINED TFM_PARTITION_PLATFORM)
180 # Enable the TF-M Platform partition
181 set(TFM_PARTITION_PLATFORM ON)
182endif()
Kevin Pengc6d74502020-03-04 16:55:37 +0800183if (NOT DEFINED TFM_PARTITION_PROTECTED_STORAGE)
184 # Enable the TF-M Protected storage partition
185 set(TFM_PARTITION_PROTECTED_STORAGE ON)
David Hu60105382019-12-25 13:37:05 +0800186endif()
187if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
188 # Enable the TF-M internal trusted storage partition
189 set(TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ON)
190endif()
191if (NOT DEFINED TFM_PARTITION_CRYPTO)
192 # Enable the TF-M crypto partition
193 set(TFM_PARTITION_CRYPTO ON)
194endif()
195if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION)
196 # Enable the TF-M initial attestation partition
197 set(TFM_PARTITION_INITIAL_ATTESTATION ON)
198endif()
Kevin Pengc73130f2019-10-22 17:27:18 +0800199
Edison Ai1dfd7b12020-02-23 14:16:08 +0800200if (NOT TFM_LVL EQUAL 1 AND NOT DEFINED CONFIG_TFM_ENABLE_MEMORY_PROTECT)
201 set (CONFIG_TFM_ENABLE_MEMORY_PROTECT ON)
202endif()
203
Kevin Pengc6d74502020-03-04 16:55:37 +0800204if (TFM_PARTITION_INITIAL_ATTESTATION OR TFM_PARTITION_PROTECTED_STORAGE)
Kevin Pengc73130f2019-10-22 17:27:18 +0800205 #PSA Initial Attestation and Protected storage rely on Cryptography API
206 set(TFM_PARTITION_CRYPTO ON)
207endif()
Jamie Foxc78c62c2019-05-23 13:42:17 +0100208
Kevin Pengc6d74502020-03-04 16:55:37 +0800209if (TFM_PARTITION_PROTECTED_STORAGE)
Kevin Peng0b5acd32020-03-03 15:17:58 +0800210 set(TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ON)
211endif()
212
Miklos Balint6cbeba62018-04-12 17:31:34 +0200213# Option to demonstrate usage of secure-only peripheral
214set (SECURE_UART1 OFF)
215
Alan DeMars61844692019-10-22 08:23:29 -0700216if (PLATFORM_SVC_HANDLERS)
217 add_definitions(-DPLATFORM_SVC_HANDLERS)
218endif()
219
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100220if (REGRESSION)
221 set(SERVICES_TEST_ENABLED ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100222endif()
223
Edison Aiec109cd2018-07-17 16:04:14 +0800224if (CORE_IPC)
225 set(TFM_PSA_API ON)
David Huf2cfa122019-08-27 15:32:38 +0800226
227 # Disable IPC Test by default if the config or platform doesn't explicitly
228 # require it
229 if (NOT DEFINED IPC_TEST)
230 set(IPC_TEST OFF)
231 endif()
232else()
233 set(IPC_TEST OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800234endif()
235
Miklos Balint87da2512018-04-19 13:45:50 +0200236if (TFM_PSA_API)
237 add_definitions(-DTFM_PSA_API)
238endif()
239
David Hu104388f2019-11-18 14:37:32 +0800240if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY)
241 add_definitions(-DTFM_MULTI_CORE_TOPOLOGY)
David Huaeaf2732019-10-10 14:32:53 +0800242
243 # Skip multi-core test cases if regression test is disabled
244 if (NOT REGRESSION)
245 set(TFM_MULTI_CORE_TEST OFF)
246 endif()
David Hu104388f2019-11-18 14:37:32 +0800247endif()
248
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100249if (SERVICES_TEST_ENABLED)
250 set(SERVICE_TEST_S ON)
251 set(SERVICE_TEST_NS ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100252endif()
253
254if (CORE_TEST)
Kevin Peng726ad7a2020-01-22 15:49:29 +0800255 if (NOT CORE_IPC OR TFM_LVL EQUAL 1)
256 set(CORE_TEST_POSITIVE ON)
257 endif()
Mate Toth-Pal6569a592019-06-07 12:09:50 +0200258 set(CORE_TEST_INTERACTIVE OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100259endif()
260
Ben Davis6d7256b2018-04-18 14:16:53 +0100261if (CORE_TEST_INTERACTIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100262 add_definitions(-DCORE_TEST_INTERACTIVE)
263 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100264 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100265endif()
266
Ben Davis6d7256b2018-04-18 14:16:53 +0100267if (CORE_TEST_POSITIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100268 add_definitions(-DCORE_TEST_POSITIVE)
269 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100270 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100271endif()
272
David Hu33f2fd22019-08-16 15:32:39 +0800273if (TFM_PARTITION_TEST_CORE)
274 # If the platform or the topology doesn't specify whether IRQ test is
275 # supported, enable it by default.
276 if (NOT DEFINED TFM_ENABLE_IRQ_TEST)
277 set(TFM_ENABLE_IRQ_TEST ON)
278 endif()
279
280 if (TFM_ENABLE_IRQ_TEST)
281 add_definitions(-DTFM_ENABLE_IRQ_TEST)
282 endif()
283else()
284 set(TFM_ENABLE_IRQ_TEST OFF)
285endif()
286
David Huf2cfa122019-08-27 15:32:38 +0800287if (IPC_TEST)
288 add_definitions(-DENABLE_IPC_TEST)
Jamie Foxadf02552019-05-16 17:44:52 +0100289 set(TEST_FRAMEWORK_NS ON)
290 set(TFM_PARTITION_TEST_CORE_IPC ON)
Edison Aiec109cd2018-07-17 16:04:14 +0800291endif()
292
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100293if (SERVICE_TEST_S)
294 add_definitions(-DSERVICES_TEST_S)
295 set(TEST_FRAMEWORK_S ON)
296endif()
297
298if (SERVICE_TEST_NS)
299 add_definitions(-DSERVICES_TEST_NS)
300 set(TEST_FRAMEWORK_NS ON)
301endif()
302
Ben Davis6d7256b2018-04-18 14:16:53 +0100303if (TEST_FRAMEWORK_S)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100304 add_definitions(-DTEST_FRAMEWORK_S)
Jamie Fox56da0992019-05-28 14:35:06 +0100305 # The secure client partition is required to run secure tests
306 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100307endif()
308
Ben Davis6d7256b2018-04-18 14:16:53 +0100309if (TEST_FRAMEWORK_NS)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100310 add_definitions(-DTEST_FRAMEWORK_NS)
311endif()
312
Jamie Foxc78c62c2019-05-23 13:42:17 +0100313if (CORE_IPC)
314 set(TFM_PARTITION_AUDIT_LOG OFF)
315endif()
316
Kevin Pengc5781482020-07-08 15:30:24 +0800317include(${TEST_DIR}/TestConfig.cmake)
Kevin Pengedde1de2019-10-25 17:12:45 +0800318
Jamie Foxc78c62c2019-05-23 13:42:17 +0100319if (TFM_PARTITION_AUDIT_LOG)
320 add_definitions(-DTFM_PARTITION_AUDIT_LOG)
321endif()
322
Mingyang Sun9511e5e2019-05-29 18:18:44 +0800323if (TFM_PARTITION_PLATFORM)
324 add_definitions(-DTFM_PARTITION_PLATFORM)
325endif()
326
Kevin Pengc6d74502020-03-04 16:55:37 +0800327if (TFM_PARTITION_PROTECTED_STORAGE)
328 add_definitions(-DTFM_PARTITION_PROTECTED_STORAGE)
Kevin Pengc73130f2019-10-22 17:27:18 +0800329endif()
330
331if (TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
332 add_definitions(-DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
333endif()
334
335if (TFM_PARTITION_CRYPTO)
336 add_definitions(-DTFM_PARTITION_CRYPTO)
337endif()
338
339if (TFM_PARTITION_INITIAL_ATTESTATION)
340 add_definitions(-DTFM_PARTITION_INITIAL_ATTESTATION)
David Hu724a12d2020-01-21 15:44:21 +0800341
342 if (NOT DEFINED SYMMETRIC_INITIAL_ATTESTATION)
343 set(SYMMETRIC_INITIAL_ATTESTATION OFF)
344 endif()
345
346 if (SYMMETRIC_INITIAL_ATTESTATION)
347 add_definitions(-DSYMMETRIC_INITIAL_ATTESTATION)
348 endif()
Kevin Pengc73130f2019-10-22 17:27:18 +0800349endif()
350
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100351if (TFM_PARTITION_TEST_CORE)
352 add_definitions(-DTFM_PARTITION_TEST_CORE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100353endif()
354
Jamie Foxadf02552019-05-16 17:44:52 +0100355if (TFM_PARTITION_TEST_CORE_IPC)
356 add_definitions(-DTFM_PARTITION_TEST_CORE_IPC)
357endif()
358
Jamie Foxc78c62c2019-05-23 13:42:17 +0100359if (TFM_PARTITION_TEST_SECURE_SERVICES)
360 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
361endif()
362
Edison Ai1dfd7b12020-02-23 14:16:08 +0800363if (CONFIG_TFM_ENABLE_MEMORY_PROTECT)
364 add_definitions(-DCONFIG_TFM_ENABLE_MEMORY_PROTECT)
365endif()
366
Jamie Fox17c30bb2019-01-10 13:39:33 +0000367if (PSA_API_TEST)
368 add_definitions(-DPSA_API_TEST_NS)
369 set(PSA_API_TEST_NS ON)
370 if (NOT DEFINED PSA_API_TEST_CRYPTO)
371 set(PSA_API_TEST_CRYPTO OFF)
372 endif()
Vinay Kumar Kotegowder75641062020-04-24 16:44:12 +0530373 if (NOT DEFINED PSA_API_TEST_STORAGE)
374 set(PSA_API_TEST_STORAGE OFF)
375 endif()
Jamie Fox6b6a19b2019-09-30 16:54:17 +0100376 if (NOT DEFINED PSA_API_TEST_INTERNAL_TRUSTED_STORAGE)
377 set(PSA_API_TEST_INTERNAL_TRUSTED_STORAGE OFF)
378 endif()
Karl Zhang1895a2c2020-03-08 18:27:32 +0800379 if (NOT DEFINED PSA_API_TEST_PROTECTED_STORAGE)
380 set(PSA_API_TEST_PROTECTED_STORAGE OFF)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000381 endif()
Karl Zhang1895a2c2020-03-08 18:27:32 +0800382 if (NOT DEFINED PSA_API_TEST_INITIAL_ATTESTATION)
383 set(PSA_API_TEST_INITIAL_ATTESTATION OFF)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000384 endif()
Jaykumar Pitambarbhai Patel38e6db52020-01-09 16:35:41 +0530385 if (NOT DEFINED PSA_API_TEST_IPC)
386 set(PSA_API_TEST_IPC OFF)
387 endif()
388
389 #Set PSA API compliance test build path
390 if(NOT DEFINED PSA_API_TEST_BUILD_PATH)
391 #If not specified, assume it's the default build folder checked out at the same level of TFM root dir
392 set(PSA_API_TEST_BUILD_PATH "${TFM_ROOT_DIR}/../psa-arch-tests/api-tests/BUILD")
393 endif()
Jamie Fox17c30bb2019-01-10 13:39:33 +0000394endif()
395
Kevin Penge9b61a72020-01-06 17:01:44 +0800396# The config for enable secure context management in TF-M
397if (NOT DEFINED CONFIG_TFM_ENABLE_CTX_MGMT)
398 set(CONFIG_TFM_ENABLE_CTX_MGMT ON)
399endif()
400
401if (CONFIG_TFM_ENABLE_CTX_MGMT)
402 add_definitions(-DCONFIG_TFM_ENABLE_CTX_MGMT)
403endif()
404
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100405# This flag indicates if the non-secure OS is capable of identify the non-secure clients
Mingyang Sun9ac02372019-08-26 15:59:14 +0800406# which call the secure services. It is diabled in IPC model.
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100407if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
Mingyang Sun9ac02372019-08-26 15:59:14 +0800408 if (TFM_PSA_API)
409 set(TFM_NS_CLIENT_IDENTIFICATION OFF)
410 else()
Kevin Penge9b61a72020-01-06 17:01:44 +0800411 if (CONFIG_TFM_ENABLE_CTX_MGMT)
412 set(TFM_NS_CLIENT_IDENTIFICATION ON)
413 else()
414 set(TFM_NS_CLIENT_IDENTIFICATION OFF)
415 endif()
Mingyang Sun9ac02372019-08-26 15:59:14 +0800416 endif()
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100417endif()
418
Kevin Penge9b61a72020-01-06 17:01:44 +0800419if (NOT CONFIG_TFM_ENABLE_CTX_MGMT AND TFM_NS_CLIENT_IDENTIFICATION)
420 # NS client ID is part of context management.
421 message(FATAL_ERROR "TFM_NS_CLIENT_IDENTIFICATION cannot be ON when CONFIG_TFM_ENABLE_CTX_MGMT is OFF")
422endif()
423
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100424if (BL2)
David Vincze63eda7a2019-08-09 17:42:51 +0200425 # Add MCUBOOT_IMAGE_NUMBER definition to the compiler command line.
426 add_definitions(-DMCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER})
427
David Vincze4638b2a2019-05-24 10:14:23 +0200428 if (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP")
Tamas Bandb69d522018-03-01 10:04:41 +0000429 set(LINK_TO_BOTH_MEMORY_REGION ON)
430 endif()
David Vincze53998032020-06-10 15:54:31 +0200431
432 if (MCUBOOT_REPO STREQUAL "TF-M")
433 # FixMe: LEGACY_TFM_TLV_HEADER could be removed when MCUBoot fork is deleted.
434 set(LEGACY_TFM_TLV_HEADER ON)
435 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100436endif()
437
Raef Coles1bb168e2019-10-17 09:04:55 +0100438##Set Mbed Crypto compiler flags and variables for crypto service
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100439set(MBEDCRYPTO_C_FLAGS_SERVICES "${CMSE_FLAGS} -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -I${CMAKE_CURRENT_LIST_DIR}/platform/ext/common")
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100440
Kevin Pengc6d74502020-03-04 16:55:37 +0800441#Default TF-M protected storage flags.
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000442#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
Kevin Pengc6d74502020-03-04 16:55:37 +0800443#Documentation about these flags can be found in docs/user_guides/services/tfm_ps_integration_guide.rst
444if (NOT DEFINED PS_ENCRYPTION)
445 set (PS_ENCRYPTION ON)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000446endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000447
Kevin Pengc6d74502020-03-04 16:55:37 +0800448if (NOT DEFINED PS_ROLLBACK_PROTECTION)
449 set (PS_ROLLBACK_PROTECTION OFF)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000450endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000451
Kevin Pengc6d74502020-03-04 16:55:37 +0800452if (NOT DEFINED PS_CREATE_FLASH_LAYOUT)
453 set (PS_CREATE_FLASH_LAYOUT OFF)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000454endif()
Marc Moreno Berengue184d2032018-08-14 12:51:43 +0100455
Kevin Pengc6d74502020-03-04 16:55:37 +0800456if (NOT DEFINED PS_VALIDATE_METADATA_FROM_FLASH)
457 set (PS_VALIDATE_METADATA_FROM_FLASH ON)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000458endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000459
Kevin Pengc6d74502020-03-04 16:55:37 +0800460if (NOT DEFINED PS_RAM_FS)
Jamie Foxf58bd222020-06-12 18:21:25 +0100461 set (PS_RAM_FS OFF)
Marc Moreno Berengue792fc682018-02-20 11:53:30 +0000462endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000463
Kevin Pengc6d74502020-03-04 16:55:37 +0800464if (NOT DEFINED PS_TEST_NV_COUNTERS)
465 if (REGRESSION AND ENABLE_PROTECTED_STORAGE_SERVICE_TESTS)
466 set(PS_TEST_NV_COUNTERS ON)
Jamie Fox95bacd42019-03-21 18:14:15 +0000467 else()
Kevin Pengc6d74502020-03-04 16:55:37 +0800468 set(PS_TEST_NV_COUNTERS OFF)
Jamie Fox95bacd42019-03-21 18:14:15 +0000469 endif()
470endif()
471
Kevin Pengc6d74502020-03-04 16:55:37 +0800472# The PS NV counter tests depend on the PS test partition to call
473# ps_system_prepare().
474if (PS_TEST_NV_COUNTERS)
475 set(TFM_PARTITION_TEST_PS ON)
476 add_definitions(-DTFM_PARTITION_TEST_PS)
Jamie Fox0e823a02019-10-28 17:28:19 +0000477endif()
478
TudorCretufb182bc2019-07-05 17:34:12 +0100479#Default TF-M internal trusted storage flags.
480#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
481#Documentation about these flags can be found in the TF-M ITS integration guide
482option(ITS_CREATE_FLASH_LAYOUT "Create an empty ITS Flash Layout" OFF)
483
484if (NOT DEFINED ITS_VALIDATE_METADATA_FROM_FLASH)
485 set (ITS_VALIDATE_METADATA_FROM_FLASH ON)
486endif()
487
488if (NOT DEFINED ITS_RAM_FS)
Jamie Foxf58bd222020-06-12 18:21:25 +0100489 set (ITS_RAM_FS OFF)
TudorCretufb182bc2019-07-05 17:34:12 +0100490endif()
491
Raef Coles1bb168e2019-10-17 09:04:55 +0100492if (NOT DEFINED MBEDCRYPTO_DEBUG)
493 set(MBEDCRYPTO_DEBUG OFF)
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000494endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100495
Tamas Ban01f64c52019-08-26 13:46:21 +0100496#Default TF-M initial-attestation service flags.
497#Documentation about these flags can be found in docs/user_guides/services/tfm_attestation_integration_guide.rst
498if (NOT DEFINED ATTEST_INCLUDE_OPTIONAL_CLAIMS)
499 set(ATTEST_INCLUDE_OPTIONAL_CLAIMS ON)
500endif()
501
Tamas Banabea89d2020-01-15 13:29:25 +0000502if (NOT DEFINED ATTEST_INCLUDE_COSE_KEY_ID)
503 set(ATTEST_INCLUDE_COSE_KEY_ID OFF)
504endif()
505
506if (NOT DEFINED ATTEST_INCLUDE_TEST_CODE)
507 if (CMAKE_BUILD_TYPE STREQUAL "debug")
508 set(ATTEST_INCLUDE_TEST_CODE ON)
509 else()
510 set(ATTEST_INCLUDE_TEST_CODE OFF)
511 endif()
Tamas Ban303dd082019-08-27 10:43:03 +0100512endif()
513
David Vinczee13a48b2020-01-08 17:42:30 +0100514if (NOT DEFINED BOOT_DATA_AVAILABLE)
David Vincze141f2152020-02-19 09:42:07 +0100515 if (BL2)
David Vinczee13a48b2020-01-08 17:42:30 +0100516 set(BOOT_DATA_AVAILABLE ON)
517 else()
518 set(BOOT_DATA_AVAILABLE OFF)
519 endif()
520endif()
521
Balint Matyi95f58eb2020-05-22 08:52:32 +0100522if (NOT DEFINED ATTEST_CLAIM_VALUE_CHECK)
523 set(ATTEST_CLAIM_VALUE_CHECK OFF)
524endif()
525
Tamas Bandb69d522018-03-01 10:04:41 +0000526##Set mbedTLS compiler flags for BL2 bootloader
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100527set(MBEDCRYPTO_C_FLAGS_BL2 "${CMSE_FLAGS} -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -DMBEDTLS_CONFIG_FILE=\\\\\\\"config-rsa.h\\\\\\\" -I${CMAKE_CURRENT_LIST_DIR}/bl2/ext/mcuboot/include")
Tamas Ban7801ed42019-05-20 13:21:53 +0100528if (MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072")
Raef Coles1bb168e2019-10-17 09:04:55 +0100529 string(APPEND MBEDCRYPTO_C_FLAGS_BL2 " -DMCUBOOT_SIGN_RSA_LEN=3072")
Jamie Foxc78c62c2019-05-23 13:42:17 +0100530endif()