blob: 6c537c3d3cd3dfecb6847b92579932c1d92be710 [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
33)
34
35add_subdirectory(platform)
36
37target_link_libraries(tfm_api_ns
38 PUBLIC
39 platform_ns
40 tfm_config
41 $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${CMAKE_CURRENT_SOURCE_DIR}/interface/lib/s_veneers.o>
42)
43
Anton Komlevaee4b612023-05-14 17:38:36 +010044add_custom_target(tfm_ns_binaries
45 DEPENDS tfm_ns
46 COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:tfm_ns> ${CMAKE_BINARY_DIR}/tfm_ns.bin
47 COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm $<TARGET_FILE:tfm_ns> ${CMAKE_BINARY_DIR}/tfm_ns.elf
48 COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:tfm_ns> ${CMAKE_BINARY_DIR}/tfm_ns.hex
49)
50
51if (MCUBOOT_IMAGE_NUMBER GREATER 1)
52
53 add_custom_target(tfm_app_binaries
54 DEPENDS tfm_ns_binaries
55 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
56 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
57
58 #Sign non-secure binary image with provided secret key
59 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
60 --version ${MCUBOOT_IMAGE_VERSION_NS}
61 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_ns.o
62 --key ${MCUBOOT_KEY_NS}
63 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
64 --align ${MCUBOOT_ALIGN_VAL}
65 --pad
66 --pad-header
67 -H ${BL2_HEADER_SIZE}
68 -s ${MCUBOOT_SECURITY_COUNTER_NS}
69 -L ${MCUBOOT_ENC_KEY_LEN}
70 -d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\"
71 ${CMAKE_BINARY_DIR}/tfm_ns.bin
72 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
73 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
74 $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}>
75 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
76 ${CMAKE_BINARY_DIR}/tfm_ns_signed.bin
77
78 # Create concatenated binary image from the two independently signed
79 # binary file. This only uses the local assemble.py script (not from
80 # upstream mcuboot) because that script is geared towards zephyr
81 # support
82 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
83 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
Anton Komlev3dd98632023-09-20 16:26:30 +010084 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
Anton Komlevaee4b612023-05-14 17:38:36 +010085 --non_secure ${CMAKE_BINARY_DIR}/tfm_ns_signed.bin
86 --output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
87 # merge bootloader and application into Hex image for upload
Anton Komlev3dd98632023-09-20 16:26:30 +010088 COMMAND srec_cat ${CMAKE_CURRENT_SOURCE_DIR}/bin/bl2.bin -Binary -offset 0xA000000
Anton Komlevaee4b612023-05-14 17:38:36 +010089 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin -Binary -offset 0xA020000
90 -o ${CMAKE_BINARY_DIR}/tfm.hex -Intel
91 )
92else()
93
94 add_custom_target(tfm_app_binaries
95 DEPENDS tfm_ns_binaries
96 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,>
97 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts
98
99 # concatenate S + NS binaries into tfm_s_ns.bin
100 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
101 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
Anton Komlev3dd98632023-09-20 16:26:30 +0100102 --secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
Anton Komlevaee4b612023-05-14 17:38:36 +0100103 --non_secure ${CMAKE_BINARY_DIR}/tfm_ns.bin
104 --output ${CMAKE_BINARY_DIR}/tfm_s_ns.bin
105
106 # sign the combined tfm_s_ns.bin file
107 COMMAND ${Python3_EXECUTABLE}
108 ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/wrapper/wrapper.py
109 --version ${MCUBOOT_IMAGE_VERSION_S}
110 --layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
111 --key ${MCUBOOT_KEY_S}
112 --public-key-format $<IF:$<BOOL:${MCUBOOT_HW_KEY}>,full,hash>
113 --align ${MCUBOOT_ALIGN_VAL}
114 --pad
115 --pad-header
116 -H ${BL2_HEADER_SIZE}
117 -s ${MCUBOOT_SECURITY_COUNTER_S}
118 -L ${MCUBOOT_ENC_KEY_LEN}
119 $<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
120 $<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
121 $<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}>
122 $<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
123 ${CMAKE_BINARY_DIR}/tfm_s_ns.bin
124 ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
125 )
126endif()
127