blob: d818cc87c2b162606b6cdb67cf54ec1993c0e57e [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>
113 $<$<BOOL:${CONFIG_TFM_ENABLE_CP10CP11}>:CONFIG_TFM_ENABLE_CP10CP11>
114)
115
Anton Komlevaee4b612023-05-14 17:38:36 +0100116target_link_libraries(tfm_api_ns
117 PUBLIC
David Hu35aa1a52023-10-24 23:04:04 +0800118 platform_region_defs
David Hu35aa1a52023-10-24 23:04:04 +0800119 platform_ns
Anton Komlevaee4b612023-05-14 17:38:36 +0100120)
121
Dávid Házi34cf9b92023-10-11 11:10:41 +0200122if(BL2 AND PLATFORM_DEFAULT_IMAGE_SIGNING)
Anton Komlevaee4b612023-05-14 17:38:36 +0100123
David Hua5fefdc2023-11-03 13:24:41 +0800124 find_package(Python3)
125
David Hua01be0a2023-10-25 23:08:10 +0800126 add_custom_target(tfm_s_ns_signed_bin
127 ALL
Dávid Házi1a72fd42024-03-06 18:33:45 +0100128 SOURCES ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800129 )
130
Dávid Házi34cf9b92023-10-11 11:10:41 +0200131 if (MCUBOOT_IMAGE_NUMBER GREATER 1)
Anton Komlevaee4b612023-05-14 17:38:36 +0100132
David Hua01be0a2023-10-25 23:08:10 +0800133 add_custom_target(tfm_ns_signed_bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100134 SOURCES ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800135 )
Dávid Házi1a72fd42024-03-06 18:33:45 +0100136 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800137 DEPENDS tfm_ns_bin $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200138 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
David Hua01be0a2023-10-25 23:08:10 +0800139 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
David Hub5f10a52023-10-26 22:24:10 +0800140 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100141
Dávid Házi34cf9b92023-10-11 11:10:41 +0200142 #Sign non-secure binary image with provided secret key
143 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
144 --version ${MCUBOOT_IMAGE_VERSION_NS}
145 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
Raef Coles1d68b872023-11-06 16:33:34 +0000146 --key ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_ns_signing_private_key.pem
Dávid Házi34cf9b92023-10-11 11:10:41 +0200147 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
148 --align ${MCUBOOT_ALIGN_VAL}
149 --pad
150 --pad-header
151 -H ${BL2_HEADER_SIZE}
152 -s ${MCUBOOT_SECURITY_COUNTER_NS}
153 -L ${MCUBOOT_ENC_KEY_LEN}
154 -d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\"
Dávid Házi34cf9b92023-10-11 11:10:41 +0200155 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
156 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
Raef Coles1d68b872023-11-06 16:33:34 +0000157 $<$<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 +0200158 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
Raef Coles1d68b872023-11-06 16:33:34 +0000159 $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100160 ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800161 )
Anton Komlevaee4b612023-05-14 17:38:36 +0100162
David Hua01be0a2023-10-25 23:08:10 +0800163 # Create concatenated binary image from the two independently signed
164 # binary file. This only uses the local assemble.py script (not from
165 # upstream mcuboot) because that script is geared towards zephyr
166 # support
Dávid Házi1a72fd42024-03-06 18:33:45 +0100167 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800168 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100169 DEPENDS tfm_ns_signed_bin ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
David Hua01be0a2023-10-25 23:08:10 +0800170 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
David Hub5f10a52023-10-26 22:24:10 +0800171 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
David Hua01be0a2023-10-25 23:08:10 +0800172
Dávid Házi34cf9b92023-10-11 11:10:41 +0200173 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
174 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
175 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100176 --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
177 --output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200178 )
179 else()
David Hua01be0a2023-10-25 23:08:10 +0800180 add_custom_target(tfm_s_ns_bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100181 SOURCES ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800182 )
Dávid Házi1a72fd42024-03-06 18:33:45 +0100183 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800184 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
185 DEPENDS tfm_ns_bin $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
David Hub5f10a52023-10-26 22:24:10 +0800186 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
187 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100188
Dávid Házi34cf9b92023-10-11 11:10:41 +0200189 # concatenate S + NS binaries into tfm_s_ns.bin
190 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
David Hub5f10a52023-10-26 22:24:10 +0800191 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Dávid Házi34cf9b92023-10-11 11:10:41 +0200192 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
David Hua01be0a2023-10-25 23:08:10 +0800193 --non_secure $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
Dávid Házi1a72fd42024-03-06 18:33:45 +0100194 --output ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hua01be0a2023-10-25 23:08:10 +0800195 )
196
Dávid Házi1a72fd42024-03-06 18:33:45 +0100197 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
198 DEPENDS tfm_s_ns_bin ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
David Hub5f10a52023-10-26 22:24:10 +0800199 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
David Hua01be0a2023-10-25 23:08:10 +0800200 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
David Hub5f10a52023-10-26 22:24:10 +0800201 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
Anton Komlevaee4b612023-05-14 17:38:36 +0100202
Dávid Házi34cf9b92023-10-11 11:10:41 +0200203 # sign the combined tfm_s_ns.bin file
204 COMMAND ${Python3_EXECUTABLE}
205 ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
206 --version ${MCUBOOT_IMAGE_VERSION_S}
David Hub5f10a52023-10-26 22:24:10 +0800207 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Raef Coles1d68b872023-11-06 16:33:34 +0000208 --key ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/keys/image_s_signing_private_key.pem
Dávid Házi34cf9b92023-10-11 11:10:41 +0200209 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
210 --align ${MCUBOOT_ALIGN_VAL}
211 --pad
212 --pad-header
213 -H ${BL2_HEADER_SIZE}
214 -s ${MCUBOOT_SECURITY_COUNTER_S}
215 -L ${MCUBOOT_ENC_KEY_LEN}
216 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
217 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
Raef Coles1d68b872023-11-06 16:33:34 +0000218 $<$<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 +0200219 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
Dávid Házi1a72fd42024-03-06 18:33:45 +0100220 ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
221 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
Dávid Házi34cf9b92023-10-11 11:10:41 +0200222 )
223 endif()
Anton Komlevaee4b612023-05-14 17:38:36 +0100224endif()