blob: 6bb1f4fa372fb0fe10e204523c5b71ab94c06894 [file] [log] [blame]
Mate Toth-Pal65c935e2018-01-17 18:42:13 +01001#-------------------------------------------------------------------------------
Jamie Fox17c30bb2019-01-10 13:39:33 +00002# Copyright (c) 2018-2019, 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")
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010014endif()
15
Mate Toth-Palee551bc2018-06-12 16:40:45 +020016if(NOT DEFINED COMPILER)
17 message(FATAL_ERROR "ERROR: COMPILER is not set in command line")
18elseif((NOT ${COMPILER} STREQUAL "ARMCLANG") AND (NOT ${COMPILER} STREQUAL "GNUARM"))
19 message(FATAL_ERROR "ERROR: Compiler \"${COMPILER}\" is not supported.")
20endif()
21
David Vincze4638b2a2019-05-24 10:14:23 +020022#BL2 bootloader (MCUBoot) related settings
23if(NOT DEFINED BL2)
24 set(BL2 True CACHE BOOL "Configure TF-M to use BL2 and enable building BL2")
25endif()
26if (BL2)
27 if (NOT DEFINED MCUBOOT_UPGRADE_STRATEGY)
David Vincze8a2a4e22019-05-24 10:14:23 +020028 set (MCUBOOT_UPGRADE_STRATEGY "OVERWRITE_ONLY" CACHE STRING "Configure BL2 which upgrade strategy to use")
David Vincze4638b2a2019-05-24 10:14:23 +020029 set_property(CACHE MCUBOOT_UPGRADE_STRATEGY PROPERTY STRINGS "OVERWRITE_ONLY;SWAP;NO_SWAP;RAM_LOADING")
30 endif()
31endif()
32
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010033set(BUILD_CMSIS_CORE Off)
34set(BUILD_RETARGET Off)
35set(BUILD_NATIVE_DRIVERS Off)
36set(BUILD_TIME Off)
37set(BUILD_STARTUP Off)
38set(BUILD_TARGET_CFG Off)
39set(BUILD_TARGET_HARDWARE_KEYS Off)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010040set(BUILD_TARGET_NV_COUNTERS Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010041set(BUILD_CMSIS_DRIVERS Off)
42set(BUILD_UART_STDOUT Off)
43set(BUILD_FLASH Off)
Tamas Ban3681ce02018-11-22 15:19:24 +000044set(BUILD_BOOT_SEED Off)
Tamas Ban38e17312018-11-22 15:26:35 +000045set(BUILD_DEVICE_ID Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010046if(NOT DEFINED PLATFORM_CMAKE_FILE)
47 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
48elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
49 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
50else()
51 include(${PLATFORM_CMAKE_FILE})
52endif()
53
Oliver Swede21440442018-07-10 09:31:32 +010054if (NOT DEFINED IMAGE_VERSION)
Jamie Fox7a4170d2018-08-15 14:13:42 +010055 set(IMAGE_VERSION 0.0.0+0)
Oliver Swede21440442018-07-10 09:31:32 +010056endif()
57
Mate Toth-Palee551bc2018-06-12 16:40:45 +020058if(${COMPILER} STREQUAL "ARMCLANG")
Mate Toth-Pal76867262018-03-09 13:15:36 +010059 #Use any ARMCLANG version found on PATH. Note: Only versions supported by the
60 #build system will work. A file cmake/Common/CompilerArmClangXY.cmake
61 #must be present with a matching version.
62 include("Common/FindArmClang")
63 include("Common/${ARMCLANG_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010064
Mate Toth-Pal76867262018-03-09 13:15:36 +010065 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -mcmse)
Tamas Bandb69d522018-03-01 10:04:41 +000066 ##Shared compiler settings.
67 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010068 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} -Wall -Werror)
Tamas Bandb69d522018-03-01 10:04:41 +000069 endfunction()
70
71 ##Shared linker settings.
72 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010073 embedded_set_target_link_flags(TARGET ${tgt} FLAGS --strict --map --symbols --xref --entry=Reset_Handler --info=summarysizes,sizes,totals,unused,veneers)
74 endfunction()
75elseif(${COMPILER} STREQUAL "GNUARM")
76 #Use any GNUARM version found on PATH. Note: Only versions supported by the
77 #build system will work. A file cmake/Common/CompilerGNUARMXY.cmake
78 #must be present with a matching version.
79 include("Common/FindGNUARM")
80 include("Common/${GNUARM_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010081
Mate Toth-Palf64f1eb2018-04-26 17:22:37 +020082 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -mcmse --specs=nano.specs)
Mate Toth-Pal76867262018-03-09 13:15:36 +010083 ##Shared compiler and linker settings.
Tamas Bandb69d522018-03-01 10:04:41 +000084 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010085 embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C 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 +000086 endfunction()
87
88 ##Shared linker settings.
89 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010090 #--no-wchar-size-warning flag is added because TF-M sources are compiled
91 #with short wchars, however the standard library is compiled with normal
92 #wchar, and this generates linker time warnings. TF-M code does not use
93 #wchar, so the warning can be suppressed.
Karl Zhangb3b9d952018-08-07 21:47:11 +080094 embedded_set_target_link_flags(TARGET ${tgt} FLAGS -Xlinker -check-sections -Xlinker -fatal-warnings --entry=Reset_Handler -Wl,--no-wchar-size-warning --specs=nano.specs
95 -Wl,--print-memory-usage)
Mate Toth-Pal76867262018-03-09 13:15:36 +010096 endfunction()
Mate Toth-Pal76867262018-03-09 13:15:36 +010097endif()
98
99#Create a string from the compile flags list, so that it can be used later
100#in this file to set mbedtls and BL2 flags
Tamas Bandb69d522018-03-01 10:04:41 +0000101list_to_string(COMMON_COMPILE_FLAGS_STR ${COMMON_COMPILE_FLAGS})
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100102
103#Settings which shall be set for all projects the same way based
104# on the variables above.
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100105set (TFM_PARTITION_TEST_CORE OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100106set (CORE_TEST_POSITIVE OFF)
107set (CORE_TEST_INTERACTIVE OFF)
Ben Davis6d7256b2018-04-18 14:16:53 +0100108set (TEST_FRAMEWORK_S OFF)
Miklos Balintf13ec022018-04-06 17:21:22 +0200109set (REFERENCE_PLATFORM OFF)
Ben Davis6d7256b2018-04-18 14:16:53 +0100110set (TFM_PARTITION_TEST_SECURE_SERVICES OFF)
Tamas Band90c81b2018-08-15 15:03:42 +0100111set (SERVICES_TEST_ENABLED OFF)
Marc Moreno Berenguecae2c532018-10-09 12:58:46 +0100112set (TEST_FRAMEWORK_S OFF)
113set (TEST_FRAMEWORK_NS OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800114set (TFM_PSA_API OFF)
Miklos Balint87da2512018-04-19 13:45:50 +0200115set (TFM_LEGACY_API ON)
Edison Aiec109cd2018-07-17 16:04:14 +0800116set (CORE_TEST_IPC OFF)
Miklos Balintf13ec022018-04-06 17:21:22 +0200117
Jamie Foxc78c62c2019-05-23 13:42:17 +0100118option(TFM_PARTITION_AUDIT_LOG "Enable the TF-M Audit Log partition" ON)
119
Miklos Balintf13ec022018-04-06 17:21:22 +0200120if(${TARGET_PLATFORM} STREQUAL "AN521" OR ${TARGET_PLATFORM} STREQUAL "AN519")
121 set (REFERENCE_PLATFORM ON)
122endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100123
Miklos Balint6cbeba62018-04-12 17:31:34 +0200124# Option to demonstrate usage of secure-only peripheral
125set (SECURE_UART1 OFF)
126
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100127if (REGRESSION)
128 set(SERVICES_TEST_ENABLED ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100129endif()
130
Edison Aiec109cd2018-07-17 16:04:14 +0800131if (CORE_IPC)
132 set(TFM_PSA_API ON)
133 set(CORE_TEST_IPC ON)
134endif()
135
Miklos Balint87da2512018-04-19 13:45:50 +0200136if (TFM_PSA_API)
137 add_definitions(-DTFM_PSA_API)
138endif()
139
140if (TFM_LEGACY_API)
141 add_definitions(-DTFM_LEGACY_API)
142endif()
143
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100144if (SERVICES_TEST_ENABLED)
145 set(SERVICE_TEST_S ON)
146 set(SERVICE_TEST_NS ON)
Edison Ai699d58e2019-05-22 18:03:41 +0800147 if (REFERENCE_PLATFORM AND NOT CORE_IPC)
Miklos Balintf13ec022018-04-06 17:21:22 +0200148 set(CORE_TEST_POSITIVE ON)
149 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100150endif()
151
152if (CORE_TEST)
153 set(CORE_TEST_POSITIVE ON)
154 set(CORE_TEST_INTERACTIVE OFF)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000155 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Tamas Ban244f08c2018-09-20 22:02:30 +0100156 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100157endif()
158
Ben Davis6d7256b2018-04-18 14:16:53 +0100159if (CORE_TEST_INTERACTIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100160 add_definitions(-DCORE_TEST_INTERACTIVE)
161 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100162 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100163endif()
164
Ben Davis6d7256b2018-04-18 14:16:53 +0100165if (CORE_TEST_POSITIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100166 add_definitions(-DCORE_TEST_POSITIVE)
167 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100168 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100169endif()
170
Edison Aiec109cd2018-07-17 16:04:14 +0800171if (CORE_TEST_IPC)
172 add_definitions(-DCORE_TEST_IPC)
Edison Ai7d6cb3b2018-09-19 16:41:50 +0800173 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Antonio de Angelis4743e672019-04-11 11:38:48 +0100174 # If PSA_API_TEST is enabled, don't run TF-M test framework from NS
175 if (PSA_API_TEST)
176 set(TEST_FRAMEWORK_NS OFF)
177 else()
178 set(TEST_FRAMEWORK_NS ON)
179 endif()
Edison Aiec109cd2018-07-17 16:04:14 +0800180endif()
181
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100182if (SERVICE_TEST_S)
183 add_definitions(-DSERVICES_TEST_S)
184 set(TEST_FRAMEWORK_S ON)
Ben Davis6d7256b2018-04-18 14:16:53 +0100185 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100186endif()
187
188if (SERVICE_TEST_NS)
189 add_definitions(-DSERVICES_TEST_NS)
190 set(TEST_FRAMEWORK_NS ON)
191endif()
192
Ben Davis6d7256b2018-04-18 14:16:53 +0100193if (TEST_FRAMEWORK_S)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100194 add_definitions(-DTEST_FRAMEWORK_S)
195endif()
196
Ben Davis6d7256b2018-04-18 14:16:53 +0100197if (TEST_FRAMEWORK_NS)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100198 add_definitions(-DTEST_FRAMEWORK_NS)
199endif()
200
Jamie Foxc78c62c2019-05-23 13:42:17 +0100201if (CORE_IPC)
202 set(TFM_PARTITION_AUDIT_LOG OFF)
203endif()
204
205if (TFM_PARTITION_AUDIT_LOG)
206 add_definitions(-DTFM_PARTITION_AUDIT_LOG)
207endif()
208
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100209if (TFM_PARTITION_TEST_CORE)
210 add_definitions(-DTFM_PARTITION_TEST_CORE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100211endif()
212
Jamie Foxc78c62c2019-05-23 13:42:17 +0100213if (TFM_PARTITION_TEST_SECURE_SERVICES)
214 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
215endif()
216
Jamie Fox17c30bb2019-01-10 13:39:33 +0000217if (PSA_API_TEST)
218 add_definitions(-DPSA_API_TEST_NS)
219 set(PSA_API_TEST_NS ON)
220 if (NOT DEFINED PSA_API_TEST_CRYPTO)
221 set(PSA_API_TEST_CRYPTO OFF)
222 endif()
223 if (NOT DEFINED PSA_API_TEST_SECURE_STORAGE)
224 set(PSA_API_TEST_SECURE_STORAGE OFF)
225 endif()
226 if (NOT DEFINED PSA_API_TEST_ATTESTATION)
227 set(PSA_API_TEST_ATTESTATION OFF)
228 endif()
229endif()
230
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100231# This flag indicates if the non-secure OS is capable of identify the non-secure clients
232# which call the secure services
233if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
234 set (TFM_NS_CLIENT_IDENTIFICATION ON)
235endif()
236
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100237if (BL2)
238 add_definitions(-DBL2)
Tamas Ban7801ed42019-05-20 13:21:53 +0100239 if (NOT ${MCUBOOT_SIGNATURE_TYPE} STREQUAL "RSA-2048" AND NOT ${MCUBOOT_SIGNATURE_TYPE} STREQUAL "RSA-3072")
240 message(FATAL_ERROR "MCUBoot only supports RSA-2048 and RSA-3072 signature")
241 endif()
242 if (NOT DEFINED MCUBOOT_SIGNATURE_TYPE)
Tamas Ban81daed02019-05-20 15:05:22 +0100243 set(MCUBOOT_SIGNATURE_TYPE "RSA-3072")
Tamas Ban7801ed42019-05-20 13:21:53 +0100244 endif()
David Vincze4638b2a2019-05-24 10:14:23 +0200245 if (NOT ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "OVERWRITE_ONLY" AND
246 NOT ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "SWAP" AND
247 NOT ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP" AND
248 NOT ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "RAM_LOADING")
249 message(FATAL_ERROR "ERROR: MCUBoot supports OVERWRITE_ONLY, SWAP, NO_SWAP and RAM_LOADING upgrade strategies only.")
250 endif()
251 if (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP")
Tamas Bandb69d522018-03-01 10:04:41 +0000252 set(LINK_TO_BOTH_MEMORY_REGION ON)
253 endif()
David Vincze4638b2a2019-05-24 10:14:23 +0200254else() #BL2 is turned off
255 if (DEFINED MCUBOOT_UPGRADE_STRATEGY)
256 message (WARNING "Ignoring value of MCUBOOT_UPGRADE_STRATEGY as BL2 option is set to False.")
257 unset (MCUBOOT_UPGRADE_STRATEGY)
Tamas Bandb69d522018-03-01 10:04:41 +0000258 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100259endif()
260
Jamie Foxdaade492019-04-26 14:35:39 +0100261##Set Mbed TLS compiler flags and variables for audit log and crypto
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100262set(MBEDTLS_C_FLAGS_SERVICES "-D__ARM_FEATURE_CMSE=3 -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -I${CMAKE_CURRENT_LIST_DIR}/platform/ext/common")
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100263
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000264#Default TF-M secure storage flags.
265#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
Marc Moreno Berenguef6a64f72018-07-26 17:33:38 +0100266#Documentation about these flags can be found in docs/user_guides/services/tfm_sst_integration_guide.md
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000267if (NOT DEFINED SST_ENCRYPTION)
268 set (SST_ENCRYPTION ON)
269endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000270
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000271if (NOT DEFINED SST_ROLLBACK_PROTECTION)
272 set (SST_ROLLBACK_PROTECTION OFF)
273endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000274
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000275if (NOT DEFINED SST_CREATE_FLASH_LAYOUT)
276 set (SST_CREATE_FLASH_LAYOUT OFF)
277endif()
Marc Moreno Berengue184d2032018-08-14 12:51:43 +0100278
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000279if (NOT DEFINED SST_VALIDATE_METADATA_FROM_FLASH)
280 set (SST_VALIDATE_METADATA_FROM_FLASH ON)
281endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000282
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000283if (NOT DEFINED SST_RAM_FS)
284 if (REGRESSION)
285 set (SST_RAM_FS ON)
286 else()
287 set (SST_RAM_FS OFF)
Marc Moreno Berengue02a23442018-08-15 14:28:45 +0100288 endif()
Marc Moreno Berengue792fc682018-02-20 11:53:30 +0000289endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000290
Jamie Fox95bacd42019-03-21 18:14:15 +0000291if (NOT DEFINED SST_TEST_NV_COUNTERS)
292 if (REGRESSION AND (TFM_LVL EQUAL 1))
293 set(SST_TEST_NV_COUNTERS ON)
294 else()
295 set(SST_TEST_NV_COUNTERS OFF)
296 endif()
297endif()
298
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000299if (NOT DEFINED MBEDTLS_DEBUG)
Jamie Fox287885f2018-10-24 14:09:34 +0100300 set(MBEDTLS_DEBUG OFF)
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000301endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100302
Tamas Bandb69d522018-03-01 10:04:41 +0000303##Set mbedTLS compiler flags for BL2 bootloader
Mate Toth-Pal76867262018-03-09 13:15:36 +0100304set(MBEDTLS_C_FLAGS_BL2 "-D__ARM_FEATURE_CMSE=3 -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -DMBEDTLS_CONFIG_FILE=\\\\\\\"config-boot.h\\\\\\\" -I${CMAKE_CURRENT_LIST_DIR}/bl2/ext/mcuboot/include")
Tamas Ban7801ed42019-05-20 13:21:53 +0100305if (MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072")
306 string(APPEND MBEDTLS_C_FLAGS_BL2 " -DMCUBOOT_SIGN_RSA_LEN=3072")
Jamie Foxc78c62c2019-05-23 13:42:17 +0100307endif()