1#------------------------------------------------------------------------------- 2# Copyright (c) 2020-2022, Arm Limited. All rights reserved. 3# Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) 4# or an affiliate of Cypress Semiconductor Corporation. All rights reserved. 5# 6# SPDX-License-Identifier: BSD-3-Clause 7# 8#------------------------------------------------------------------------------- 9cmake_minimum_required(VERSION 3.15) 10cmake_policy(SET CMP0076 NEW) 11cmake_policy(SET CMP0079 NEW) 12 13add_subdirectory(ns) 14 15add_library(platform_s STATIC) 16add_library(platform_region_defs INTERFACE) 17add_library(platform_common_interface INTERFACE) 18 19if (BL2) 20 add_library(platform_bl2 STATIC) 21endif() 22 23if (BL1 AND PLATFORM_DEFAULT_BL1) 24 add_library(platform_bl1 STATIC) 25 add_library(platform_bl1_interface INTERFACE) 26endif() 27 28if (TFM_PARTITION_CRYPTO) 29 add_library(platform_crypto_keys STATIC) 30endif() 31 32set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR}) 33 34add_subdirectory(ext/target/${TFM_PLATFORM} target) 35 36#====================== CMSIS stack override interface ========================# 37 38# NS linker scripts using the default CMSIS style naming conventions, while the 39# secure and bl2 linker scripts remain untouched (region.h compatibility). 40# To be compatible with the untouched files (which using ARMCLANG naming style), 41# we have to override __INITIAL_SP and __STACK_LIMIT labels. 42 43set(CMSIS_OVERRIDE_HEADER "${CMAKE_CURRENT_LIST_DIR}/include/cmsis_override.h") 44add_library(cmsis_stack_override INTERFACE) 45target_compile_options(cmsis_stack_override 46 INTERFACE 47 "$<$<C_COMPILER_ID:GNU>:SHELL:-include ${CMSIS_OVERRIDE_HEADER}>" 48 "$<$<C_COMPILER_ID:IAR>:SHELL:--preinclude ${CMSIS_OVERRIDE_HEADER}>" 49) 50 51#========================= Platform Common interface ==========================# 52 53target_include_directories(platform_common_interface 54 INTERFACE 55 ./ext 56 ./ext/cmsis 57 ./ext/common 58 ./ext/driver 59 ./include 60) 61 62#========================= Platform Secure ====================================# 63 64target_include_directories(platform_s 65 PUBLIC 66 $<$<BOOL:${CRYPTO_HW_ACCELERATOR}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/accelerator/interface> 67) 68 69target_sources(platform_s 70 PRIVATE 71 $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/tfm_hal_ps.c> 72 $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/tfm_hal_its.c> 73 $<$<BOOL:${PLATFORM_DEFAULT_SYSTEM_RESET_HALT}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/tfm_hal_reset_halt.c> 74 $<$<BOOL:${PLATFORM_DEFAULT_UART_STDOUT}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/uart_stdout.c> 75 $<$<BOOL:${TFM_SPM_LOG_RAW_ENABLED}>:ext/common/tfm_hal_spm_logdev_peripheral.c> 76 $<$<BOOL:${TFM_EXCEPTION_INFO_DUMP}>:ext/common/exception_info.c> 77 ext/common/tfm_hal_memory_symbols.c 78 $<$<BOOL:${PLATFORM_DEFAULT_ATTEST_HAL}>:ext/common/template/attest_hal.c> 79 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:ext/common/template/nv_counters.c> 80 $<$<BOOL:${PLATFORM_DEFAULT_ROTPK}>:ext/common/template/tfm_rotpk.c> 81 $<$<BOOL:${PLATFORM_DEFAULT_NV_SEED}>:ext/common/template/crypto_nv_seed.c> 82 $<$<AND:$<NOT:$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>>,$<BOOL:${TEST_S_ATTESTATION}>>:ext/common/template/tfm_initial_attest_pub_key.c> 83 $<$<OR:$<AND:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>,$<BOOL:${PLATFORM_DEFAULT_OTP}>>:ext/common/template/flash_otp_nv_counters_backend.c> 84 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/otp_flash.c> 85 $<$<BOOL:${PLATFORM_DEFAULT_PROVISIONING}>:ext/common/provisioning.c> 86 $<$<OR:$<BOOL:${TEST_S_FPU}>,$<BOOL:${TEST_NS_FPU}>>:${CMAKE_SOURCE_DIR}/platform/ext/common/test_interrupt.c> 87) 88 89# If this is not added to the tfm_s it will not correctly override the weak 90# default handlers declared in assemebly, and will instead be discarded as they 91# are not in use. 92target_sources(tfm_s 93 PRIVATE 94 ext/common/faults.c 95) 96 97target_link_libraries(platform_s 98 PUBLIC 99 platform_common_interface 100 platform_region_defs 101 tfm_fih_headers 102 cmsis_stack_override 103 PRIVATE 104 psa_interface 105 tfm_partition_defs 106 tfm_spm_defs # For tfm_spm_log.h 107 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:platform_crypto_keys> 108 $<$<BOOL:${PLATFORM_DEFAULT_ATTEST_HAL}>:tfm_sprt> 109 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:crypto_service_mbedcrypto> 110 $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:tfm_attestation_defs> 111 $<$<NOT:$<STREQUAL:${TFM_FIH_PROFILE},OFF>>:tfm_fih> 112) 113 114target_compile_definitions(platform_s 115 PUBLIC 116 TFM_SPM_LOG_LEVEL=${TFM_SPM_LOG_LEVEL} 117 $<$<BOOL:${TFM_SPM_LOG_RAW_ENABLED}>:TFM_SPM_LOG_RAW_ENABLED> 118 $<$<BOOL:${OTP_NV_COUNTERS_RAM_EMULATION}>:OTP_NV_COUNTERS_RAM_EMULATION> 119 $<$<BOOL:${TFM_EXCEPTION_INFO_DUMP}>:TFM_EXCEPTION_INFO_DUMP> 120 $<$<OR:$<VERSION_GREATER:${TFM_ISOLATION_LEVEL},1>,$<STREQUAL:"${TEST_PSA_API}","IPC">>:CONFIG_TFM_ENABLE_MEMORY_PROTECT> 121 $<$<AND:$<BOOL:${TFM_PXN_ENABLE}>,$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8.1-m.main>>:TFM_PXN_ENABLE> 122 $<$<STREQUAL:${CONFIG_TFM_FLOAT_ABI},hard>:CONFIG_TFM_FLOAT_ABI=2> 123 $<$<STREQUAL:${CONFIG_TFM_FLOAT_ABI},soft>:CONFIG_TFM_FLOAT_ABI=0> 124 $<$<BOOL:${CONFIG_TFM_LAZY_STACKING}>:CONFIG_TFM_LAZY_STACKING> 125 $<$<BOOL:${CONFIG_TFM_ENABLE_CP10CP11}>:CONFIG_TFM_ENABLE_CP10CP11> 126 $<$<BOOL:${PLATFORM_DEFAULT_CRYPTO_KEYS}>:PLATFORM_DEFAULT_CRYPTO_KEYS> 127 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:PLATFORM_DEFAULT_OTP> 128 PRIVATE 129 $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION> 130 $<$<BOOL:${TFM_DUMMY_PROVISIONING}>:TFM_DUMMY_PROVISIONING> 131 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:PLATFORM_DEFAULT_NV_COUNTERS> 132 $<$<BOOL:${PLATFORM_DEFAULT_OTP_WRITEABLE}>:OTP_WRITEABLE> 133) 134 135target_compile_options(platform_s 136 PUBLIC 137 ${COMPILER_CP_FLAG} 138) 139 140#========================= Platform Crypto Keys ===============================# 141 142 143if(TFM_PARTITION_CRYPTO) 144 target_sources(platform_crypto_keys 145 PRIVATE 146 $<$<BOOL:${PLATFORM_DEFAULT_CRYPTO_KEYS}>:ext/common/template/crypto_keys.c> 147 ) 148 149 target_link_libraries(platform_crypto_keys 150 PRIVATE 151 crypto_service_mbedcrypto 152 tfm_psa_rot_partition_crypto 153 platform_region_defs 154 tfm_partition_defs 155 ) 156 157 target_include_directories(platform_crypto_keys 158 PRIVATE 159 $<$<BOOL:${PLATFORM_DEFAULT_CRYPTO_KEYS}>:${CMAKE_SOURCE_DIR}/interface/include/crypto_keys> 160 ${CMAKE_BINARY_DIR}/generated/interface/include 161 ) 162 163 target_compile_definitions(platform_crypto_keys 164 PRIVATE 165 $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION> 166 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:PLATFORM_DEFAULT_OTP> 167 $<$<BOOL:${TEST_S_ATTESTATION}>:TEST_S_ATTESTATION> 168 $<$<BOOL:${TEST_NS_ATTESTATION}>:TEST_NS_ATTESTATION> 169 ) 170 171 target_compile_options(platform_crypto_keys 172 PUBLIC 173 ${COMPILER_CP_FLAG} 174 ) 175endif() 176 177#========================= Platform BL2 =======================================# 178if(BL2) 179 #TODO import policy 180 target_include_directories(platform_bl2 181 PUBLIC 182 $<$<BOOL:${CRYPTO_HW_ACCELERATOR}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/accelerator/interface> 183 ${MCUBOOT_PATH}/boot/bootutil/include 184 ${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/include 185 ) 186 187 target_sources(platform_bl2 188 PRIVATE 189 ext/common/boot_hal_bl2.c 190 $<$<BOOL:${PLATFORM_DEFAULT_UART_STDOUT}>:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/uart_stdout.c> 191 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:ext/common/template/nv_counters.c> 192 $<$<BOOL:${PLATFORM_DEFAULT_ROTPK}>:ext/common/template/tfm_rotpk.c> 193 $<$<OR:$<AND:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>,$<BOOL:${PLATFORM_DEFAULT_OTP}>>:ext/common/template/flash_otp_nv_counters_backend.c> 194 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/otp_flash.c> 195 ) 196 197 target_link_libraries(platform_bl2 198 PUBLIC 199 platform_common_interface 200 platform_region_defs 201 cmsis_stack_override 202 PRIVATE 203 bl2_hal 204 mcuboot_config 205 ) 206 207 target_compile_definitions(platform_bl2 208 PUBLIC 209 BL2 210 MCUBOOT_${MCUBOOT_UPGRADE_STRATEGY} 211 $<$<BOOL:${MCUBOOT_DIRECT_XIP_REVERT}>:MCUBOOT_DIRECT_XIP_REVERT> 212 $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION> 213 $<$<BOOL:${MCUBOOT_HW_KEY}>:MCUBOOT_HW_KEY> 214 MCUBOOT_FIH_PROFILE_${MCUBOOT_FIH_PROFILE} 215 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:PLATFORM_DEFAULT_OTP> 216 $<$<BOOL:${OTP_NV_COUNTERS_RAM_EMULATION}>:OTP_NV_COUNTERS_RAM_EMULATION> 217 $<$<BOOL:${TFM_DUMMY_PROVISIONING}>:TFM_DUMMY_PROVISIONING> 218 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:PLATFORM_DEFAULT_NV_COUNTERS> 219 $<$<BOOL:${PLATFORM_DEFAULT_OTP_WRITEABLE}>:OTP_WRITEABLE> 220 ) 221 222endif() 223 224#========================= Platform BL1_1 =====================================# 225 226if(BL1 AND PLATFORM_DEFAULT_BL1) 227 target_include_directories(platform_bl1_interface 228 INTERFACE 229 . 230 ./include 231 ./ext/cmsis 232 ./ext/driver 233 ) 234 235 target_link_libraries(platform_bl1_interface 236 INTERFACE 237 platform_region_defs 238 platform_common_interface 239 cmsis_stack_override 240 ) 241 242 target_compile_definitions(platform_bl1_interface 243 INTERFACE 244 $<$<BOOL:${CRYPTO_HW_ACCELERATOR}>:CRYPTO_HW_ACCELERATOR> 245 $<$<BOOL:${TFM_BL1_LOGGING}>:TFM_BL1_LOGGING> 246 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:PLATFORM_DEFAULT_OTP> 247 $<$<BOOL:${OTP_NV_COUNTERS_RAM_EMULATION}>:OTP_NV_COUNTERS_RAM_EMULATION> 248 $<$<BOOL:${TFM_DUMMY_PROVISIONING}>:TFM_DUMMY_PROVISIONING> 249 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:PLATFORM_DEFAULT_NV_COUNTERS> 250 $<$<BOOL:${PLATFORM_DEFAULT_OTP_WRITEABLE}>:OTP_WRITEABLE> 251 ) 252 253 target_sources(platform_bl1 254 PRIVATE 255 ./ext/common/boot_hal_bl1.c 256 ./ext/common/uart_stdout.c 257 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:ext/common/template/nv_counters.c> 258 $<$<OR:$<AND:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>,$<BOOL:${PLATFORM_DEFAULT_OTP}>>:ext/common/template/flash_otp_nv_counters_backend.c> 259 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/otp_flash.c> 260 ) 261 262 target_link_libraries(platform_bl1 263 PUBLIC 264 platform_bl1_interface 265 PRIVATE 266 tfm_fih 267 tfm_fih_headers 268 $<$<BOOL:${CRYPTO_HW_ACCELERATOR}>:bl1_crypto_hw> 269 tfm_boot_status 270 ) 271 272endif() 273 274#========================= Platform region defs ===============================# 275 276#TODO maybe just link the other platforms to this 277target_compile_definitions(platform_region_defs 278 INTERFACE 279 $<$<BOOL:${BL1}>:BL1> 280 $<$<BOOL:${BL2}>:BL2> 281 BL2_HEADER_SIZE=${BL2_HEADER_SIZE} 282 BL2_TRAILER_SIZE=${BL2_TRAILER_SIZE} 283 BL1_HEADER_SIZE=${BL1_HEADER_SIZE} 284 BL1_TRAILER_SIZE=${BL1_TRAILER_SIZE} 285 $<$<BOOL:${PLATFORM_DEFAULT_BL1}>:PLATFORM_DEFAULT_BL1> 286 $<$<BOOL:${SECURE_UART1}>:SECURE_UART1> 287 DAUTH_${DEBUG_AUTHENTICATION} 288 $<$<BOOL:${MCUBOOT_IMAGE_NUMBER}>:MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}> 289 $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA> 290 $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA_LEN=${MCUBOOT_SIGNATURE_KEY_LEN}> 291 $<$<STREQUAL:${MCUBOOT_EXECUTION_SLOT},2>:LINK_TO_SECONDARY_PARTITION> 292 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_${TEST_PSA_API}> 293 $<$<BOOL:${TFM_CODE_SHARING}>:CODE_SHARING> 294 $<$<OR:$<CONFIG:Debug>,$<CONFIG:relwithdebinfo>>:ENABLE_HEAP> 295 PLATFORM_NS_NV_COUNTERS=${TFM_NS_NV_COUNTER_AMOUNT} 296) 297 298target_include_directories(platform_region_defs 299 INTERFACE 300 ${CMAKE_CURRENT_LIST_DIR}/ext/common 301) 302