blob: 9815d94fae0257672019e31c4204d658d69b72d5 [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")
12elseif(NOT DEFINED BL2)
13 message(FATAL_ERROR "ERROR: Incomplete Configuration: BL2 not defined, Include this file from a Config*.cmake")
Tamas Band90c81b2018-08-15 15:03:42 +010014elseif(NOT DEFINED TFM_LVL)
15 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 +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
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010024set(BUILD_CMSIS_CORE Off)
25set(BUILD_RETARGET Off)
26set(BUILD_NATIVE_DRIVERS Off)
27set(BUILD_TIME Off)
28set(BUILD_STARTUP Off)
29set(BUILD_TARGET_CFG Off)
30set(BUILD_TARGET_HARDWARE_KEYS Off)
Marc Moreno Berengue4cc81fc2018-08-10 14:32:01 +010031set(BUILD_TARGET_NV_COUNTERS Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010032set(BUILD_CMSIS_DRIVERS Off)
33set(BUILD_UART_STDOUT Off)
34set(BUILD_FLASH Off)
Tamas Ban3681ce02018-11-22 15:19:24 +000035set(BUILD_BOOT_SEED Off)
Tamas Ban38e17312018-11-22 15:26:35 +000036set(BUILD_DEVICE_ID Off)
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010037if(NOT DEFINED PLATFORM_CMAKE_FILE)
38 message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
39elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
40 message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
41else()
42 include(${PLATFORM_CMAKE_FILE})
43endif()
44
Oliver Swede21440442018-07-10 09:31:32 +010045if (NOT DEFINED IMAGE_VERSION)
Jamie Fox7a4170d2018-08-15 14:13:42 +010046 set(IMAGE_VERSION 0.0.0+0)
Oliver Swede21440442018-07-10 09:31:32 +010047endif()
48
Mate Toth-Palee551bc2018-06-12 16:40:45 +020049if(${COMPILER} STREQUAL "ARMCLANG")
Mate Toth-Pal76867262018-03-09 13:15:36 +010050 #Use any ARMCLANG version found on PATH. Note: Only versions supported by the
51 #build system will work. A file cmake/Common/CompilerArmClangXY.cmake
52 #must be present with a matching version.
53 include("Common/FindArmClang")
54 include("Common/${ARMCLANG_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010055
Mate Toth-Pal76867262018-03-09 13:15:36 +010056 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -mcmse)
Tamas Bandb69d522018-03-01 10:04:41 +000057 ##Shared compiler settings.
58 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010059 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 +000060 endfunction()
61
62 ##Shared linker settings.
63 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010064 embedded_set_target_link_flags(TARGET ${tgt} FLAGS --strict --map --symbols --xref --entry=Reset_Handler --info=summarysizes,sizes,totals,unused,veneers)
65 endfunction()
66elseif(${COMPILER} STREQUAL "GNUARM")
67 #Use any GNUARM version found on PATH. Note: Only versions supported by the
68 #build system will work. A file cmake/Common/CompilerGNUARMXY.cmake
69 #must be present with a matching version.
70 include("Common/FindGNUARM")
71 include("Common/${GNUARM_MODULE}")
Mate Toth-Pal48fc6a02018-01-24 09:50:14 +010072
Mate Toth-Palf64f1eb2018-04-26 17:22:37 +020073 set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -mcmse --specs=nano.specs)
Mate Toth-Pal76867262018-03-09 13:15:36 +010074 ##Shared compiler and linker settings.
Tamas Bandb69d522018-03-01 10:04:41 +000075 function(config_setting_shared_compiler_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010076 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 +000077 endfunction()
78
79 ##Shared linker settings.
80 function(config_setting_shared_linker_flags tgt)
Mate Toth-Pal76867262018-03-09 13:15:36 +010081 #--no-wchar-size-warning flag is added because TF-M sources are compiled
82 #with short wchars, however the standard library is compiled with normal
83 #wchar, and this generates linker time warnings. TF-M code does not use
84 #wchar, so the warning can be suppressed.
Karl Zhangb3b9d952018-08-07 21:47:11 +080085 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
86 -Wl,--print-memory-usage)
Mate Toth-Pal76867262018-03-09 13:15:36 +010087 endfunction()
Mate Toth-Pal76867262018-03-09 13:15:36 +010088endif()
89
90#Create a string from the compile flags list, so that it can be used later
91#in this file to set mbedtls and BL2 flags
Tamas Bandb69d522018-03-01 10:04:41 +000092list_to_string(COMMON_COMPILE_FLAGS_STR ${COMMON_COMPILE_FLAGS})
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010093
94#Settings which shall be set for all projects the same way based
95# on the variables above.
Mate Toth-Pal349714a2018-02-23 15:30:24 +010096set (TFM_PARTITION_TEST_CORE OFF)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +010097set (CORE_TEST_POSITIVE OFF)
98set (CORE_TEST_INTERACTIVE OFF)
Ben Davis6d7256b2018-04-18 14:16:53 +010099set (TEST_FRAMEWORK_S OFF)
Miklos Balintf13ec022018-04-06 17:21:22 +0200100set (REFERENCE_PLATFORM OFF)
Ben Davis6d7256b2018-04-18 14:16:53 +0100101set (TFM_PARTITION_TEST_SECURE_SERVICES OFF)
Tamas Band90c81b2018-08-15 15:03:42 +0100102set (SERVICES_TEST_ENABLED OFF)
Marc Moreno Berenguecae2c532018-10-09 12:58:46 +0100103set (TEST_FRAMEWORK_S OFF)
104set (TEST_FRAMEWORK_NS OFF)
Edison Aiec109cd2018-07-17 16:04:14 +0800105set (TFM_PSA_API OFF)
Miklos Balint87da2512018-04-19 13:45:50 +0200106set (TFM_LEGACY_API ON)
Edison Aiec109cd2018-07-17 16:04:14 +0800107set (CORE_TEST_IPC OFF)
Miklos Balintf13ec022018-04-06 17:21:22 +0200108
109if(${TARGET_PLATFORM} STREQUAL "AN521" OR ${TARGET_PLATFORM} STREQUAL "AN519")
110 set (REFERENCE_PLATFORM ON)
111endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100112
Miklos Balint6cbeba62018-04-12 17:31:34 +0200113# Option to demonstrate usage of secure-only peripheral
114set (SECURE_UART1 OFF)
115
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100116if (REGRESSION)
117 set(SERVICES_TEST_ENABLED ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100118endif()
119
Edison Aiec109cd2018-07-17 16:04:14 +0800120if (CORE_IPC)
121 set(TFM_PSA_API ON)
122 set(CORE_TEST_IPC ON)
123endif()
124
Miklos Balint87da2512018-04-19 13:45:50 +0200125if (TFM_PSA_API)
126 add_definitions(-DTFM_PSA_API)
127endif()
128
129if (TFM_LEGACY_API)
130 add_definitions(-DTFM_LEGACY_API)
131endif()
132
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100133if (SERVICES_TEST_ENABLED)
134 set(SERVICE_TEST_S ON)
135 set(SERVICE_TEST_NS ON)
Edison Ai699d58e2019-05-22 18:03:41 +0800136 if (REFERENCE_PLATFORM AND NOT CORE_IPC)
Miklos Balintf13ec022018-04-06 17:21:22 +0200137 set(CORE_TEST_POSITIVE ON)
138 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100139endif()
140
141if (CORE_TEST)
142 set(CORE_TEST_POSITIVE ON)
143 set(CORE_TEST_INTERACTIVE OFF)
Jamie Fox17c30bb2019-01-10 13:39:33 +0000144 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Tamas Ban244f08c2018-09-20 22:02:30 +0100145 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100146endif()
147
Ben Davis6d7256b2018-04-18 14:16:53 +0100148if (CORE_TEST_INTERACTIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100149 add_definitions(-DCORE_TEST_INTERACTIVE)
150 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100151 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100152endif()
153
Ben Davis6d7256b2018-04-18 14:16:53 +0100154if (CORE_TEST_POSITIVE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100155 add_definitions(-DCORE_TEST_POSITIVE)
156 set(TEST_FRAMEWORK_NS ON)
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100157 set(TFM_PARTITION_TEST_CORE ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100158endif()
159
Edison Aiec109cd2018-07-17 16:04:14 +0800160if (CORE_TEST_IPC)
161 add_definitions(-DCORE_TEST_IPC)
Edison Ai7d6cb3b2018-09-19 16:41:50 +0800162 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Antonio de Angelis4743e672019-04-11 11:38:48 +0100163 # If PSA_API_TEST is enabled, don't run TF-M test framework from NS
164 if (PSA_API_TEST)
165 set(TEST_FRAMEWORK_NS OFF)
166 else()
167 set(TEST_FRAMEWORK_NS ON)
168 endif()
Edison Aiec109cd2018-07-17 16:04:14 +0800169endif()
170
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100171if (SERVICE_TEST_S)
172 add_definitions(-DSERVICES_TEST_S)
173 set(TEST_FRAMEWORK_S ON)
Ben Davis6d7256b2018-04-18 14:16:53 +0100174 set(TFM_PARTITION_TEST_SECURE_SERVICES ON)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100175endif()
176
Edison Ai7d6cb3b2018-09-19 16:41:50 +0800177if (TFM_PARTITION_TEST_SECURE_SERVICES)
178 add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES)
179endif()
180
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100181if (SERVICE_TEST_NS)
182 add_definitions(-DSERVICES_TEST_NS)
183 set(TEST_FRAMEWORK_NS ON)
184endif()
185
Ben Davis6d7256b2018-04-18 14:16:53 +0100186if (TEST_FRAMEWORK_S)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100187 add_definitions(-DTEST_FRAMEWORK_S)
188endif()
189
Ben Davis6d7256b2018-04-18 14:16:53 +0100190if (TEST_FRAMEWORK_NS)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100191 add_definitions(-DTEST_FRAMEWORK_NS)
192endif()
193
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100194if (TFM_PARTITION_TEST_CORE)
195 add_definitions(-DTFM_PARTITION_TEST_CORE)
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100196endif()
197
Jamie Fox17c30bb2019-01-10 13:39:33 +0000198if (PSA_API_TEST)
199 add_definitions(-DPSA_API_TEST_NS)
200 set(PSA_API_TEST_NS ON)
201 if (NOT DEFINED PSA_API_TEST_CRYPTO)
202 set(PSA_API_TEST_CRYPTO OFF)
203 endif()
204 if (NOT DEFINED PSA_API_TEST_SECURE_STORAGE)
205 set(PSA_API_TEST_SECURE_STORAGE OFF)
206 endif()
207 if (NOT DEFINED PSA_API_TEST_ATTESTATION)
208 set(PSA_API_TEST_ATTESTATION OFF)
209 endif()
210endif()
211
Marc Moreno Berenguec2e4db82018-09-14 16:32:24 +0100212# This flag indicates if the non-secure OS is capable of identify the non-secure clients
213# which call the secure services
214if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
215 set (TFM_NS_CLIENT_IDENTIFICATION ON)
216endif()
217
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100218if (BL2)
219 add_definitions(-DBL2)
Tamas Bandb69d522018-03-01 10:04:41 +0000220 if (MCUBOOT_NO_SWAP)
221 set(LINK_TO_BOTH_MEMORY_REGION ON)
222 endif()
Oliver Swedef9982442018-08-24 18:37:44 +0100223 if (MCUBOOT_NO_SWAP AND MCUBOOT_RAM_LOADING)
224 message (FATAL_ERROR "Bootloader: MCUBOOT_RAM_LOADING and MCUBOOT_NO_SWAP are not supported together")
225 endif()
Tamas Bandb69d522018-03-01 10:04:41 +0000226else()
227 if (MCUBOOT_NO_SWAP)
228 message (FATAL_ERROR "Bootloader build is turned off, not possible to specify bootloader behavior")
229 endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100230endif()
231
Antonio de Angelis8908f472018-08-31 15:44:25 +0100232##Set mbedTLS compiler flags and variables for secure storage, audit log and crypto
233set(MBEDTLS_C_FLAGS_SERVICES "-D__ARM_FEATURE_CMSE=3 -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -DMBEDTLS_CONFIG_FILE=\\\\\\\"tfm_mbedtls_config.h\\\\\\\" -I${CMAKE_CURRENT_LIST_DIR}/platform/ext/common")
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100234
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000235#Default TF-M secure storage flags.
236#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
Marc Moreno Berenguef6a64f72018-07-26 17:33:38 +0100237#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 +0000238if (NOT DEFINED SST_ENCRYPTION)
239 set (SST_ENCRYPTION ON)
240endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000241
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000242if (NOT DEFINED SST_ROLLBACK_PROTECTION)
243 set (SST_ROLLBACK_PROTECTION OFF)
244endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000245
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000246if (NOT DEFINED SST_CREATE_FLASH_LAYOUT)
247 set (SST_CREATE_FLASH_LAYOUT OFF)
248endif()
Marc Moreno Berengue184d2032018-08-14 12:51:43 +0100249
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000250if (NOT DEFINED SST_VALIDATE_METADATA_FROM_FLASH)
251 set (SST_VALIDATE_METADATA_FROM_FLASH ON)
252endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000253
Marc Moreno Berengue8385e8e2019-01-21 11:49:50 +0000254if (NOT DEFINED SST_RAM_FS)
255 if (REGRESSION)
256 set (SST_RAM_FS ON)
257 else()
258 set (SST_RAM_FS OFF)
Marc Moreno Berengue02a23442018-08-15 14:28:45 +0100259 endif()
Marc Moreno Berengue792fc682018-02-20 11:53:30 +0000260endif()
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000261
Jamie Fox95bacd42019-03-21 18:14:15 +0000262if (NOT DEFINED SST_TEST_NV_COUNTERS)
263 if (REGRESSION AND (TFM_LVL EQUAL 1))
264 set(SST_TEST_NV_COUNTERS ON)
265 else()
266 set(SST_TEST_NV_COUNTERS OFF)
267 endif()
268endif()
269
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000270if (NOT DEFINED MBEDTLS_DEBUG)
Jamie Fox287885f2018-10-24 14:09:34 +0100271 set(MBEDTLS_DEBUG OFF)
Marc Moreno Berengue6ffb22f2018-02-20 13:46:30 +0000272endif()
Mate Toth-Pal65c935e2018-01-17 18:42:13 +0100273
Tamas Bandb69d522018-03-01 10:04:41 +0000274##Set mbedTLS compiler flags for BL2 bootloader
Mate Toth-Pal76867262018-03-09 13:15:36 +0100275set(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")