blob: 862baf985b6a3629714340a597b3fcccb3d8e2f8 [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
Gergely Kovacsaae6d782024-10-11 07:21:30 +0000132 if (DEFINED S_NS_SIGNED_TARGET_NAME)
133 message(STATUS "Using S_NS_SIGNED_TARGET_NAME: ${S_NS_SIGNED_TARGET_NAME}")
134 else()
135 set(S_NS_SIGNED_TARGET_NAME tfm_s_ns_signed)
136 endif()
137
138 add_custom_command(
139 TARGET tfm_s_ns_signed_bin
140 POST_BUILD
141 COMMAND ${CMAKE_COMMAND} -E copy
142 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
143 $<TARGET_FILE_DIR:tfm_ns>/${S_NS_SIGNED_TARGET_NAME}.bin
144 )
145
Dávid Házi34cf9b92023-10-11 11:10:41 +0200146 if (MCUBOOT_IMAGE_NUMBER GREATER 1)
Anton Komlevaee4b612023-05-14 17:38:36 +0100147
David Hua01be0a2023-10-25 23:08:10 +0800148 add_custom_target(tfm_ns_signed_bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100149 SOURCES ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800150 )
Dávid Házi1a72fd42024-03-06 18:33:45 +0100151 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800152 DEPENDS tfm_ns_bin $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200153 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
David Hua01be0a2023-10-25 23:08:10 +0800154 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
David Hub5f10a52023-10-26 22:24:10 +0800155 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100156
Dávid Házi34cf9b92023-10-11 11:10:41 +0200157 #Sign non-secure binary image with provided secret key
158 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
159 --version ${MCUBOOT_IMAGE_VERSION_NS}
160 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
Raef Coles1d68b872023-11-06 16:33:34 +0000161 --key ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_ns_signing_private_key.pem
Dávid Házi34cf9b92023-10-11 11:10:41 +0200162 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
163 --align ${MCUBOOT_ALIGN_VAL}
164 --pad
165 --pad-header
166 -H ${BL2_HEADER_SIZE}
167 -s ${MCUBOOT_SECURITY_COUNTER_NS}
168 -L ${MCUBOOT_ENC_KEY_LEN}
169 -d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\"
Dávid Házi34cf9b92023-10-11 11:10:41 +0200170 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
171 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
Raef Coles1d68b872023-11-06 16:33:34 +0000172 $<$<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 +0200173 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
Raef Coles1d68b872023-11-06 16:33:34 +0000174 $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100175 ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800176 )
Anton Komlevaee4b612023-05-14 17:38:36 +0100177
David Hua01be0a2023-10-25 23:08:10 +0800178 # Create concatenated binary image from the two independently signed
179 # binary file. This only uses the local assemble.py script (not from
180 # upstream mcuboot) because that script is geared towards zephyr
181 # support
Dávid Házi1a72fd42024-03-06 18:33:45 +0100182 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800183 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100184 DEPENDS tfm_ns_signed_bin ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800185 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
David Hub5f10a52023-10-26 22:24:10 +0800186 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
David Hua01be0a2023-10-25 23:08:10 +0800187
Dávid Házi34cf9b92023-10-11 11:10:41 +0200188 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
189 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
190 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100191 --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
192 --output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200193 )
194 else()
David Hua01be0a2023-10-25 23:08:10 +0800195 add_custom_target(tfm_s_ns_bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100196 SOURCES ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800197 )
Dávid Házi1a72fd42024-03-06 18:33:45 +0100198 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800199 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
200 DEPENDS tfm_ns_bin $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
David Hub5f10a52023-10-26 22:24:10 +0800201 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
202 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 # concatenate S + NS binaries into tfm_s_ns.bin
205 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
David Hub5f10a52023-10-26 22:24:10 +0800206 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Dávid Házi34cf9b92023-10-11 11:10:41 +0200207 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
David Hua01be0a2023-10-25 23:08:10 +0800208 --non_secure $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100209 --output ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800210 )
211
Dávid Házi1a72fd42024-03-06 18:33:45 +0100212 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
213 DEPENDS tfm_s_ns_bin ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hub5f10a52023-10-26 22:24:10 +0800214 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
David Hua01be0a2023-10-25 23:08:10 +0800215 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
David Hub5f10a52023-10-26 22:24:10 +0800216 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100217
Dávid Házi34cf9b92023-10-11 11:10:41 +0200218 # sign the combined tfm_s_ns.bin file
219 COMMAND ${Python3_EXECUTABLE}
220 ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
221 --version ${MCUBOOT_IMAGE_VERSION_S}
David Hub5f10a52023-10-26 22:24:10 +0800222 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Raef Coles1d68b872023-11-06 16:33:34 +0000223 --key ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_s_signing_private_key.pem
Dávid Házi34cf9b92023-10-11 11:10:41 +0200224 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
225 --align ${MCUBOOT_ALIGN_VAL}
226 --pad
227 --pad-header
228 -H ${BL2_HEADER_SIZE}
229 -s ${MCUBOOT_SECURITY_COUNTER_S}
230 -L ${MCUBOOT_ENC_KEY_LEN}
231 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
232 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
Raef Coles1d68b872023-11-06 16:33:34 +0000233 $<$<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 +0200234 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
Dávid Házi1a72fd42024-03-06 18:33:45 +0100235 ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
236 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200237 )
238 endif()
Anton Komlevaee4b612023-05-14 17:38:36 +0100239endif()