blob: 3f0fe4b963f2733b7924116eb1a9eaaaadfacfb8 [file] [log] [blame]
Anton Komlevaee4b612023-05-14 17:38:36 +01001#-------------------------------------------------------------------------------
Dávid Házi1a72fd42024-03-06 18:33:45 +01002# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
Anton Komlevaee4b612023-05-14 17:38:36 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
David Hu1249f0d2023-12-04 22:57:56 +08007cmake_minimum_required(VERSION 3.21)
Anton Komlevaee4b612023-05-14 17:38:36 +01008
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
Antonio de Angelis8bb98512024-01-16 14:13:36 +000016set_target_properties(tfm_config psa_interface psa_crypto_config PROPERTIES IMPORTED_GLOBAL True)
Anton Komlevaee4b612023-05-14 17:38:36 +010017target_link_libraries(tfm_config INTERFACE psa_interface)
18
David Hub27a6632023-10-23 22:38:39 +080019# In actual NS integration, NS side build should include the source files
20# exported by TF-M build.
21set(INTERFACE_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/interface/src)
22set(INTERFACE_INC_DIR ${CMAKE_CURRENT_LIST_DIR}/interface/include)
Anton Komlevaee4b612023-05-14 17:38:36 +010023
David Hub27a6632023-10-23 22:38:39 +080024add_library(tfm_api_ns STATIC)
Anton Komlevaee4b612023-05-14 17:38:36 +010025
26target_sources(tfm_api_ns
David Hu0a07b632023-10-16 15:25:20 +080027 PUBLIC
David Hub27a6632023-10-23 22:38:39 +080028 $<$<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 Komlevaee4b612023-05-14 17:38:36 +010034)
35
David Hub27a6632023-10-23 22:38:39 +080036# Include interface headers exported by TF-M
Anton Komlevaee4b612023-05-14 17:38:36 +010037target_include_directories(tfm_api_ns
38 PUBLIC
David Hub27a6632023-10-23 22:38:39 +080039 ${INTERFACE_INC_DIR}
40 ${INTERFACE_INC_DIR}/crypto_keys
Anton Komlevaee4b612023-05-14 17:38:36 +010041)
42
Jamie Foxc0489cc2023-11-28 17:55:36 +000043if (CONFIG_TFM_USE_TRUSTZONE)
44 add_library(tfm_api_ns_tz INTERFACE)
45
46 target_sources(tfm_api_ns_tz
47 INTERFACE
48 ${INTERFACE_SRC_DIR}/tfm_tz_psa_ns_api.c
49 )
50
51 target_link_libraries(tfm_api_ns_tz
52 INTERFACE
53 ${CMAKE_CURRENT_SOURCE_DIR}/interface/lib/s_veneers.o
54 )
55endif()
56
57if (TFM_PARTITION_NS_AGENT_MAILBOX)
58 add_library(tfm_api_ns_mailbox INTERFACE)
59
60 target_sources(tfm_api_ns_mailbox
61 INTERFACE
62 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
63 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
64 )
65
66 target_include_directories(tfm_api_ns_mailbox
67 INTERFACE
68 ${INTERFACE_INC_DIR}/multi_core
69 )
70endif()
71
Antonio de Angelis8bb98512024-01-16 14:13:36 +000072if (TFM_PARTITION_CRYPTO)
73 target_link_libraries(tfm_api_ns
74 PUBLIC
75 psa_crypto_config
76 )
77endif()
78
David Hu35aa1a52023-10-24 23:04:04 +080079add_library(platform_region_defs INTERFACE)
80
81target_compile_definitions(platform_region_defs
82 INTERFACE
83 $<$<BOOL:${BL1}>:BL1>
84 $<$<BOOL:${BL2}>:BL2>
85 BL2_HEADER_SIZE=${BL2_HEADER_SIZE}
86 BL2_TRAILER_SIZE=${BL2_TRAILER_SIZE}
87 BL1_HEADER_SIZE=${BL1_HEADER_SIZE}
88 BL1_TRAILER_SIZE=${BL1_TRAILER_SIZE}
89 $<$<BOOL:${MCUBOOT_IMAGE_NUMBER}>:MCUBOOT_IMAGE_NUMBER=${MCUBOOT_IMAGE_NUMBER}>
Dávid Házi78157732024-07-11 22:18:42 +020090 $<$<STREQUAL:${MCUBOOT_EXECUTION_SLOT},2>:LINK_TO_SECONDARY_PARTITION>
David Hu35aa1a52023-10-24 23:04:04 +080091 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_${TEST_PSA_API}>
92 $<$<OR:$<CONFIG:Debug>,$<CONFIG:relwithdebinfo>>:ENABLE_HEAP>
93)
94
95target_link_libraries(platform_region_defs
96 INTERFACE
97 tfm_config
98)
99
Anton Komlevaee4b612023-05-14 17:38:36 +0100100add_subdirectory(platform)
101
David Hub27a6632023-10-23 22:38:39 +0800102target_sources(platform_ns
103 PRIVATE
104 $<$<BOOL:${PLATFORM_DEFAULT_UART_STDOUT}>:${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/common/uart_stdout.c>
105)
106
Anton Komlev8dc9eb22023-09-15 15:53:03 +0100107target_compile_definitions(platform_ns
108 PUBLIC
Kevin Peng7dc0ebf2023-11-14 14:31:31 +0800109 DOMAIN_NS=1
Anton Komlev8dc9eb22023-09-15 15:53:03 +0100110 $<$<BOOL:${PLATFORM_DEFAULT_CRYPTO_KEYS}>:PLATFORM_DEFAULT_CRYPTO_KEYS>
111 $<$<STREQUAL:${CONFIG_TFM_FLOAT_ABI},hard>:CONFIG_TFM_FLOAT_ABI=2>
112 $<$<STREQUAL:${CONFIG_TFM_FLOAT_ABI},soft>:CONFIG_TFM_FLOAT_ABI=0>
Roman Mazurak0a79e672024-08-14 16:48:13 +0300113 $<$<BOOL:${CONFIG_TFM_DISABLE_CP10CP11}>:CONFIG_TFM_DISABLE_CP10CP11>
Anton Komlev8dc9eb22023-09-15 15:53:03 +0100114 $<$<BOOL:${CONFIG_TFM_ENABLE_CP10CP11}>:CONFIG_TFM_ENABLE_CP10CP11>
115)
116
Anton Komlevaee4b612023-05-14 17:38:36 +0100117target_link_libraries(tfm_api_ns
118 PUBLIC
David Hu35aa1a52023-10-24 23:04:04 +0800119 platform_region_defs
David Hu35aa1a52023-10-24 23:04:04 +0800120 platform_ns
Anton Komlevaee4b612023-05-14 17:38:36 +0100121)
122
Dávid Házi34cf9b92023-10-11 11:10:41 +0200123if(BL2 AND PLATFORM_DEFAULT_IMAGE_SIGNING)
Anton Komlevaee4b612023-05-14 17:38:36 +0100124
David Hua5fefdc2023-11-03 13:24:41 +0800125 find_package(Python3)
126
David Hua01be0a2023-10-25 23:08:10 +0800127 add_custom_target(tfm_s_ns_signed_bin
128 ALL
Dávid Házi1a72fd42024-03-06 18:33:45 +0100129 SOURCES ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800130 )
131
Dávid Házi34cf9b92023-10-11 11:10:41 +0200132 if (MCUBOOT_IMAGE_NUMBER GREATER 1)
Anton Komlevaee4b612023-05-14 17:38:36 +0100133
David Hua01be0a2023-10-25 23:08:10 +0800134 add_custom_target(tfm_ns_signed_bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100135 SOURCES ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800136 )
Dávid Házi1a72fd42024-03-06 18:33:45 +0100137 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800138 DEPENDS tfm_ns_bin $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200139 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
David Hua01be0a2023-10-25 23:08:10 +0800140 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
David Hub5f10a52023-10-26 22:24:10 +0800141 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100142
Dávid Házi34cf9b92023-10-11 11:10:41 +0200143 #Sign non-secure binary image with provided secret key
144 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
145 --version ${MCUBOOT_IMAGE_VERSION_NS}
146 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
Raef Coles1d68b872023-11-06 16:33:34 +0000147 --key ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_ns_signing_private_key.pem
Dávid Házi34cf9b92023-10-11 11:10:41 +0200148 --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_NS}
154 -L ${MCUBOOT_ENC_KEY_LEN}
155 -d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\"
Dávid Házi34cf9b92023-10-11 11:10:41 +0200156 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
157 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
Raef Coles1d68b872023-11-06 16:33:34 +0000158 $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_enc_key.pem>
Dávid Házi34cf9b92023-10-11 11:10:41 +0200159 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
Raef Coles1d68b872023-11-06 16:33:34 +0000160 $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100161 ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800162 )
Anton Komlevaee4b612023-05-14 17:38:36 +0100163
David Hua01be0a2023-10-25 23:08:10 +0800164 # Create concatenated binary image from the two independently signed
165 # binary file. This only uses the local assemble.py script (not from
166 # upstream mcuboot) because that script is geared towards zephyr
167 # support
Dávid Házi1a72fd42024-03-06 18:33:45 +0100168 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800169 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100170 DEPENDS tfm_ns_signed_bin ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800171 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
David Hub5f10a52023-10-26 22:24:10 +0800172 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
David Hua01be0a2023-10-25 23:08:10 +0800173
Dávid Házi34cf9b92023-10-11 11:10:41 +0200174 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
175 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
176 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100177 --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
178 --output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200179 )
180 else()
David Hua01be0a2023-10-25 23:08:10 +0800181 add_custom_target(tfm_s_ns_bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100182 SOURCES ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800183 )
Dávid Házi1a72fd42024-03-06 18:33:45 +0100184 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800185 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
186 DEPENDS tfm_ns_bin $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
David Hub5f10a52023-10-26 22:24:10 +0800187 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
188 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100189
Dávid Házi34cf9b92023-10-11 11:10:41 +0200190 # concatenate S + NS binaries into tfm_s_ns.bin
191 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
David Hub5f10a52023-10-26 22:24:10 +0800192 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Dávid Házi34cf9b92023-10-11 11:10:41 +0200193 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
David Hua01be0a2023-10-25 23:08:10 +0800194 --non_secure $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100195 --output ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800196 )
197
Dávid Házi1a72fd42024-03-06 18:33:45 +0100198 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
199 DEPENDS tfm_s_ns_bin ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hub5f10a52023-10-26 22:24:10 +0800200 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
David Hua01be0a2023-10-25 23:08:10 +0800201 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
David Hub5f10a52023-10-26 22:24:10 +0800202 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100203
Dávid Házi34cf9b92023-10-11 11:10:41 +0200204 # sign the combined tfm_s_ns.bin file
205 COMMAND ${Python3_EXECUTABLE}
206 ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
207 --version ${MCUBOOT_IMAGE_VERSION_S}
David Hub5f10a52023-10-26 22:24:10 +0800208 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Raef Coles1d68b872023-11-06 16:33:34 +0000209 --key ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_s_signing_private_key.pem
Dávid Házi34cf9b92023-10-11 11:10:41 +0200210 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
211 --align ${MCUBOOT_ALIGN_VAL}
212 --pad
213 --pad-header
214 -H ${BL2_HEADER_SIZE}
215 -s ${MCUBOOT_SECURITY_COUNTER_S}
216 -L ${MCUBOOT_ENC_KEY_LEN}
217 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
218 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
Raef Coles1d68b872023-11-06 16:33:34 +0000219 $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_enc_key.pem>
Dávid Házi34cf9b92023-10-11 11:10:41 +0200220 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
Dávid Házi1a72fd42024-03-06 18:33:45 +0100221 ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
222 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200223 )
224 endif()
Anton Komlevaee4b612023-05-14 17:38:36 +0100225endif()