blob: 1c56338f4302d0b237a600f3037e5cebfae010eb [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
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
27 PRIVATE
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 +080036target_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 Komlevaee4b612023-05-14 17:38:36 +010044target_include_directories(tfm_api_ns
45 PUBLIC
David Hub27a6632023-10-23 22:38:39 +080046 ${INTERFACE_INC_DIR}
47 ${INTERFACE_INC_DIR}/crypto_keys
48 $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:${INTERFACE_INC_DIR}/multi_core>
Anton Komlevaee4b612023-05-14 17:38:36 +010049)
50
David Hu35aa1a52023-10-24 23:04:04 +080051add_library(platform_region_defs INTERFACE)
52
53target_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
66target_link_libraries(platform_region_defs
67 INTERFACE
68 tfm_config
69)
70
Anton Komlevaee4b612023-05-14 17:38:36 +010071add_subdirectory(platform)
72
David Hub27a6632023-10-23 22:38:39 +080073target_sources(platform_ns
74 PRIVATE
75 $<$<BOOL:${PLATFORM_DEFAULT_UART_STDOUT}>:${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/common/uart_stdout.c>
76)
77
Anton Komlevaee4b612023-05-14 17:38:36 +010078target_link_libraries(tfm_api_ns
79 PUBLIC
David Hu35aa1a52023-10-24 23:04:04 +080080 platform_region_defs
Anton Komlevaee4b612023-05-14 17:38:36 +010081 $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${CMAKE_CURRENT_SOURCE_DIR}/interface/lib/s_veneers.o>
David Hu35aa1a52023-10-24 23:04:04 +080082 PRIVATE
83 platform_ns
Anton Komlevaee4b612023-05-14 17:38:36 +010084)
85
Dávid Házi34cf9b92023-10-11 11:10:41 +020086if(BL2 AND PLATFORM_DEFAULT_IMAGE_SIGNING)
Anton Komlevaee4b612023-05-14 17:38:36 +010087
Dávid Házi34cf9b92023-10-11 11:10:41 +020088 if (MCUBOOT_IMAGE_NUMBER GREATER 1)
Anton Komlevaee4b612023-05-14 17:38:36 +010089
Dávid Házi34cf9b92023-10-11 11:10:41 +020090 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 Komlevaee4b612023-05-14 17:38:36 +010094
Dávid Házi34cf9b92023-10-11 11:10:41 +020095 #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 Komlevaee4b612023-05-14 17:38:36 +0100114
Dávid Házi34cf9b92023-10-11 11:10:41 +0200115 # 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 Komlevaee4b612023-05-14 17:38:36 +0100134
Dávid Házi34cf9b92023-10-11 11:10:41 +0200135 # 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 Komlevaee4b612023-05-14 17:38:36 +0100141
Dávid Házi34cf9b92023-10-11 11:10:41 +0200142 # 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 Komlevaee4b612023-05-14 17:38:36 +0100163endif()