#------------------------------------------------------------------------------- # Copyright (c) 2020-2023, Arm Limited. All rights reserved. # Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) # or an affiliate of Cypress Semiconductor Corporation. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # #------------------------------------------------------------------------------- cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0079 NEW) add_subdirectory(ns) add_library(platform_s STATIC) add_library(platform_region_defs INTERFACE) add_library(platform_common_interface INTERFACE) if (BL2) add_library(platform_bl2 STATIC) endif() if (BL1 AND PLATFORM_DEFAULT_BL1) add_library(platform_bl1 STATIC) add_library(platform_bl1_interface INTERFACE) endif() if (TFM_PARTITION_CRYPTO) add_library(platform_crypto_keys STATIC) endif() set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR}) add_subdirectory(ext/target/${TFM_PLATFORM} target) #====================== CMSIS stack override interface ========================# # NS linker scripts using the default CMSIS style naming conventions, while the # secure and bl2 linker scripts remain untouched (region.h compatibility). # To be compatible with the untouched files (which using ARMCLANG naming style), # we have to override __INITIAL_SP and __STACK_LIMIT labels. set(CMSIS_OVERRIDE_HEADER "${CMAKE_CURRENT_LIST_DIR}/include/cmsis_override.h") add_library(cmsis_stack_override INTERFACE) target_compile_options(cmsis_stack_override INTERFACE "$<$:SHELL:-include ${CMSIS_OVERRIDE_HEADER}>" "$<$:SHELL:--preinclude ${CMSIS_OVERRIDE_HEADER}>" ) #========================= Platform Common interface ==========================# target_include_directories(platform_common_interface INTERFACE ./ext ./ext/cmsis ./ext/common ./ext/driver ./include ) #========================= Platform Secure ====================================# target_include_directories(platform_s PUBLIC $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/accelerator/interface> ) target_sources(platform_s PRIVATE $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/tfm_hal_ps.c> $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/tfm_hal_its.c> $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/tfm_hal_reset_halt.c> $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/uart_stdout.c> $<$:ext/common/tfm_hal_spm_logdev_peripheral.c> $<$:ext/common/exception_info.c> $<$:ext/common/template/attest_hal.c> $<$:ext/common/template/nv_counters.c> $<$:ext/common/template/tfm_rotpk.c> $<$:ext/common/template/crypto_nv_seed.c> $<$>,$>:ext/common/template/tfm_initial_attest_pub_key.c> $<$,$>,$>:ext/common/template/flash_otp_nv_counters_backend.c> $<$:ext/common/template/otp_flash.c> $<$:ext/common/provisioning.c> $<$,$>:${CMAKE_SOURCE_DIR}/platform/ext/common/test_interrupt.c> ) # If this is not added to the tfm_s it will not correctly override the weak # default handlers declared in assemebly, and will instead be discarded as they # are not in use. target_sources(tfm_s PRIVATE ext/common/faults.c ) target_link_libraries(platform_s PUBLIC platform_common_interface platform_region_defs tfm_fih_headers cmsis_stack_override PRIVATE psa_interface tfm_partition_defs tfm_spm_defs # For tfm_spm_log.h $<$:platform_crypto_keys> $<$:tfm_sprt> $<$:crypto_service_mbedcrypto> $<$:tfm_attestation_defs> $<$>:tfm_fih> ) target_compile_definitions(platform_s PUBLIC TFM_SPM_LOG_LEVEL=${TFM_SPM_LOG_LEVEL} $<$:TFM_SPM_LOG_RAW_ENABLED> $<$:OTP_NV_COUNTERS_RAM_EMULATION> $<$:TFM_EXCEPTION_INFO_DUMP> $<$,$>:CONFIG_TFM_ENABLE_MEMORY_PROTECT> $<$:TFM_PXN_ENABLE> $<$:CONFIG_TFM_FLOAT_ABI=2> $<$:CONFIG_TFM_FLOAT_ABI=0> $<$:CONFIG_TFM_LAZY_STACKING> $<$:CONFIG_TFM_ENABLE_CP10CP11> $<$:PLATFORM_DEFAULT_CRYPTO_KEYS> $<$:PLATFORM_DEFAULT_OTP> PRIVATE $<$:SYMMETRIC_INITIAL_ATTESTATION> $<$:TFM_DUMMY_PROVISIONING> $<$:PLATFORM_DEFAULT_NV_COUNTERS> $<$:OTP_WRITEABLE> ) target_compile_options(platform_s PUBLIC ${COMPILER_CP_FLAG} ) #========================= Platform Crypto Keys ===============================# if(TFM_PARTITION_CRYPTO) target_sources(platform_crypto_keys PRIVATE $<$:ext/common/template/crypto_keys.c> ) target_link_libraries(platform_crypto_keys PRIVATE crypto_service_mbedcrypto tfm_psa_rot_partition_crypto platform_region_defs tfm_partition_defs ) target_include_directories(platform_crypto_keys PRIVATE $<$:${CMAKE_SOURCE_DIR}/interface/include/crypto_keys> ${CMAKE_BINARY_DIR}/generated/interface/include ) target_compile_definitions(platform_crypto_keys PRIVATE MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER $<$:SYMMETRIC_INITIAL_ATTESTATION> $<$:PLATFORM_DEFAULT_OTP> $<$:TEST_S_ATTESTATION> $<$:TEST_NS_ATTESTATION> ) target_compile_options(platform_crypto_keys PUBLIC ${COMPILER_CP_FLAG} ) endif() #========================= Platform BL2 =======================================# if(BL2) #TODO import policy target_include_directories(platform_bl2 PUBLIC $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/accelerator/interface> ${MCUBOOT_PATH}/boot/bootutil/include ${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/include ) target_sources(platform_bl2 PRIVATE ext/common/boot_hal_bl2.c $<$:${CMAKE_CURRENT_SOURCE_DIR}/ext/common/uart_stdout.c> $<$:ext/common/template/nv_counters.c> $<$:ext/common/template/tfm_rotpk.c> $<$,$>,$>:ext/common/template/flash_otp_nv_counters_backend.c> $<$:ext/common/template/otp_flash.c> ) target_link_libraries(platform_bl2 PUBLIC platform_common_interface platform_region_defs cmsis_stack_override PRIVATE bl2_hal mcuboot_config ) target_compile_definitions(platform_bl2 PUBLIC BL2 MCUBOOT_${MCUBOOT_UPGRADE_STRATEGY} $<$:MCUBOOT_DIRECT_XIP_REVERT> $<$:SYMMETRIC_INITIAL_ATTESTATION> $<$:MCUBOOT_HW_KEY> MCUBOOT_FIH_PROFILE_${MCUBOOT_FIH_PROFILE} $<$:PLATFORM_DEFAULT_OTP> $<$:OTP_NV_COUNTERS_RAM_EMULATION> $<$:TFM_DUMMY_PROVISIONING> $<$:PLATFORM_DEFAULT_NV_COUNTERS> $<$:OTP_WRITEABLE> ) target_compile_options(platform_bl2 PUBLIC ${BL2_COMPILER_CP_FLAG} ) endif() #========================= Platform BL1_1 =====================================# if(BL1 AND PLATFORM_DEFAULT_BL1) target_include_directories(platform_bl1_interface INTERFACE . ./include ./ext/cmsis ./ext/driver ) target_link_libraries(platform_bl1_interface INTERFACE platform_region_defs platform_common_interface cmsis_stack_override ) target_compile_definitions(platform_bl1_interface INTERFACE $<$:CRYPTO_HW_ACCELERATOR> $<$:TFM_BL1_LOGGING> $<$:PLATFORM_DEFAULT_OTP> $<$:OTP_NV_COUNTERS_RAM_EMULATION> $<$:TFM_DUMMY_PROVISIONING> $<$:PLATFORM_DEFAULT_NV_COUNTERS> $<$:OTP_WRITEABLE> $<$:TFM_BL1_MEMORY_MAPPED_FLASH> ) target_sources(platform_bl1 PRIVATE ./ext/common/boot_hal_bl1.c ./ext/common/uart_stdout.c $<$:ext/common/template/nv_counters.c> $<$,$>,$>:ext/common/template/flash_otp_nv_counters_backend.c> $<$:ext/common/template/otp_flash.c> ) target_link_libraries(platform_bl1 PUBLIC platform_bl1_interface PRIVATE tfm_fih tfm_fih_headers $<$:bl1_crypto_hw> tfm_boot_status ) endif() #========================= Platform region defs ===============================# #TODO maybe just link the other platforms to this target_compile_definitions(platform_region_defs INTERFACE $<$:BL1> $<$:BL2> BL2_HEADER_SIZE=${BL2_HEADER_SIZE} BL2_TRAILER_SIZE=${BL2_TRAILER_SIZE} BL1_HEADER_SIZE=${BL1_HEADER_SIZE} BL1_TRAILER_SIZE=${BL1_TRAILER_SIZE} $<$:PLATFORM_DEFAULT_BL1> $<$:SECURE_UART1> DAUTH_${DEBUG_AUTHENTICATION} $<$:MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}> $<$:MCUBOOT_SIGN_RSA> $<$:MCUBOOT_SIGN_RSA_LEN=${MCUBOOT_SIGNATURE_KEY_LEN}> $<$:LINK_TO_SECONDARY_PARTITION> $<$:PSA_API_TEST_${TEST_PSA_API}> $<$:CODE_SHARING> $<$,$>:ENABLE_HEAP> PLATFORM_NS_NV_COUNTERS=${TFM_NS_NV_COUNTER_AMOUNT} ) target_include_directories(platform_region_defs INTERFACE ${CMAKE_CURRENT_LIST_DIR}/ext/common ) target_link_libraries(platform_region_defs INTERFACE tfm_config )