blob: 3402ba3885f58fa4e73187b418c2e79acfa74ff0 [file] [log] [blame]
Anton Komlevaee4b612023-05-14 17:38:36 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2023, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7cmake_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
13include(spe_config)
14include(spe_export)
15
16set_target_properties(tfm_config psa_interface PROPERTIES IMPORTED_GLOBAL True)
17target_link_libraries(tfm_config INTERFACE psa_interface)
18
19add_library(tfm_api_ns)
20
21file(GLOB spe_sources "interface/src/*.c")
22
23target_sources(tfm_api_ns
24 PRIVATE
25 ${spe_sources}
26 # NS specific implementation of NS interface dispatcher
27 $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:interface/src/os_wrapper/tfm_ns_interface_rtos.c>
28)
29
30target_include_directories(tfm_api_ns
31 PUBLIC
32 interface/include
David Hu71f6dcc2023-10-18 11:52:21 +080033 interface/include/crypto_keys
Anton Komlevaee4b612023-05-14 17:38:36 +010034)
35
David Hu35aa1a52023-10-24 23:04:04 +080036add_library(platform_region_defs INTERFACE)
37
38target_compile_definitions(platform_region_defs
39 INTERFACE
40 $<$<BOOL:${BL1}>:BL1>
41 $<$<BOOL:${BL2}>:BL2>
42 BL2_HEADER_SIZE=${BL2_HEADER_SIZE}
43 BL2_TRAILER_SIZE=${BL2_TRAILER_SIZE}
44 BL1_HEADER_SIZE=${BL1_HEADER_SIZE}
45 BL1_TRAILER_SIZE=${BL1_TRAILER_SIZE}
46 $<$<BOOL:${MCUBOOT_IMAGE_NUMBER}>:MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}>
47 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_${TEST_PSA_API}>
48 $<$<OR:$<CONFIG:Debug>,$<CONFIG:relwithdebinfo>>:ENABLE_HEAP>
49)
50
51target_link_libraries(platform_region_defs
52 INTERFACE
53 tfm_config
54)
55
Anton Komlevaee4b612023-05-14 17:38:36 +010056add_subdirectory(platform)
57
58target_link_libraries(tfm_api_ns
59 PUBLIC
David Hu35aa1a52023-10-24 23:04:04 +080060 platform_region_defs
Anton Komlevaee4b612023-05-14 17:38:36 +010061 $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${CMAKE_CURRENT_SOURCE_DIR}/interface/lib/s_veneers.o>
David Hu35aa1a52023-10-24 23:04:04 +080062 PRIVATE
63 platform_ns
Anton Komlevaee4b612023-05-14 17:38:36 +010064)
65
Dávid Házi34cf9b92023-10-11 11:10:41 +020066if(BL2 AND PLATFORM_DEFAULT_IMAGE_SIGNING)
Anton Komlevaee4b612023-05-14 17:38:36 +010067
Dávid Házi34cf9b92023-10-11 11:10:41 +020068 if (MCUBOOT_IMAGE_NUMBER GREATER 1)
Anton Komlevaee4b612023-05-14 17:38:36 +010069
Dávid Házi34cf9b92023-10-11 11:10:41 +020070 add_custom_target(tfm_app_binaries
71 DEPENDS tfm_ns_binaries
72 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
73 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +010074
Dávid Házi34cf9b92023-10-11 11:10:41 +020075 #Sign non-secure binary image with provided secret key
76 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
77 --version ${MCUBOOT_IMAGE_VERSION_NS}
78 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
79 --key ${MCUBOOT_KEY_NS}
80 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
81 --align ${MCUBOOT_ALIGN_VAL}
82 --pad
83 --pad-header
84 -H ${BL2_HEADER_SIZE}
85 -s ${MCUBOOT_SECURITY_COUNTER_NS}
86 -L ${MCUBOOT_ENC_KEY_LEN}
87 -d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\"
88 ${CMAKE_BINARY_DIR}/bin/tfm_ns.bin
89 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
90 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
91 $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}>
92 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
93 ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
Anton Komlevaee4b612023-05-14 17:38:36 +010094
Dávid Házi34cf9b92023-10-11 11:10:41 +020095 # Create concatenated binary image from the two independently signed
96 # binary file. This only uses the local assemble.py script (not from
97 # upstream mcuboot) because that script is geared towards zephyr
98 # support
99 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
100 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
101 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
102 --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
103 --output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
104 # merge bootloader and application into Hex image for upload
105 COMMAND srec_cat ${CMAKE_CURRENT_SOURCE_DIR}/bin/bl2.bin -Binary -offset 0xA000000
106 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin -Binary -offset 0xA020000
107 -o ${CMAKE_BINARY_DIR}/tfm.hex -Intel
108 )
109 else()
110 add_custom_target(tfm_app_binaries
111 DEPENDS tfm_ns_binaries
112 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
113 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100114
Dávid Házi34cf9b92023-10-11 11:10:41 +0200115 # concatenate S + NS binaries into tfm_s_ns.bin
116 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
117 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
118 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
119 --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns.bin
120 --output ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
Anton Komlevaee4b612023-05-14 17:38:36 +0100121
Dávid Házi34cf9b92023-10-11 11:10:41 +0200122 # sign the combined tfm_s_ns.bin file
123 COMMAND ${Python3_EXECUTABLE}
124 ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
125 --version ${MCUBOOT_IMAGE_VERSION_S}
126 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
127 --key ${MCUBOOT_KEY_S}
128 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
129 --align ${MCUBOOT_ALIGN_VAL}
130 --pad
131 --pad-header
132 -H ${BL2_HEADER_SIZE}
133 -s ${MCUBOOT_SECURITY_COUNTER_S}
134 -L ${MCUBOOT_ENC_KEY_LEN}
135 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
136 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
137 $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}>
138 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
139 ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
140 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
141 )
142 endif()
Anton Komlevaee4b612023-05-14 17:38:36 +0100143endif()