#------------------------------------------------------------------------------- # Copyright (c) 2020-2023, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # #------------------------------------------------------------------------------- cmake_minimum_required(VERSION 3.15) project("Bootloader" VERSION 0.1.0 LANGUAGES C ASM) add_executable(bl2 src/flash_map.c $<$:src/security_cnt.c> $<$:src/default_flash_map.c> $<$:src/shared_data.c> $<$:src/provisioning.c> $<$:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c> ) add_subdirectory(ext/mcuboot) set_target_properties(bl2 PROPERTIES SUFFIX ".axf" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) target_include_directories(bl2 PRIVATE $ $ ) target_link_libraries(bl2 PRIVATE tfm_boot_status $<$:mcuboot_tests> platform_bl2 ) target_compile_options(bl2 PRIVATE ${BL2_COMPILER_CP_FLAG} ) target_link_options(bl2 PRIVATE $<$:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/bl2.map> $<$:--map;${BL2_LINKER_CP_OPTION}> $<$:--map\;${CMAKE_BINARY_DIR}/bin/bl2.map> ) target_compile_definitions(bl2 PRIVATE $<$:DEFAULT_MCUBOOT_FLASH_MAP> $<$:PLATFORM_PSA_ADAC_SECURE_DEBUG> $<$:TEST_BL2> $<$:TFM_PARTITION_FIRMWARE_UPDATE> $<$,$>>:TFM_MEASURED_BOOT_API> ) add_convert_to_bin_target(bl2) ############################### BOOT HAL # ##################################### add_library(bl2_hal INTERFACE) target_include_directories(bl2_hal INTERFACE include ) ############################### MBEDCRYPTO ##################################### add_library(bl2_mbedcrypto_config INTERFACE) if(NOT ${MCUBOOT_SIGNATURE_TYPE} STREQUAL "") string(REGEX MATCH "[0-9]*$" SIG_LEN ${MCUBOOT_SIGNATURE_TYPE}) string(REGEX MATCH "^[A-Z]*" SIG_TYPE ${MCUBOOT_SIGNATURE_TYPE}) endif() target_compile_definitions(bl2_mbedcrypto_config INTERFACE $<$:MCUBOOT_SIGN_RSA> $<$:MCUBOOT_SIGN_RSA_LEN=${SIG_LEN}> $<$:MCUBOOT_USE_PSA_CRYPTO> $<$:MCUBOOT_SIGN_EC${SIG_LEN}> MBEDTLS_CONFIG_FILE="${MCUBOOT_MBEDCRYPTO_CONFIG_FILEPATH}" # Workaround for https://github.com/ARMmbed/mbedtls/issues/1077 $<$,$>:MULADDC_CANNOT_USE_R7> $<$:CC312_LEGACY_DRIVER_API_ENABLED> ) cmake_policy(SET CMP0079 NEW) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) set(ENABLE_TESTING OFF) set(ENABLE_PROGRAMS OFF) set(MBEDTLS_FATAL_WARNINGS OFF) set(ENABLE_DOCS OFF) set(INSTALL_MBEDTLS_HEADERS OFF) set(LIB_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto/install) set(GEN_FILES OFF) # Set the prefix to be used by mbedTLS targets set(MBEDTLS_TARGET_PREFIX bl2_) # Mbedcrypto is quite a large lib, and it uses too much memory for it to be # reasonable to build it in debug info. As a compromise, if `debug` build type # is selected mbedcrypto will build under `relwithdebinfo` which preserved debug # symbols whild optimizing space. set(SAVED_BUILD_TYPE ${CMAKE_BUILD_TYPE}) set(CMAKE_BUILD_TYPE ${MBEDCRYPTO_BUILD_TYPE}) add_subdirectory(${MBEDCRYPTO_PATH} ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto EXCLUDE_FROM_ALL) set(CMAKE_BUILD_TYPE ${SAVED_BUILD_TYPE} CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE) if(NOT TARGET ${MBEDTLS_TARGET_PREFIX}mbedcrypto) message(FATAL_ERROR "Target ${MBEDTLS_TARGET_PREFIX}mbedcrypto does not exist. Have the patches in ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH} ? Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") endif() target_link_libraries(${MBEDTLS_TARGET_PREFIX}mbedcrypto PUBLIC bl2_mbedcrypto_config ) target_include_directories(${MBEDTLS_TARGET_PREFIX}mbedcrypto PUBLIC ${MBEDCRYPTO_PATH}/library ) target_compile_options(bl2_mbedcrypto PRIVATE ${BL2_COMPILER_CP_FLAG} ) target_compile_options(bl2_mbedtls PRIVATE ${BL2_COMPILER_CP_FLAG} ) target_compile_options(bl2_mbedx509 PRIVATE ${BL2_COMPILER_CP_FLAG} ) ############################### CODE SHARING ################################### if (TFM_CODE_SHARING) target_share_symbols(bl2 ${CMAKE_CURRENT_SOURCE_DIR}/bl2_shared_symbols.txt) if (NOT EXISTS ${MBEDCRYPTO_PATH}/library/code_share.c) message(FATAL_ERROR "File ${MBEDCRYPTO_PATH}/library/code_share.c does not exist. Have the patch ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/0005-Enable-crypto-code-sharing-between-independent-binar.patch been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH}? Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") endif() endif()