blob: 4ddd9be1e33c04dd7b98123ef06c9a15c332131c [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")
David Huf2cfa122019-08-27 15:32:38 +080014elseif(NOT DEFINED CORE_IPC)
15 message(FATAL_ERROR "ERROR: Incomplete Configuration: CORE_IPC not deinfed. 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")
20elseif((NOT ${COMPILER} STREQUAL "ARMCLANG") AND (NOT ${COMPILER} STREQUAL "GNUARM"))
21 message(FATAL_ERROR "ERROR: Compiler \"${COMPILER}\" is not supported.")
22endif()
23
Edison Aicb0ecf62019-07-10 18:43:51 +080024if(CORE_IPC)
25 if (TFM_LVL EQUAL 3)
26 message(FATAL_ERROR "ERROR: Invalid isolation level!")
27 endif()
28else()
29 if(NOT TFM_LVL EQUAL 1)
30 message(FATAL_ERROR "ERROR: Invalid isolation level!")
31 endif()
32endif()
33
David Vincze4638b2a2019-05-24 10:14:23 +020034#BL2 bootloader (MCUBoot) related settings
David Vincze54d05552019-08-05 12:58:47 +020035include(${CMAKE_CURRENT_LIST_DIR}/bl2/ext/mcuboot/MCUBootConfig.cmake)
David Vincze4638b2a2019-05-24 10:14:23 +020036
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010037set(BUILD_CMSIS_CORE Off)
38set(BUILD_RETARGET Off)
39set(BUILD_NATIVE_DRIVERS Off)
40set(BUILD_TIME Off)
41set(BUILD_STARTUP Off)
42set(BUILD_TARGET_CFG Off)
43set(BUILD_TARGET_HARDWARE_KEYS Off)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010044set(BUILD_TARGET_NV_COUNTERS Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010045set(BUILD_CMSIS_DRIVERS Off)
46set(BUILD_UART_STDOUT Off)
47set(BUILD_FLASH Off)
Tamas Ban3681ce02018-11-22 15:19:24 +000048set(BUILD_BOOT_SEED Off)
Tamas Ban38e17312018-11-22 15:26:35 +000049set(BUILD_DEVICE_ID Off)
Mate Toth-Pald3c77662019-02-20 16:23:00 +010050set(BUILD_PLAT_TEST Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010051if(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()
58
Mate Toth-Palee551bc2018-06-12 16:40:45 +020059if(${COMPILER} STREQUAL "ARMCLANG")
Mate Toth-Pal76867262018-03-09 13:15:36 +010060 #Use any ARMCLANG version found on PATH. Note: Only versions supported by the
61 #build system will work. A file cmake/Common/CompilerArmClangXY.cmake
62 #must be present with a matching version.
63 include("Common/FindArmClang")
64 include("Common/${ARMCLANG_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010065
Antonio de Angelis3302f452019-07-19 10:36:33 +010066 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -mcmse -ffunction-sections -fdata-sections)
Tamas Bandb69d522018-03-01 10:04:41 +000067 ##Shared compiler settings.
68 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010069 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 +000070 endfunction()
71
72 ##Shared linker settings.
73 function(config_setting_shared_linker_flags tgt)
Antonio de Angelis3302f452019-07-19 10:36:33 +010074 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 +010075 endfunction()
76elseif(${COMPILER} STREQUAL "GNUARM")
77 #Use any GNUARM version found on PATH. Note: Only versions supported by the
78 #build system will work. A file cmake/Common/CompilerGNUARMXY.cmake
79 #must be present with a matching version.
80 include("Common/FindGNUARM")
81 include("Common/${GNUARM_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010082
Antonio de Angelis3302f452019-07-19 10:36:33 +010083 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -mcmse -ffunction-sections -fdata-sections --specs=nano.specs)
Mate Toth-Pal76867262018-03-09 13:15:36 +010084 ##Shared compiler and linker settings.
Tamas Bandb69d522018-03-01 10:04:41 +000085 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010086 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 +000087 endfunction()
88
89 ##Shared linker settings.
90 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010091 #--no-wchar-size-warning flag is added because TF-M sources are compiled
92 #with short wchars, however the standard library is compiled with normal
93 #wchar, and this generates linker time warnings. TF-M code does not use
94 #wchar, so the warning can be suppressed.
Antonio de Angelis3302f452019-07-19 10:36:33 +010095 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 +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)
Jamie Foxadf02552019-05-16 17:44:52 +0100106set (TFM_PARTITION_TEST_CORE_IPC OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100107set (CORE_TEST_POSITIVE OFF)
108set (CORE_TEST_INTERACTIVE 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)
Miklos Balintf13ec022018-04-06 17:21:22 +0200116
Jamie Foxc78c62c2019-05-23 13:42:17 +0100117option(TFM_PARTITION_AUDIT_LOG "Enable the TF-M Audit Log partition" ON)
Mingyang Sun9511e5e2019-05-29 18:18:44 +0800118option(TFM_PARTITION_PLATFORM "Enable the TF-M Platform partition" ON)
Jamie Foxc78c62c2019-05-23 13:42:17 +0100119
Marton Berke6fd21f12019-07-02 13:43:07 +0200120if(${TARGET_PLATFORM} STREQUAL "AN521" OR ${TARGET_PLATFORM} STREQUAL "AN519" OR ${TARGET_PLATFORM} STREQUAL "AN539")
Miklos Balintf13ec022018-04-06 17:21:22 +0200121 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)
David Huf2cfa122019-08-27 15:32:38 +0800133
134 # Disable IPC Test by default if the config or platform doesn't explicitly
135 # require it
136 if (NOT DEFINED IPC_TEST)
137 set(IPC_TEST OFF)
138 endif()
139else()
140 set(IPC_TEST OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800141endif()
142
Miklos Balint87da2512018-04-19 13:45:50 +0200143if (TFM_PSA_API)
144 add_definitions(-DTFM_PSA_API)
145endif()
146
147if (TFM_LEGACY_API)
148 add_definitions(-DTFM_LEGACY_API)
149endif()
150
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100151if (SERVICES_TEST_ENABLED)
152 set(SERVICE_TEST_S ON)
153 set(SERVICE_TEST_NS ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100154endif()
155
156if (CORE_TEST)
Mate Toth-Pal6569a592019-06-07 12:09:50 +0200157 set(CORE_TEST_POSITIVE ON)
158 set(CORE_TEST_INTERACTIVE OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100159endif()
160
Ben Davis6d7256b2018-04-18 14:16:53 +0100161if (CORE_TEST_INTERACTIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100162 add_definitions(-DCORE_TEST_INTERACTIVE)
163 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100164 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100165endif()
166
Ben Davis6d7256b2018-04-18 14:16:53 +0100167if (CORE_TEST_POSITIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100168 add_definitions(-DCORE_TEST_POSITIVE)
169 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100170 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100171endif()
172
David Hu33f2fd22019-08-16 15:32:39 +0800173if (TFM_PARTITION_TEST_CORE)
174 # If the platform or the topology doesn't specify whether IRQ test is
175 # supported, enable it by default.
176 if (NOT DEFINED TFM_ENABLE_IRQ_TEST)
177 set(TFM_ENABLE_IRQ_TEST ON)
178 endif()
179
180 if (TFM_ENABLE_IRQ_TEST)
181 add_definitions(-DTFM_ENABLE_IRQ_TEST)
182 endif()
183else()
184 set(TFM_ENABLE_IRQ_TEST OFF)
185endif()
186
David Huf2cfa122019-08-27 15:32:38 +0800187if (IPC_TEST)
188 add_definitions(-DENABLE_IPC_TEST)
Jamie Foxadf02552019-05-16 17:44:52 +0100189 set(TEST_FRAMEWORK_NS ON)
190 set(TFM_PARTITION_TEST_CORE_IPC ON)
Edison Aiec109cd2018-07-17 16:04:14 +0800191endif()
192
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100193if (SERVICE_TEST_S)
194 add_definitions(-DSERVICES_TEST_S)
195 set(TEST_FRAMEWORK_S ON)
196endif()
197
198if (SERVICE_TEST_NS)
199 add_definitions(-DSERVICES_TEST_NS)
200 set(TEST_FRAMEWORK_NS ON)
201endif()
202
Ben Davis6d7256b2018-04-18 14:16:53 +0100203if (TEST_FRAMEWORK_S)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100204 add_definitions(-DTEST_FRAMEWORK_S)
Jamie Fox56da0992019-05-28 14:35:06 +0100205 # The secure client partition is required to run secure tests
206 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100207endif()
208
Ben Davis6d7256b2018-04-18 14:16:53 +0100209if (TEST_FRAMEWORK_NS)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100210 add_definitions(-DTEST_FRAMEWORK_NS)
211endif()
212
Jamie Foxc78c62c2019-05-23 13:42:17 +0100213if (CORE_IPC)
214 set(TFM_PARTITION_AUDIT_LOG OFF)
Mingyang Sun9511e5e2019-05-29 18:18:44 +0800215 set(TFM_PARTITION_PLATFORM OFF)
Jamie Foxc78c62c2019-05-23 13:42:17 +0100216endif()
217
218if (TFM_PARTITION_AUDIT_LOG)
219 add_definitions(-DTFM_PARTITION_AUDIT_LOG)
220endif()
221
Mingyang Sun9511e5e2019-05-29 18:18:44 +0800222if (TFM_PARTITION_PLATFORM)
223 add_definitions(-DTFM_PARTITION_PLATFORM)
224endif()
225
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100226if (TFM_PARTITION_TEST_CORE)
227 add_definitions(-DTFM_PARTITION_TEST_CORE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100228endif()
229
Jamie Foxadf02552019-05-16 17:44:52 +0100230if (TFM_PARTITION_TEST_CORE_IPC)
231 add_definitions(-DTFM_PARTITION_TEST_CORE_IPC)
232endif()
233
Jamie Foxc78c62c2019-05-23 13:42:17 +0100234if (TFM_PARTITION_TEST_SECURE_SERVICES)
235 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
236endif()
237
Jamie Fox17c30bb2019-01-10 13:39:33 +0000238if (PSA_API_TEST)
239 add_definitions(-DPSA_API_TEST_NS)
240 set(PSA_API_TEST_NS ON)
241 if (NOT DEFINED PSA_API_TEST_CRYPTO)
242 set(PSA_API_TEST_CRYPTO OFF)
243 endif()
244 if (NOT DEFINED PSA_API_TEST_SECURE_STORAGE)
245 set(PSA_API_TEST_SECURE_STORAGE OFF)
246 endif()
247 if (NOT DEFINED PSA_API_TEST_ATTESTATION)
248 set(PSA_API_TEST_ATTESTATION OFF)
249 endif()
250endif()
251
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100252# This flag indicates if the non-secure OS is capable of identify the non-secure clients
253# which call the secure services
254if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
255 set (TFM_NS_CLIENT_IDENTIFICATION ON)
256endif()
257
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100258if (BL2)
David Vincze63eda7a2019-08-09 17:42:51 +0200259 # Add MCUBOOT_IMAGE_NUMBER definition to the compiler command line.
260 add_definitions(-DMCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER})
261
David Vincze4638b2a2019-05-24 10:14:23 +0200262 if (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP")
Tamas Bandb69d522018-03-01 10:04:41 +0000263 set(LINK_TO_BOTH_MEMORY_REGION ON)
264 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100265endif()
266
Jamie Foxdaade492019-04-26 14:35:39 +0100267##Set Mbed TLS compiler flags and variables for audit log and crypto
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100268set(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 +0100269
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000270#Default TF-M secure storage flags.
271#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
Marc Moreno Berenguef6a64f72018-07-26 17:33:38 +0100272#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 +0000273if (NOT DEFINED SST_ENCRYPTION)
274 set (SST_ENCRYPTION ON)
275endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000276
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000277if (NOT DEFINED SST_ROLLBACK_PROTECTION)
278 set (SST_ROLLBACK_PROTECTION OFF)
279endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000280
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000281if (NOT DEFINED SST_CREATE_FLASH_LAYOUT)
282 set (SST_CREATE_FLASH_LAYOUT OFF)
283endif()
Marc Moreno Berengue184d2032018-08-14 12:51:43 +0100284
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000285if (NOT DEFINED SST_VALIDATE_METADATA_FROM_FLASH)
286 set (SST_VALIDATE_METADATA_FROM_FLASH ON)
287endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000288
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000289if (NOT DEFINED SST_RAM_FS)
290 if (REGRESSION)
291 set (SST_RAM_FS ON)
292 else()
293 set (SST_RAM_FS OFF)
Marc Moreno Berengue02a23442018-08-15 14:28:45 +0100294 endif()
Marc Moreno Berengue792fc682018-02-20 11:53:30 +0000295endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000296
Jamie Fox95bacd42019-03-21 18:14:15 +0000297if (NOT DEFINED SST_TEST_NV_COUNTERS)
298 if (REGRESSION AND (TFM_LVL EQUAL 1))
299 set(SST_TEST_NV_COUNTERS ON)
300 else()
301 set(SST_TEST_NV_COUNTERS OFF)
302 endif()
303endif()
304
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000305if (NOT DEFINED MBEDTLS_DEBUG)
Jamie Fox287885f2018-10-24 14:09:34 +0100306 set(MBEDTLS_DEBUG OFF)
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000307endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100308
Tamas Bandb69d522018-03-01 10:04:41 +0000309##Set mbedTLS compiler flags for BL2 bootloader
Mate Toth-Pal76867262018-03-09 13:15:36 +0100310set(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 +0100311if (MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072")
312 string(APPEND MBEDTLS_C_FLAGS_BL2 " -DMCUBOOT_SIGN_RSA_LEN=3072")
Jamie Foxc78c62c2019-05-23 13:42:17 +0100313endif()