blob: 583bbba0bba52bc66d6e0e1f1972b86b00126e8e [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 Pengb3a70452020-07-08 17:50:09 +080024set(TEST_DIR ${CMAKE_SOURCE_DIR}/../tf-m-tests/test)
Kevin Pengc5781482020-07-08 15:30:24 +080025
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
Karl Zhangb10723f2020-07-23 11:47:05 +080097if(NOT ${COMPILER} STREQUAL "GNUARM")
98 if(CODE_COVERAGE_EN)
99 message(WARNING "CODE COVERAGE for '${COMPILER}' is not supported.")
100 endif()
101endif()
102
Mate Toth-Palee551bc2018-06-12 16:40:45 +0200103if(${COMPILER} STREQUAL "ARMCLANG")
Mate Toth-Pal76867262018-03-09 13:15:36 +0100104 #Use any ARMCLANG version found on PATH. Note: Only versions supported by the
105 #build system will work. A file cmake/Common/CompilerArmClangXY.cmake
106 #must be present with a matching version.
107 include("Common/FindArmClang")
108 include("Common/${ARMCLANG_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100109
Ken Liu8e7622b2020-04-16 17:05:56 +0800110 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 +0000111 ##Shared compiler settings.
112 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100113 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 +0000114 endfunction()
115
116 ##Shared linker settings.
117 function(config_setting_shared_linker_flags tgt)
Antonio de Angelis3302f452019-07-19 10:36:33 +0100118 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 +0100119 endfunction()
120elseif(${COMPILER} STREQUAL "GNUARM")
121 #Use any GNUARM version found on PATH. Note: Only versions supported by the
122 #build system will work. A file cmake/Common/CompilerGNUARMXY.cmake
123 #must be present with a matching version.
124 include("Common/FindGNUARM")
125 include("Common/${GNUARM_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +0100126
Ken Liu8e7622b2020-04-16 17:05:56 +0800127 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -ffunction-sections -fdata-sections --specs=nano.specs -fno-builtin)
Karl Zhangb10723f2020-07-23 11:47:05 +0800128
129 #Code coverage required
130 if(CODE_COVERAGE_EN)
131 set (CODE_COVERAGE_FLAGS -g)
132 else()
133 unset (CODE_COVERAGE_FLAGS)
134 endif()
135
Mate Toth-Pal76867262018-03-09 13:15:36 +0100136 ##Shared compiler and linker settings.
Tamas Bandb69d522018-03-01 10:04:41 +0000137 function(config_setting_shared_compiler_flags tgt)
Karl Zhangb10723f2020-07-23 11:47:05 +0800138 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} ${CODE_COVERAGE_FLAGS} -Wall -Werror -Wno-format -Wno-return-type -Wno-unused-but-set-variable)
Tamas Bandb69d522018-03-01 10:04:41 +0000139 endfunction()
140
141 ##Shared linker settings.
142 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +0100143 #--no-wchar-size-warning flag is added because TF-M sources are compiled
144 #with short wchars, however the standard library is compiled with normal
145 #wchar, and this generates linker time warnings. TF-M code does not use
146 #wchar, so the warning can be suppressed.
Antonio de Angelis3302f452019-07-19 10:36:33 +0100147 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 +0100148 endfunction()
TTornblom99f0be22019-12-17 16:22:38 +0100149elseif(${COMPILER} STREQUAL "IARARM")
150 #Use any IARARM version found on PATH. Note: Only versions supported by the
151 #build system will work. A file cmake/Common/CompilerIARARMXY.cmake
152 #must be present with a matching version.
153 include("Common/FindIARARM")
154 include("Common/${IARARM_MODULE}")
155
TTornblomae979882020-04-24 13:39:23 +0200156 set (COMMON_COMPILE_FLAGS -e --dlib_config=full --vla --silent -DNO_TYPEOF --diag_suppress Pe546,Pe940,Pa082,Pa084)
TTornblom99f0be22019-12-17 16:22:38 +0100157 ##Shared compiler and linker settings.
158 function(config_setting_shared_compiler_flags tgt)
TTornblom17766722020-07-10 08:42:44 +0200159 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C APPEND FLAGS ${COMMON_COMPILE_FLAGS} )
TTornblom99f0be22019-12-17 16:22:38 +0100160 endfunction()
161
162 ##Shared linker settings.
163 function(config_setting_shared_linker_flags tgt)
164 #--no-wchar-size-warning flag is added because TF-M sources are compiled
165 #with short wchars, however the standard library is compiled with normal
166 #wchar, and this generates linker time warnings. TF-M code does not use
167 #wchar, so the warning can be suppressed.
168 embedded_set_target_link_flags(TARGET ${tgt} FLAGS --silent --semihosting --redirect __write=__write_buffered)
169 endfunction()
Mate Toth-Pal76867262018-03-09 13:15:36 +0100170endif()
171
172#Create a string from the compile flags list, so that it can be used later
173#in this file to set mbedtls and BL2 flags
Tamas Bandb69d522018-03-01 10:04:41 +0000174list_to_string(COMMON_COMPILE_FLAGS_STR ${COMMON_COMPILE_FLAGS})
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100175
176#Settings which shall be set for all projects the same way based
177# on the variables above.
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100178set (TFM_PARTITION_TEST_CORE OFF)
Jamie Foxadf02552019-05-16 17:44:52 +0100179set (TFM_PARTITION_TEST_CORE_IPC OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100180set (CORE_TEST_POSITIVE OFF)
181set (CORE_TEST_INTERACTIVE OFF)
Ben Davis6d7256b2018-04-18 14:16:53 +0100182set (TFM_PARTITION_TEST_SECURE_SERVICES OFF)
Kevin Pengc6d74502020-03-04 16:55:37 +0800183set (TFM_PARTITION_TEST_PS OFF)
Tamas Band90c81b2018-08-15 15:03:42 +0100184set (SERVICES_TEST_ENABLED OFF)
Marc Moreno Berenguecae2c532018-10-09 12:58:46 +0100185set (TEST_FRAMEWORK_S OFF)
186set (TEST_FRAMEWORK_NS OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800187set (TFM_PSA_API OFF)
Miklos Balintf13ec022018-04-06 17:21:22 +0200188
David Hu60105382019-12-25 13:37:05 +0800189if (NOT DEFINED TFM_PARTITION_AUDIT_LOG)
190 # Enable the TF-M Audit Log partition
191 set(TFM_PARTITION_AUDIT_LOG ON)
192endif()
193if (NOT DEFINED TFM_PARTITION_PLATFORM)
194 # Enable the TF-M Platform partition
195 set(TFM_PARTITION_PLATFORM ON)
196endif()
Kevin Pengc6d74502020-03-04 16:55:37 +0800197if (NOT DEFINED TFM_PARTITION_PROTECTED_STORAGE)
198 # Enable the TF-M Protected storage partition
199 set(TFM_PARTITION_PROTECTED_STORAGE ON)
David Hu60105382019-12-25 13:37:05 +0800200endif()
201if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
202 # Enable the TF-M internal trusted storage partition
203 set(TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ON)
204endif()
205if (NOT DEFINED TFM_PARTITION_CRYPTO)
206 # Enable the TF-M crypto partition
207 set(TFM_PARTITION_CRYPTO ON)
208endif()
209if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION)
210 # Enable the TF-M initial attestation partition
211 set(TFM_PARTITION_INITIAL_ATTESTATION ON)
212endif()
Kevin Pengc73130f2019-10-22 17:27:18 +0800213
Edison Ai1dfd7b12020-02-23 14:16:08 +0800214if (NOT TFM_LVL EQUAL 1 AND NOT DEFINED CONFIG_TFM_ENABLE_MEMORY_PROTECT)
215 set (CONFIG_TFM_ENABLE_MEMORY_PROTECT ON)
216endif()
217
Kevin Pengc6d74502020-03-04 16:55:37 +0800218if (TFM_PARTITION_INITIAL_ATTESTATION OR TFM_PARTITION_PROTECTED_STORAGE)
Kevin Pengc73130f2019-10-22 17:27:18 +0800219 #PSA Initial Attestation and Protected storage rely on Cryptography API
220 set(TFM_PARTITION_CRYPTO ON)
221endif()
Jamie Foxc78c62c2019-05-23 13:42:17 +0100222
Kevin Pengc6d74502020-03-04 16:55:37 +0800223if (TFM_PARTITION_PROTECTED_STORAGE)
Kevin Peng0b5acd32020-03-03 15:17:58 +0800224 set(TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ON)
225endif()
226
Miklos Balint6cbeba62018-04-12 17:31:34 +0200227# Option to demonstrate usage of secure-only peripheral
Øyvind Rønningstad8f895ab2020-09-02 11:09:19 +0200228if (NOT DEFINED SECURE_UART1)
229 set (SECURE_UART1 OFF)
230endif()
Miklos Balint6cbeba62018-04-12 17:31:34 +0200231
Alan DeMars61844692019-10-22 08:23:29 -0700232if (PLATFORM_SVC_HANDLERS)
233 add_definitions(-DPLATFORM_SVC_HANDLERS)
234endif()
235
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100236if (REGRESSION)
237 set(SERVICES_TEST_ENABLED ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100238endif()
239
Edison Aiec109cd2018-07-17 16:04:14 +0800240if (CORE_IPC)
241 set(TFM_PSA_API ON)
David Huf2cfa122019-08-27 15:32:38 +0800242
243 # Disable IPC Test by default if the config or platform doesn't explicitly
244 # require it
245 if (NOT DEFINED IPC_TEST)
246 set(IPC_TEST OFF)
247 endif()
248else()
249 set(IPC_TEST OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800250endif()
251
Miklos Balint87da2512018-04-19 13:45:50 +0200252if (TFM_PSA_API)
253 add_definitions(-DTFM_PSA_API)
254endif()
255
David Hu104388f2019-11-18 14:37:32 +0800256if (DEFINED TFM_MULTI_CORE_TOPOLOGY AND TFM_MULTI_CORE_TOPOLOGY)
257 add_definitions(-DTFM_MULTI_CORE_TOPOLOGY)
David Huaeaf2732019-10-10 14:32:53 +0800258
259 # Skip multi-core test cases if regression test is disabled
260 if (NOT REGRESSION)
261 set(TFM_MULTI_CORE_TEST OFF)
262 endif()
David Hu104388f2019-11-18 14:37:32 +0800263endif()
264
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100265if (SERVICES_TEST_ENABLED)
266 set(SERVICE_TEST_S ON)
267 set(SERVICE_TEST_NS ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100268endif()
269
270if (CORE_TEST)
Kevin Peng726ad7a2020-01-22 15:49:29 +0800271 if (NOT CORE_IPC OR TFM_LVL EQUAL 1)
272 set(CORE_TEST_POSITIVE ON)
273 endif()
Mate Toth-Pal6569a592019-06-07 12:09:50 +0200274 set(CORE_TEST_INTERACTIVE OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100275endif()
276
Ben Davis6d7256b2018-04-18 14:16:53 +0100277if (CORE_TEST_INTERACTIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100278 add_definitions(-DCORE_TEST_INTERACTIVE)
279 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100280 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100281endif()
282
Ben Davis6d7256b2018-04-18 14:16:53 +0100283if (CORE_TEST_POSITIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100284 add_definitions(-DCORE_TEST_POSITIVE)
285 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100286 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100287endif()
288
David Hu33f2fd22019-08-16 15:32:39 +0800289if (TFM_PARTITION_TEST_CORE)
290 # If the platform or the topology doesn't specify whether IRQ test is
291 # supported, enable it by default.
292 if (NOT DEFINED TFM_ENABLE_IRQ_TEST)
293 set(TFM_ENABLE_IRQ_TEST ON)
294 endif()
295
296 if (TFM_ENABLE_IRQ_TEST)
297 add_definitions(-DTFM_ENABLE_IRQ_TEST)
298 endif()
299else()
300 set(TFM_ENABLE_IRQ_TEST OFF)
301endif()
302
David Huf2cfa122019-08-27 15:32:38 +0800303if (IPC_TEST)
304 add_definitions(-DENABLE_IPC_TEST)
Jamie Foxadf02552019-05-16 17:44:52 +0100305 set(TEST_FRAMEWORK_NS ON)
306 set(TFM_PARTITION_TEST_CORE_IPC ON)
Edison Aiec109cd2018-07-17 16:04:14 +0800307endif()
308
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100309if (SERVICE_TEST_S)
310 add_definitions(-DSERVICES_TEST_S)
311 set(TEST_FRAMEWORK_S ON)
312endif()
313
314if (SERVICE_TEST_NS)
315 add_definitions(-DSERVICES_TEST_NS)
316 set(TEST_FRAMEWORK_NS ON)
317endif()
318
Ben Davis6d7256b2018-04-18 14:16:53 +0100319if (TEST_FRAMEWORK_S)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100320 add_definitions(-DTEST_FRAMEWORK_S)
Jamie Fox56da0992019-05-28 14:35:06 +0100321 # The secure client partition is required to run secure tests
322 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100323endif()
324
Ben Davis6d7256b2018-04-18 14:16:53 +0100325if (TEST_FRAMEWORK_NS)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100326 add_definitions(-DTEST_FRAMEWORK_NS)
327endif()
328
Jamie Foxc78c62c2019-05-23 13:42:17 +0100329if (CORE_IPC)
330 set(TFM_PARTITION_AUDIT_LOG OFF)
331endif()
332
Kevin Pengc5781482020-07-08 15:30:24 +0800333include(${TEST_DIR}/TestConfig.cmake)
Kevin Pengedde1de2019-10-25 17:12:45 +0800334
Jamie Foxc78c62c2019-05-23 13:42:17 +0100335if (TFM_PARTITION_AUDIT_LOG)
336 add_definitions(-DTFM_PARTITION_AUDIT_LOG)
337endif()
338
Mingyang Sun9511e5e2019-05-29 18:18:44 +0800339if (TFM_PARTITION_PLATFORM)
340 add_definitions(-DTFM_PARTITION_PLATFORM)
341endif()
342
Kevin Pengc6d74502020-03-04 16:55:37 +0800343if (TFM_PARTITION_PROTECTED_STORAGE)
344 add_definitions(-DTFM_PARTITION_PROTECTED_STORAGE)
Kevin Pengc73130f2019-10-22 17:27:18 +0800345endif()
346
347if (TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
348 add_definitions(-DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
349endif()
350
351if (TFM_PARTITION_CRYPTO)
352 add_definitions(-DTFM_PARTITION_CRYPTO)
353endif()
354
355if (TFM_PARTITION_INITIAL_ATTESTATION)
356 add_definitions(-DTFM_PARTITION_INITIAL_ATTESTATION)
David Hu724a12d2020-01-21 15:44:21 +0800357
358 if (NOT DEFINED SYMMETRIC_INITIAL_ATTESTATION)
359 set(SYMMETRIC_INITIAL_ATTESTATION OFF)
360 endif()
361
362 if (SYMMETRIC_INITIAL_ATTESTATION)
363 add_definitions(-DSYMMETRIC_INITIAL_ATTESTATION)
364 endif()
Kevin Pengc73130f2019-10-22 17:27:18 +0800365endif()
366
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100367if (TFM_PARTITION_TEST_CORE)
368 add_definitions(-DTFM_PARTITION_TEST_CORE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100369endif()
370
Jamie Foxadf02552019-05-16 17:44:52 +0100371if (TFM_PARTITION_TEST_CORE_IPC)
372 add_definitions(-DTFM_PARTITION_TEST_CORE_IPC)
373endif()
374
Jamie Foxc78c62c2019-05-23 13:42:17 +0100375if (TFM_PARTITION_TEST_SECURE_SERVICES)
376 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
377endif()
378
Edison Ai1dfd7b12020-02-23 14:16:08 +0800379if (CONFIG_TFM_ENABLE_MEMORY_PROTECT)
380 add_definitions(-DCONFIG_TFM_ENABLE_MEMORY_PROTECT)
381endif()
382
Jamie Fox17c30bb2019-01-10 13:39:33 +0000383if (PSA_API_TEST)
384 add_definitions(-DPSA_API_TEST_NS)
385 set(PSA_API_TEST_NS ON)
386 if (NOT DEFINED PSA_API_TEST_CRYPTO)
387 set(PSA_API_TEST_CRYPTO OFF)
388 endif()
Vinay Kumar Kotegowder75641062020-04-24 16:44:12 +0530389 if (NOT DEFINED PSA_API_TEST_STORAGE)
390 set(PSA_API_TEST_STORAGE OFF)
391 endif()
Jamie Fox6b6a19b2019-09-30 16:54:17 +0100392 if (NOT DEFINED PSA_API_TEST_INTERNAL_TRUSTED_STORAGE)
393 set(PSA_API_TEST_INTERNAL_TRUSTED_STORAGE OFF)
394 endif()
Karl Zhang1895a2c2020-03-08 18:27:32 +0800395 if (NOT DEFINED PSA_API_TEST_PROTECTED_STORAGE)
396 set(PSA_API_TEST_PROTECTED_STORAGE OFF)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000397 endif()
Karl Zhang1895a2c2020-03-08 18:27:32 +0800398 if (NOT DEFINED PSA_API_TEST_INITIAL_ATTESTATION)
399 set(PSA_API_TEST_INITIAL_ATTESTATION OFF)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000400 endif()
Jaykumar Pitambarbhai Patel38e6db52020-01-09 16:35:41 +0530401 if (NOT DEFINED PSA_API_TEST_IPC)
402 set(PSA_API_TEST_IPC OFF)
403 endif()
404
405 #Set PSA API compliance test build path
406 if(NOT DEFINED PSA_API_TEST_BUILD_PATH)
407 #If not specified, assume it's the default build folder checked out at the same level of TFM root dir
408 set(PSA_API_TEST_BUILD_PATH "${TFM_ROOT_DIR}/../psa-arch-tests/api-tests/BUILD")
409 endif()
Jamie Fox17c30bb2019-01-10 13:39:33 +0000410endif()
411
Kevin Penge9b61a72020-01-06 17:01:44 +0800412# The config for enable secure context management in TF-M
413if (NOT DEFINED CONFIG_TFM_ENABLE_CTX_MGMT)
414 set(CONFIG_TFM_ENABLE_CTX_MGMT ON)
415endif()
416
417if (CONFIG_TFM_ENABLE_CTX_MGMT)
418 add_definitions(-DCONFIG_TFM_ENABLE_CTX_MGMT)
419endif()
420
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100421# This flag indicates if the non-secure OS is capable of identify the non-secure clients
Mingyang Sun9ac02372019-08-26 15:59:14 +0800422# which call the secure services. It is diabled in IPC model.
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100423if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
Mingyang Sun9ac02372019-08-26 15:59:14 +0800424 if (TFM_PSA_API)
425 set(TFM_NS_CLIENT_IDENTIFICATION OFF)
426 else()
Kevin Penge9b61a72020-01-06 17:01:44 +0800427 if (CONFIG_TFM_ENABLE_CTX_MGMT)
428 set(TFM_NS_CLIENT_IDENTIFICATION ON)
429 else()
430 set(TFM_NS_CLIENT_IDENTIFICATION OFF)
431 endif()
Mingyang Sun9ac02372019-08-26 15:59:14 +0800432 endif()
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100433endif()
434
Kevin Penge9b61a72020-01-06 17:01:44 +0800435if (NOT CONFIG_TFM_ENABLE_CTX_MGMT AND TFM_NS_CLIENT_IDENTIFICATION)
436 # NS client ID is part of context management.
437 message(FATAL_ERROR "TFM_NS_CLIENT_IDENTIFICATION cannot be ON when CONFIG_TFM_ENABLE_CTX_MGMT is OFF")
438endif()
439
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100440if (BL2)
David Vincze63eda7a2019-08-09 17:42:51 +0200441 # Add MCUBOOT_IMAGE_NUMBER definition to the compiler command line.
442 add_definitions(-DMCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER})
443
David Vincze4638b2a2019-05-24 10:14:23 +0200444 if (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP")
Tamas Bandb69d522018-03-01 10:04:41 +0000445 set(LINK_TO_BOTH_MEMORY_REGION ON)
446 endif()
David Vincze53998032020-06-10 15:54:31 +0200447
448 if (MCUBOOT_REPO STREQUAL "TF-M")
449 # FixMe: LEGACY_TFM_TLV_HEADER could be removed when MCUBoot fork is deleted.
450 set(LEGACY_TFM_TLV_HEADER ON)
451 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100452endif()
453
Raef Coles1bb168e2019-10-17 09:04:55 +0100454##Set Mbed Crypto compiler flags and variables for crypto service
Mate Toth-Pal8f17a712020-03-02 16:22:19 +0100455set(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 +0100456
Kevin Pengc6d74502020-03-04 16:55:37 +0800457#Default TF-M protected storage flags.
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000458#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
Kevin Pengc6d74502020-03-04 16:55:37 +0800459#Documentation about these flags can be found in docs/user_guides/services/tfm_ps_integration_guide.rst
460if (NOT DEFINED PS_ENCRYPTION)
461 set (PS_ENCRYPTION ON)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000462endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000463
Kevin Pengc6d74502020-03-04 16:55:37 +0800464if (NOT DEFINED PS_ROLLBACK_PROTECTION)
465 set (PS_ROLLBACK_PROTECTION OFF)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000466endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000467
Kevin Pengc6d74502020-03-04 16:55:37 +0800468if (NOT DEFINED PS_CREATE_FLASH_LAYOUT)
469 set (PS_CREATE_FLASH_LAYOUT OFF)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000470endif()
Marc Moreno Berengue184d2032018-08-14 12:51:43 +0100471
Kevin Pengc6d74502020-03-04 16:55:37 +0800472if (NOT DEFINED PS_VALIDATE_METADATA_FROM_FLASH)
473 set (PS_VALIDATE_METADATA_FROM_FLASH ON)
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000474endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000475
Kevin Pengc6d74502020-03-04 16:55:37 +0800476if (NOT DEFINED PS_RAM_FS)
Jamie Foxf58bd222020-06-12 18:21:25 +0100477 set (PS_RAM_FS OFF)
Marc Moreno Berengue792fc682018-02-20 11:53:30 +0000478endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000479
Kevin Pengc6d74502020-03-04 16:55:37 +0800480if (NOT DEFINED PS_TEST_NV_COUNTERS)
481 if (REGRESSION AND ENABLE_PROTECTED_STORAGE_SERVICE_TESTS)
482 set(PS_TEST_NV_COUNTERS ON)
Jamie Fox95bacd42019-03-21 18:14:15 +0000483 else()
Kevin Pengc6d74502020-03-04 16:55:37 +0800484 set(PS_TEST_NV_COUNTERS OFF)
Jamie Fox95bacd42019-03-21 18:14:15 +0000485 endif()
486endif()
487
Kevin Pengc6d74502020-03-04 16:55:37 +0800488# The PS NV counter tests depend on the PS test partition to call
489# ps_system_prepare().
490if (PS_TEST_NV_COUNTERS)
491 set(TFM_PARTITION_TEST_PS ON)
492 add_definitions(-DTFM_PARTITION_TEST_PS)
Jamie Fox0e823a02019-10-28 17:28:19 +0000493endif()
494
TudorCretufb182bc2019-07-05 17:34:12 +0100495#Default TF-M internal trusted storage flags.
496#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
497#Documentation about these flags can be found in the TF-M ITS integration guide
498option(ITS_CREATE_FLASH_LAYOUT "Create an empty ITS Flash Layout" OFF)
499
500if (NOT DEFINED ITS_VALIDATE_METADATA_FROM_FLASH)
501 set (ITS_VALIDATE_METADATA_FROM_FLASH ON)
502endif()
503
504if (NOT DEFINED ITS_RAM_FS)
Jamie Foxf58bd222020-06-12 18:21:25 +0100505 set (ITS_RAM_FS OFF)
TudorCretufb182bc2019-07-05 17:34:12 +0100506endif()
507
Raef Coles1bb168e2019-10-17 09:04:55 +0100508if (NOT DEFINED MBEDCRYPTO_DEBUG)
509 set(MBEDCRYPTO_DEBUG OFF)
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000510endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100511
Tamas Ban01f64c52019-08-26 13:46:21 +0100512#Default TF-M initial-attestation service flags.
513#Documentation about these flags can be found in docs/user_guides/services/tfm_attestation_integration_guide.rst
514if (NOT DEFINED ATTEST_INCLUDE_OPTIONAL_CLAIMS)
515 set(ATTEST_INCLUDE_OPTIONAL_CLAIMS ON)
516endif()
517
Tamas Banabea89d2020-01-15 13:29:25 +0000518if (NOT DEFINED ATTEST_INCLUDE_COSE_KEY_ID)
519 set(ATTEST_INCLUDE_COSE_KEY_ID OFF)
520endif()
521
522if (NOT DEFINED ATTEST_INCLUDE_TEST_CODE)
523 if (CMAKE_BUILD_TYPE STREQUAL "debug")
524 set(ATTEST_INCLUDE_TEST_CODE ON)
525 else()
526 set(ATTEST_INCLUDE_TEST_CODE OFF)
527 endif()
Tamas Ban303dd082019-08-27 10:43:03 +0100528endif()
529
David Vinczee13a48b2020-01-08 17:42:30 +0100530if (NOT DEFINED BOOT_DATA_AVAILABLE)
David Vincze141f2152020-02-19 09:42:07 +0100531 if (BL2)
David Vinczee13a48b2020-01-08 17:42:30 +0100532 set(BOOT_DATA_AVAILABLE ON)
533 else()
534 set(BOOT_DATA_AVAILABLE OFF)
535 endif()
536endif()
537
Balint Matyi95f58eb2020-05-22 08:52:32 +0100538if (NOT DEFINED ATTEST_CLAIM_VALUE_CHECK)
539 set(ATTEST_CLAIM_VALUE_CHECK OFF)
540endif()
541
Balint Matyi5c476312020-03-31 13:15:39 +0100542##Set common mbedTLS compiler flags for BL2 bootloader
543set(MBEDCRYPTO_C_FLAGS_BL2 "${CMSE_FLAGS} -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -DMBEDTLS_CONFIG_FILE=\\\\\\\"config-rsa.h\\\\\\\"")