Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 8 | cmake_minimum_required(VERSION 3.15) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 9 | |
| 10 | project("Bootloader" VERSION 0.1.0 LANGUAGES C ASM) |
| 11 | |
| 12 | add_executable(bl2 |
| 13 | src/security_cnt.c |
| 14 | src/flash_map.c |
| 15 | ) |
| 16 | |
| 17 | add_subdirectory(ext/mcuboot) |
| 18 | |
| 19 | set_target_properties(bl2 |
| 20 | PROPERTIES |
| 21 | SUFFIX ".axf" |
| 22 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" |
| 23 | ) |
| 24 | |
| 25 | target_include_directories(bl2 |
| 26 | PRIVATE |
| 27 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 28 | ) |
| 29 | |
| 30 | target_link_libraries(bl2 |
| 31 | PRIVATE |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 32 | tfm_boot_status |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | target_link_options(bl2 |
| 36 | PRIVATE |
| 37 | $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/bl2.map> |
| 38 | $<$<C_COMPILER_ID:ARMClang>:--map> |
TTornblom | af19ae9 | 2020-09-29 13:26:29 +0200 | [diff] [blame] | 39 | $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/bl2.map> |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | add_convert_to_bin_target(bl2) |
| 43 | |
| 44 | ############################### BOOT HAL # ##################################### |
| 45 | |
| 46 | add_library(bl2_hal INTERFACE) |
| 47 | |
| 48 | target_include_directories(bl2_hal |
| 49 | INTERFACE |
| 50 | include |
| 51 | ) |
| 52 | |
| 53 | ############################### MBEDCRYPTO ##################################### |
| 54 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 55 | add_library(bl2_mbedcrypto_config INTERFACE) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 56 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 57 | target_compile_definitions(bl2_mbedcrypto_config |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 58 | INTERFACE |
| 59 | $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA> |
| 60 | $<$<STREQUAL:${MCUBOOT_SIGNATURE_TYPE},RSA>:MCUBOOT_SIGN_RSA_LEN=${MCUBOOT_SIGNATURE_KEY_LEN}> |
Balint Matyi | 69e2d2e | 2020-07-08 10:53:54 +0100 | [diff] [blame] | 61 | MBEDTLS_CONFIG_FILE="$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ext/mcuboot/include/mcuboot-mbedtls-cfg.h>" |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 62 | # Workaround for https://github.com/ARMmbed/mbedtls/issues/1077 |
| 63 | $<$<OR:$<STREQUAL:${CMAKE_SYSTEM_ARCHITECTURE},armv8-m.base>,$<STREQUAL:${CMAKE_SYSTEM_ARCHITECTURE},armv6-m>>:MULADDC_CANNOT_USE_R7> |
| 64 | ) |
| 65 | |
| 66 | cmake_policy(SET CMP0079 NEW) |
| 67 | |
| 68 | set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) |
| 69 | set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) |
| 70 | set(ENABLE_TESTING OFF) |
| 71 | set(ENABLE_PROGRAMS OFF) |
| 72 | set(MBEDTLS_FATAL_WARNINGS OFF) |
| 73 | set(ENABLE_DOCS OFF) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 74 | set(INSTALL_MBEDTLS_HEADERS OFF) |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 75 | set(LIB_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto/install) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 76 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 77 | set(lib_target bl2_mbedcrypto_libs) |
| 78 | set(mbedcrypto_target bl2_mbedcrypto) |
| 79 | set(mbedtls_target bl2_mbedtls) |
| 80 | set(mbedx509_target bl2_mbedx509) |
| 81 | set(MBEDTLS_TARGET_PREFIX bl2_) |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 82 | |
| 83 | # Mbedcrypto is quite a large lib, and it uses too much memory for it to be |
| 84 | # reasonable to build it in debug info. As a compromise, if `debug` build type |
| 85 | # is selected mbedcrypto will build under `relwithdebinfo` which preserved debug |
| 86 | # symbols whild optimizing space. |
| 87 | set(SAVED_BUILD_TYPE ${CMAKE_BUILD_TYPE}) |
| 88 | set(CMAKE_BUILD_TYPE ${MBEDCRYPTO_BUILD_TYPE}) |
| 89 | add_subdirectory(${MBEDCRYPTO_PATH} ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto) |
| 90 | set(CMAKE_BUILD_TYPE ${SAVED_BUILD_TYPE} CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE) |
| 91 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 92 | if(NOT TARGET bl2_mbedcrypto) |
| 93 | message(FATAL_ERROR "Target bl2_mbedcrypto does not exist. Have the patches in ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH} ? |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 94 | Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") |
| 95 | endif() |
| 96 | |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 97 | target_link_libraries(bl2_mbedcrypto |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 98 | PUBLIC |
Raef Coles | e82831b | 2020-10-13 16:52:52 +0100 | [diff] [blame] | 99 | bl2_mbedcrypto_config |
Raef Coles | 8efad88 | 2020-07-10 09:46:00 +0100 | [diff] [blame] | 100 | ) |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 101 | |
| 102 | ############################### CODE SHARING ################################### |
| 103 | |
| 104 | if (TFM_CODE_SHARING) |
| 105 | compiler_create_shared_code(bl2 ${CMAKE_CURRENT_SOURCE_DIR}/src/shared_symbol_template.txt) |
Tamas Ban | 4a5cc97 | 2020-10-27 09:03:56 +0000 | [diff] [blame] | 106 | |
| 107 | if (NOT EXISTS ${MBEDCRYPTO_PATH}/library/code_share.c) |
| 108 | message(FATAL_ERROR "File ${MBEDCRYPTO_PATH}/library/code_share.c does not exist. |
| 109 | Have the patch ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/0005-Enable-crypto-code-sharing-between-independent-binar.patch |
| 110 | been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH}? |
| 111 | Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`") |
| 112 | endif() |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 113 | endif() |