Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | if(NOT DEFINED REGRESSION) |
| 9 | message(FATAL_ERROR "ERROR: Incomplete Configuration: REGRESSION not defined, Include this file from a Config*.cmake") |
| 10 | elseif(NOT DEFINED CORE_TEST) |
| 11 | message(FATAL_ERROR "ERROR: Incomplete Configuration: CORE_TEST not defined, Include this file from a Config*.cmake") |
| 12 | elseif(NOT DEFINED BL2) |
| 13 | message(FATAL_ERROR "ERROR: Incomplete Configuration: BL2 not defined, Include this file from a Config*.cmake") |
Tamas Ban | d90c81b | 2018-08-15 15:03:42 +0100 | [diff] [blame] | 14 | elseif(NOT DEFINED TFM_LVL) |
| 15 | message(FATAL_ERROR "ERROR: Incomplete Configuration: TFM_LVL not defined, Include this file from a Config*.cmake") |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 16 | endif() |
| 17 | |
Mate Toth-Pal | ee551bc | 2018-06-12 16:40:45 +0200 | [diff] [blame] | 18 | if(NOT DEFINED COMPILER) |
| 19 | message(FATAL_ERROR "ERROR: COMPILER is not set in command line") |
| 20 | elseif((NOT ${COMPILER} STREQUAL "ARMCLANG") AND (NOT ${COMPILER} STREQUAL "GNUARM")) |
| 21 | message(FATAL_ERROR "ERROR: Compiler \"${COMPILER}\" is not supported.") |
| 22 | endif() |
| 23 | |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 24 | set(BUILD_CMSIS_CORE Off) |
| 25 | set(BUILD_RETARGET Off) |
| 26 | set(BUILD_NATIVE_DRIVERS Off) |
| 27 | set(BUILD_TIME Off) |
| 28 | set(BUILD_STARTUP Off) |
| 29 | set(BUILD_TARGET_CFG Off) |
| 30 | set(BUILD_TARGET_HARDWARE_KEYS Off) |
Marc Moreno Berengue | 4cc81fc | 2018-08-10 14:32:01 +0100 | [diff] [blame] | 31 | set(BUILD_TARGET_NV_COUNTERS Off) |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 32 | set(BUILD_CMSIS_DRIVERS Off) |
| 33 | set(BUILD_UART_STDOUT Off) |
| 34 | set(BUILD_FLASH Off) |
| 35 | if(NOT DEFINED PLATFORM_CMAKE_FILE) |
| 36 | message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.") |
| 37 | elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE}) |
| 38 | message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.") |
| 39 | else() |
| 40 | include(${PLATFORM_CMAKE_FILE}) |
| 41 | endif() |
| 42 | |
Oliver Swede | 2144044 | 2018-07-10 09:31:32 +0100 | [diff] [blame] | 43 | if (NOT DEFINED IMAGE_VERSION) |
| 44 | set(IMAGE_VERSION 0.0.0+0) |
| 45 | endif() |
| 46 | |
Mate Toth-Pal | ee551bc | 2018-06-12 16:40:45 +0200 | [diff] [blame] | 47 | if(${COMPILER} STREQUAL "ARMCLANG") |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 48 | #Use any ARMCLANG version found on PATH. Note: Only versions supported by the |
| 49 | #build system will work. A file cmake/Common/CompilerArmClangXY.cmake |
| 50 | #must be present with a matching version. |
| 51 | include("Common/FindArmClang") |
| 52 | include("Common/${ARMCLANG_MODULE}") |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 53 | |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 54 | set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -mfpu=none -mcmse) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 55 | ##Shared compiler settings. |
| 56 | function(config_setting_shared_compiler_flags tgt) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 57 | embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C FLAGS -xc -std=c99 ${COMMON_COMPILE_FLAGS} -Wall -Werror) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 58 | endfunction() |
| 59 | |
| 60 | ##Shared linker settings. |
| 61 | function(config_setting_shared_linker_flags tgt) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 62 | embedded_set_target_link_flags(TARGET ${tgt} FLAGS --strict --map --symbols --xref --entry=Reset_Handler --info=summarysizes,sizes,totals,unused,veneers) |
| 63 | endfunction() |
| 64 | elseif(${COMPILER} STREQUAL "GNUARM") |
| 65 | #Use any GNUARM version found on PATH. Note: Only versions supported by the |
| 66 | #build system will work. A file cmake/Common/CompilerGNUARMXY.cmake |
| 67 | #must be present with a matching version. |
| 68 | include("Common/FindGNUARM") |
| 69 | include("Common/${GNUARM_MODULE}") |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 70 | |
Mate Toth-Pal | f64f1eb | 2018-04-26 17:22:37 +0200 | [diff] [blame] | 71 | set (COMMON_COMPILE_FLAGS -fshort-enums -fshort-wchar -funsigned-char -msoft-float -mcmse --specs=nano.specs) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 72 | ##Shared compiler and linker settings. |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 73 | function(config_setting_shared_compiler_flags tgt) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 74 | 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 Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 75 | endfunction() |
| 76 | |
| 77 | ##Shared linker settings. |
| 78 | function(config_setting_shared_linker_flags tgt) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 79 | #--no-wchar-size-warning flag is added because TF-M sources are compiled |
| 80 | #with short wchars, however the standard library is compiled with normal |
| 81 | #wchar, and this generates linker time warnings. TF-M code does not use |
| 82 | #wchar, so the warning can be suppressed. |
Mate Toth-Pal | f64f1eb | 2018-04-26 17:22:37 +0200 | [diff] [blame] | 83 | 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) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 84 | endfunction() |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 85 | endif() |
| 86 | |
| 87 | #Create a string from the compile flags list, so that it can be used later |
| 88 | #in this file to set mbedtls and BL2 flags |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 89 | list_to_string(COMMON_COMPILE_FLAGS_STR ${COMMON_COMPILE_FLAGS}) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 90 | |
| 91 | #Settings which shall be set for all projects the same way based |
| 92 | # on the variables above. |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 93 | set (TFM_PARTITION_TEST_CORE OFF) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 94 | set (CORE_TEST_POSITIVE OFF) |
| 95 | set (CORE_TEST_INTERACTIVE OFF) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 96 | set (TFM_PARTITION_TEST_SST OFF) |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 97 | set (TEST_FRAMEWORK_S OFF) |
Miklos Balint | f13ec02 | 2018-04-06 17:21:22 +0200 | [diff] [blame] | 98 | set (REFERENCE_PLATFORM OFF) |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 99 | set (TFM_PARTITION_TEST_SECURE_SERVICES OFF) |
Tamas Ban | d90c81b | 2018-08-15 15:03:42 +0100 | [diff] [blame] | 100 | set (SERVICES_TEST_ENABLED OFF) |
Miklos Balint | f13ec02 | 2018-04-06 17:21:22 +0200 | [diff] [blame] | 101 | |
| 102 | if(${TARGET_PLATFORM} STREQUAL "AN521" OR ${TARGET_PLATFORM} STREQUAL "AN519") |
| 103 | set (REFERENCE_PLATFORM ON) |
Avinash Mehta | 788036c | 2018-03-15 12:38:43 +0000 | [diff] [blame] | 104 | elseif(${TARGET_PLATFORM} STREQUAL "MUSCA_A") |
| 105 | add_definitions(-DTARGET_MUSCA_A) |
Miklos Balint | f13ec02 | 2018-04-06 17:21:22 +0200 | [diff] [blame] | 106 | endif() |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 107 | |
Miklos Balint | 6cbeba6 | 2018-04-12 17:31:34 +0200 | [diff] [blame] | 108 | # Option to demonstrate usage of secure-only peripheral |
| 109 | set (SECURE_UART1 OFF) |
| 110 | |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 111 | if (REGRESSION) |
| 112 | set(SERVICES_TEST_ENABLED ON) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 113 | endif() |
| 114 | |
| 115 | if (SERVICES_TEST_ENABLED) |
| 116 | set(SERVICE_TEST_S ON) |
| 117 | set(SERVICE_TEST_NS ON) |
Miklos Balint | f13ec02 | 2018-04-06 17:21:22 +0200 | [diff] [blame] | 118 | if (REFERENCE_PLATFORM) |
| 119 | set(CORE_TEST_POSITIVE ON) |
| 120 | endif() |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 121 | endif() |
| 122 | |
| 123 | if (CORE_TEST) |
| 124 | set(CORE_TEST_POSITIVE ON) |
| 125 | set(CORE_TEST_INTERACTIVE OFF) |
| 126 | endif() |
| 127 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 128 | if (CORE_TEST_INTERACTIVE) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 129 | add_definitions(-DCORE_TEST_INTERACTIVE) |
| 130 | set(TEST_FRAMEWORK_NS ON) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 131 | set(TFM_PARTITION_TEST_CORE ON) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 132 | endif() |
| 133 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 134 | if (CORE_TEST_POSITIVE) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 135 | add_definitions(-DCORE_TEST_POSITIVE) |
| 136 | set(TEST_FRAMEWORK_NS ON) |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 137 | set(TFM_PARTITION_TEST_CORE ON) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 138 | endif() |
| 139 | |
| 140 | if (SERVICE_TEST_S) |
| 141 | add_definitions(-DSERVICES_TEST_S) |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 142 | add_definitions(-DTFM_PARTITION_TEST_SECURE_SERVICES) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 143 | set(TEST_FRAMEWORK_S ON) |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 144 | set(TFM_PARTITION_TEST_SECURE_SERVICES ON) |
Tamas Ban | d90c81b | 2018-08-15 15:03:42 +0100 | [diff] [blame] | 145 | set(TFM_PARTITION_TEST_SST ON) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 146 | endif() |
| 147 | |
| 148 | if (SERVICE_TEST_NS) |
| 149 | add_definitions(-DSERVICES_TEST_NS) |
| 150 | set(TEST_FRAMEWORK_NS ON) |
| 151 | endif() |
| 152 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 153 | if (TEST_FRAMEWORK_S) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 154 | add_definitions(-DTEST_FRAMEWORK_S) |
| 155 | endif() |
| 156 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 157 | if (TEST_FRAMEWORK_NS) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 158 | add_definitions(-DTEST_FRAMEWORK_NS) |
| 159 | endif() |
| 160 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 161 | if (TFM_PARTITION_TEST_CORE) |
| 162 | add_definitions(-DTFM_PARTITION_TEST_CORE) |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 163 | endif() |
| 164 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 165 | if (TFM_PARTITION_TEST_SST) |
| 166 | add_definitions(-DTFM_PARTITION_TEST_SST) |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 167 | endif() |
| 168 | |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 169 | if (BL2) |
| 170 | add_definitions(-DBL2) |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 171 | if (MCUBOOT_NO_SWAP) |
| 172 | set(LINK_TO_BOTH_MEMORY_REGION ON) |
| 173 | endif() |
Oliver Swede | f998244 | 2018-08-24 18:37:44 +0100 | [diff] [blame] | 174 | if (MCUBOOT_NO_SWAP AND MCUBOOT_RAM_LOADING) |
| 175 | message (FATAL_ERROR "Bootloader: MCUBOOT_RAM_LOADING and MCUBOOT_NO_SWAP are not supported together") |
| 176 | endif() |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 177 | else() |
| 178 | if (MCUBOOT_NO_SWAP) |
| 179 | message (FATAL_ERROR "Bootloader build is turned off, not possible to specify bootloader behavior") |
| 180 | endif() |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 181 | endif() |
| 182 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 183 | ##Set mbedTLS compiler flags and variables for secure storage and audit log |
| 184 | set(MBEDTLS_C_FLAGS_SST_LOG "-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-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 185 | |
Marc Moreno Berengue | 6ffb22f | 2018-02-20 13:46:30 +0000 | [diff] [blame] | 186 | #Default TF-M secure storage flags. |
| 187 | #These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake |
Marc Moreno Berengue | f6a64f7 | 2018-07-26 17:33:38 +0100 | [diff] [blame] | 188 | #Documentation about these flags can be found in docs/user_guides/services/tfm_sst_integration_guide.md |
Marc Moreno Berengue | 6ffb22f | 2018-02-20 13:46:30 +0000 | [diff] [blame] | 189 | if (NOT DEFINED ENABLE_SECURE_STORAGE) |
| 190 | set (ENABLE_SECURE_STORAGE ON) |
| 191 | |
| 192 | if (NOT DEFINED SST_ENCRYPTION) |
| 193 | set (SST_ENCRYPTION ON) |
| 194 | endif() |
| 195 | |
Marc Moreno Berengue | 184d203 | 2018-08-14 12:51:43 +0100 | [diff] [blame^] | 196 | if (NOT DEFINED SST_ROLLBACK_PROTECTION) |
| 197 | set (SST_ROLLBACK_PROTECTION OFF) |
| 198 | endif() |
| 199 | |
Marc Moreno Berengue | 95d6572 | 2018-07-26 17:24:02 +0100 | [diff] [blame] | 200 | if (NOT DEFINED SST_CREATE_FLASH_LAYOUT) |
| 201 | set (SST_CREATE_FLASH_LAYOUT OFF) |
Marc Moreno Berengue | 6ffb22f | 2018-02-20 13:46:30 +0000 | [diff] [blame] | 202 | endif() |
| 203 | |
| 204 | if (NOT DEFINED SST_VALIDATE_METADATA_FROM_FLASH) |
| 205 | set (SST_VALIDATE_METADATA_FROM_FLASH ON) |
| 206 | endif() |
Ben Davis | 38902c8 | 2018-05-01 15:36:31 +0100 | [diff] [blame] | 207 | |
| 208 | if (NOT DEFINED SST_ENABLE_PARTIAL_ASSET_RW) |
| 209 | set (SST_ENABLE_PARTIAL_ASSET_RW ON) |
| 210 | endif() |
Marc Moreno Berengue | 792fc68 | 2018-02-20 11:53:30 +0000 | [diff] [blame] | 211 | endif() |
Marc Moreno Berengue | 6ffb22f | 2018-02-20 13:46:30 +0000 | [diff] [blame] | 212 | |
| 213 | if (NOT DEFINED MBEDTLS_DEBUG) |
Mate Toth-Pal | f64f1eb | 2018-04-26 17:22:37 +0200 | [diff] [blame] | 214 | if (${COMPILER} STREQUAL "GNUARM" AND ${TARGET_PLATFORM} STREQUAL "MUSCA_A" AND BL2) |
| 215 | #The size of the MCUboot binary compiled with GCC exceeds the size limit on |
| 216 | #Musca A. By turning off the mbed TLS debug build is a good way to go below |
| 217 | #that limit, while it is still possible to debug TFM/bootloader code. |
| 218 | set (MBEDTLS_DEBUG OFF) |
| 219 | else () |
| 220 | set (MBEDTLS_DEBUG ON) |
| 221 | endif () |
Marc Moreno Berengue | 6ffb22f | 2018-02-20 13:46:30 +0000 | [diff] [blame] | 222 | endif() |
Mate Toth-Pal | 65c935e | 2018-01-17 18:42:13 +0100 | [diff] [blame] | 223 | |
Tamas Ban | db69d52 | 2018-03-01 10:04:41 +0000 | [diff] [blame] | 224 | ##Set mbedTLS compiler flags for BL2 bootloader |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame] | 225 | set(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") |