Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | cmake_minimum_required(VERSION 3.15) |
| 8 | |
| 9 | # This CMake script is prepard by TF-M for building the non-secure side |
| 10 | # application and not used in secure build a tree being for export only. |
| 11 | # This file is renamed to spe/CMakeList.txt during installation phase |
| 12 | |
| 13 | include(spe_config) |
| 14 | include(spe_export) |
| 15 | |
| 16 | set_target_properties(tfm_config psa_interface PROPERTIES IMPORTED_GLOBAL True) |
| 17 | target_link_libraries(tfm_config INTERFACE psa_interface) |
| 18 | |
David Hu | b27a663 | 2023-10-23 22:38:39 +0800 | [diff] [blame] | 19 | # In actual NS integration, NS side build should include the source files |
| 20 | # exported by TF-M build. |
| 21 | set(INTERFACE_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/interface/src) |
| 22 | set(INTERFACE_INC_DIR ${CMAKE_CURRENT_LIST_DIR}/interface/include) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 23 | |
David Hu | b27a663 | 2023-10-23 22:38:39 +0800 | [diff] [blame] | 24 | add_library(tfm_api_ns STATIC) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 25 | |
| 26 | target_sources(tfm_api_ns |
| 27 | PRIVATE |
David Hu | b27a663 | 2023-10-23 22:38:39 +0800 | [diff] [blame] | 28 | $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_api.c> |
| 29 | $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_api.c> |
| 30 | $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_api.c> |
| 31 | $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_api.c> |
| 32 | $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_attest_api.c> |
| 33 | $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_fwu_api.c> |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 34 | ) |
| 35 | |
David Hu | b27a663 | 2023-10-23 22:38:39 +0800 | [diff] [blame] | 36 | target_sources(tfm_api_ns |
| 37 | PRIVATE |
| 38 | $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c> |
| 39 | $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c> |
| 40 | $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c> |
| 41 | ) |
| 42 | |
| 43 | # Include interface headers exported by TF-M |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 44 | target_include_directories(tfm_api_ns |
| 45 | PUBLIC |
David Hu | b27a663 | 2023-10-23 22:38:39 +0800 | [diff] [blame] | 46 | ${INTERFACE_INC_DIR} |
| 47 | ${INTERFACE_INC_DIR}/crypto_keys |
| 48 | $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:${INTERFACE_INC_DIR}/multi_core> |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 49 | ) |
| 50 | |
David Hu | 35aa1a5 | 2023-10-24 23:04:04 +0800 | [diff] [blame] | 51 | add_library(platform_region_defs INTERFACE) |
| 52 | |
| 53 | target_compile_definitions(platform_region_defs |
| 54 | INTERFACE |
| 55 | $<$<BOOL:${BL1}>:BL1> |
| 56 | $<$<BOOL:${BL2}>:BL2> |
| 57 | BL2_HEADER_SIZE=${BL2_HEADER_SIZE} |
| 58 | BL2_TRAILER_SIZE=${BL2_TRAILER_SIZE} |
| 59 | BL1_HEADER_SIZE=${BL1_HEADER_SIZE} |
| 60 | BL1_TRAILER_SIZE=${BL1_TRAILER_SIZE} |
| 61 | $<$<BOOL:${MCUBOOT_IMAGE_NUMBER}>:MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}> |
| 62 | $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_${TEST_PSA_API}> |
| 63 | $<$<OR:$<CONFIG:Debug>,$<CONFIG:relwithdebinfo>>:ENABLE_HEAP> |
| 64 | ) |
| 65 | |
| 66 | target_link_libraries(platform_region_defs |
| 67 | INTERFACE |
| 68 | tfm_config |
| 69 | ) |
| 70 | |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 71 | add_subdirectory(platform) |
| 72 | |
David Hu | b27a663 | 2023-10-23 22:38:39 +0800 | [diff] [blame] | 73 | target_sources(platform_ns |
| 74 | PRIVATE |
| 75 | $<$<BOOL:${PLATFORM_DEFAULT_UART_STDOUT}>:${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/common/uart_stdout.c> |
| 76 | ) |
| 77 | |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 78 | target_link_libraries(tfm_api_ns |
| 79 | PUBLIC |
David Hu | 35aa1a5 | 2023-10-24 23:04:04 +0800 | [diff] [blame] | 80 | platform_region_defs |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 81 | $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${CMAKE_CURRENT_SOURCE_DIR}/interface/lib/s_veneers.o> |
David Hu | 35aa1a5 | 2023-10-24 23:04:04 +0800 | [diff] [blame] | 82 | PRIVATE |
| 83 | platform_ns |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 84 | ) |
| 85 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 86 | if(BL2 AND PLATFORM_DEFAULT_IMAGE_SIGNING) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 87 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 88 | if (MCUBOOT_IMAGE_NUMBER GREATER 1) |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 89 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 90 | add_custom_target(tfm_app_binaries |
| 91 | DEPENDS tfm_ns_binaries |
| 92 | DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,> |
| 93 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 94 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 95 | #Sign non-secure binary image with provided secret key |
| 96 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py |
| 97 | --version ${MCUBOOT_IMAGE_VERSION_NS} |
| 98 | --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o |
| 99 | --key ${MCUBOOT_KEY_NS} |
| 100 | --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash> |
| 101 | --align ${MCUBOOT_ALIGN_VAL} |
| 102 | --pad |
| 103 | --pad-header |
| 104 | -H ${BL2_HEADER_SIZE} |
| 105 | -s ${MCUBOOT_SECURITY_COUNTER_NS} |
| 106 | -L ${MCUBOOT_ENC_KEY_LEN} |
| 107 | -d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\" |
| 108 | ${CMAKE_BINARY_DIR}/bin/tfm_ns.bin |
| 109 | $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only> |
| 110 | $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm> |
| 111 | $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}> |
| 112 | $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record> |
| 113 | ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 114 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 115 | # Create concatenated binary image from the two independently signed |
| 116 | # binary file. This only uses the local assemble.py script (not from |
| 117 | # upstream mcuboot) because that script is geared towards zephyr |
| 118 | # support |
| 119 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py |
| 120 | --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o |
| 121 | --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin |
| 122 | --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin |
| 123 | --output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin |
| 124 | # merge bootloader and application into Hex image for upload |
| 125 | COMMAND srec_cat ${CMAKE_CURRENT_SOURCE_DIR}/bin/bl2.bin -Binary -offset 0xA000000 |
| 126 | ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin -Binary -offset 0xA020000 |
| 127 | -o ${CMAKE_BINARY_DIR}/tfm.hex -Intel |
| 128 | ) |
| 129 | else() |
| 130 | add_custom_target(tfm_app_binaries |
| 131 | DEPENDS tfm_ns_binaries |
| 132 | DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,> |
| 133 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 134 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 135 | # concatenate S + NS binaries into tfm_s_ns.bin |
| 136 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py |
| 137 | --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o |
| 138 | --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin |
| 139 | --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns.bin |
| 140 | --output ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 141 | |
Dávid Házi | 34cf9b9 | 2023-10-11 11:10:41 +0200 | [diff] [blame] | 142 | # sign the combined tfm_s_ns.bin file |
| 143 | COMMAND ${Python3_EXECUTABLE} |
| 144 | ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py |
| 145 | --version ${MCUBOOT_IMAGE_VERSION_S} |
| 146 | --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o |
| 147 | --key ${MCUBOOT_KEY_S} |
| 148 | --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash> |
| 149 | --align ${MCUBOOT_ALIGN_VAL} |
| 150 | --pad |
| 151 | --pad-header |
| 152 | -H ${BL2_HEADER_SIZE} |
| 153 | -s ${MCUBOOT_SECURITY_COUNTER_S} |
| 154 | -L ${MCUBOOT_ENC_KEY_LEN} |
| 155 | $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only> |
| 156 | $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm> |
| 157 | $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}> |
| 158 | $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record> |
| 159 | ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin |
| 160 | ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin |
| 161 | ) |
| 162 | endif() |
Anton Komlev | aee4b61 | 2023-05-14 17:38:36 +0100 | [diff] [blame] | 163 | endif() |