Skip to content

Commit 4740e53

Browse files
gergkvaggarg
authored andcommitted
build: Blinky application with split-build
Blinky application with the seperately build TF-M and the new toolchain. The cmake files exported by TF-M set up the NS interface. The default TF-M signing is used and the resulting images are merged by FRI. Signed-off-by: Gergely Kovacs <[email protected]>
1 parent ed9a156 commit 4740e53

File tree

7 files changed

+61
-99
lines changed

7 files changed

+61
-99
lines changed

applications/blinky/CMakeLists.txt

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@
44

55
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
66

7+
# NS target name the TF-M api_ns CMakeLists.txt uses
8+
set(NS_TARGET_NAME blinky)
79
set(APPLICATION_PATH "${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/applications/blinky" CACHE STRING "Path to the application folder")
810

9-
# Trusted Firmware-M setup
10-
set(TFM_CMAKE_APP_ARGS
11-
-DPROJECT_CONFIG_HEADER_FILE=${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/applications/blinky/configs/tfm_config/project_config.h
12-
)
13-
set(MCUBOOT_IMAGE_NUMBER 2 CACHE STRING "Total number of firmware images")
14-
set(DEFAULT_MCUBOOT_FLASH_MAP ON)
11+
# Toolchain file has to be included before the very first project() call
12+
include(${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/components/security/trusted_firmware-m/integration/cmake/TfmNsToolchain.cmake)
1513

1614
project(blinky-example LANGUAGES C)
1715

18-
# Set global optimization level to reduce code size while keeping the debug experience.
19-
if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
20-
add_compile_options(-Og)
21-
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "ARMClang")
22-
add_compile_options(-O1)
23-
endif()
16+
set_compiler_and_linker_flags()
17+
include(${CONFIG_SPE_PATH}/config/cp_check.cmake)
2418

2519
add_subdirectory(${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR} ${CMAKE_BINARY_DIR}/iot_reference_arm_corstone3xx)
2620

@@ -32,40 +26,43 @@ include(SignTfmImage)
3226

3327
add_subdirectory(configs)
3428

35-
add_executable(blinky main.c)
36-
# Trusted Firmware-M must be built before the application, because
37-
# the application depends on the NS interface and the BL2 signing scripts,
38-
# both of which are generated as parts of the Trusted Firmware-M build process.
39-
add_dependencies(blinky trusted_firmware-m-build)
29+
add_executable(blinky
30+
main.c
31+
${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_rtos.c
32+
)
33+
4034
target_link_libraries(blinky
4135
freertos_kernel
4236
fri-bsp
43-
tfm-ns-interface
37+
tfm_api_ns
4438
toolchain-override
39+
# FRI always uses TrustZone
40+
tfm_api_ns_tz
4541
)
4642

4743
set_linker_script(blinky)
4844

4945
list(APPEND CMAKE_MODULE_PATH ${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/tools/cmake)
5046
include(ConvertElfToBin)
51-
include(ExternalProject)
52-
ExternalProject_Get_Property(trusted_firmware-m-build BINARY_DIR)
5347

5448
extract_sections_from_axf(
5549
blinky
5650
SECTIONS_NAMES "ddr.bin"
5751
OUTPUT_BIN_NAME "ns_image"
5852
)
5953

60-
# The non-secure application image should be padded while being signed
61-
# Hence, passing "TRUE" as the input parameter to the pad option of sign function.
62-
iot_reference_arm_corstone3xx_tf_m_sign_image(
63-
blinky
64-
"ns_image"
65-
blinky_signed
66-
0.0.1
67-
"${BINARY_DIR}/api_ns/image_signing/layout_files/signing_layout_ns.o"
68-
TRUE
54+
# Copy the binary flash content to the location expected by default signing
55+
# Signing is implemented in the exported TF-M NS CMakeLists.txt (in the
56+
# ${CONFIG_SPE_PATH} directory)
57+
add_custom_target(blinky_bin
58+
SOURCES ${CMAKE_BINARY_DIR}/blinky.bin
59+
DEPENDS blinky
60+
)
61+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/blinky.bin
62+
DEPENDS blinky
63+
COMMAND ${CMAKE_COMMAND}
64+
-E copy ${SECTORS_BIN_DIR}/ns_image.bin
65+
${CMAKE_BINARY_DIR}/blinky.bin
6966
)
7067

7168
# A user project that consumes the ARM FRI needs to explicitly provide

applications/blinky/configs/freertos_config/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Arm Limited and/or its affiliates
1+
# Copyright 2023-2025 Arm Limited and/or its affiliates
22
33
# SPDX-License-Identifier: MIT
44

@@ -14,6 +14,6 @@ target_compile_definitions(freertos_config
1414

1515
target_link_libraries(freertos_config
1616
INTERFACE
17-
tfm-ns-interface
17+
tfm_api_ns
1818
app-config
1919
)

components/security/freertos_pkcs11_psa/integration/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Arm Limited and/or its affiliates
1+
# Copyright 2023-2025 Arm Limited and/or its affiliates
22
33
# SPDX-License-Identifier: MIT
44

@@ -10,19 +10,17 @@ add_library(freertos-pkcs11-psa
1010
${freertos_pkcs11_psa_SOURCE_DIR}/iot_pkcs11_psa.c
1111
)
1212

13-
ExternalProject_Get_Property(trusted_firmware-m-build BINARY_DIR)
14-
1513
target_include_directories(freertos-pkcs11-psa
1614
PUBLIC
1715
${freertos_pkcs11_psa_SOURCE_DIR}
18-
${BINARY_DIR}/api_ns/interface/include
1916
)
2017

2118
add_library(freertos-pkcs11-psa-config INTERFACE)
2219

2320
target_link_libraries(freertos-pkcs11-psa
2421
PUBLIC
2522
freertos-pkcs11-psa-config
23+
tfm_api_ns
2624
PRIVATE
2725
corepkcs11
2826
freertos_kernel

components/security/mbedtls/integration/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023-2024 Arm Limited and/or its affiliates
1+
# Copyright 2023-2025 Arm Limited and/or its affiliates
22
33
# SPDX-License-Identifier: MIT
44

@@ -15,7 +15,7 @@ target_link_libraries(mbedtls
1515
if(PSA_CRYPTO_IMPLEMENTATION STREQUAL "TF-M")
1616
target_link_libraries(mbedtls
1717
PRIVATE
18-
tfm-ns-interface
18+
tfm_api_ns
1919
)
2020
target_compile_definitions(mbedtls-config
2121
INTERFACE

components/security/trusted_firmware-m/integration/CMakeLists.txt

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,24 @@
22
33
# SPDX-License-Identifier: MIT
44

5-
project(tfm-ns-interface)
6-
75
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
86

9-
include(BuildTfm)
10-
11-
# TF-M NS interface for the non-secure side
12-
13-
add_library(tfm-ns-interface ${tfm_ns_interface_generated})
14-
add_dependencies(tfm-ns-interface trusted_firmware-m-build)
7+
# Use different startup and driver files than TF-M defaults
8+
set(PLATFORM_CUSTOM_NS_FILES TRUE)
9+
# The exported TF-M interfaces
10+
add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
1511

16-
target_include_directories(tfm-ns-interface
17-
PUBLIC
18-
${BINARY_DIR}/api_ns/interface/include
19-
${BINARY_DIR}/api_ns/platform/include
20-
)
21-
22-
target_link_libraries(tfm-ns-interface
12+
target_link_libraries(tfm_api_ns
2313
PRIVATE
24-
${s_veneers_generated}
2514
tfm-ns-interface-mbedtls-config
2615
)
2716

28-
target_compile_definitions(tfm-ns-interface
29-
PUBLIC
30-
BL2
31-
# Corstone-315 is not using the default crypto keys, it is defined in the TF-M platform port
32-
$<$<STREQUAL:${ARM_CORSTONE_BSP_TARGET_PLATFORM},corstone300>:PLATFORM_DEFAULT_CRYPTO_KEYS>
33-
$<$<STREQUAL:${ARM_CORSTONE_BSP_TARGET_PLATFORM},corstone310>:PLATFORM_DEFAULT_CRYPTO_KEYS>
34-
)
35-
3617
add_library(tfm-ns-interface-mbedtls-config INTERFACE)
3718

3819
if(APPLICATION_PATH MATCHES ".*blinky")
39-
# TODO: These compile definitions shouldn't be defined explicitly for `blinky` application as
40-
# they should have been defined by `psa_crypto_config` library which should be linked
41-
# to `tfm-ns-interface-mbedtls-config` library. However, since we are not using TF-M split-build feature,
42-
# the exported library `psa_crypto_config` is not used by the non-secure side and these definitions are missing.
43-
target_compile_definitions(tfm-ns-interface-mbedtls-config
44-
INTERFACE
45-
MBEDTLS_CONFIG_FILE="${trusted_firmware-m_SOURCE_DIR}/lib/ext/mbedcrypto/mbedcrypto_config/tfm_mbedcrypto_config_client.h"
46-
MBEDTLS_PSA_CRYPTO_CONFIG_FILE="${trusted_firmware-m_SOURCE_DIR}/lib/ext/mbedcrypto/mbedcrypto_config/crypto_config_default.h"
20+
target_link_libraries(tfm-ns-interface-mbedtls-config
21+
INTERFACE
22+
psa_crypto_config
4723
)
4824
else()
4925
target_link_libraries(tfm-ns-interface-mbedtls-config
@@ -52,9 +28,13 @@ else()
5228
)
5329
target_compile_definitions(tfm-ns-interface-mbedtls-config
5430
INTERFACE
55-
MBEDTLS_CONFIG_FILE="${APPLICATION_PATH}/configs/mbedtls_config/aws_mbedtls_config.h"
5631
-DPSA_CRYPTO_IMPLEMENTATION_TFM
5732
)
33+
# Change PUBLIC sources to PRIVATE:
34+
# PUBLIC sources are added to both INTERFACE_SOURCES and SOURCES property,
35+
# so removing from interface makes them PRIVATE (only use them when
36+
# building tfm_api_ns, not consuming targets)
37+
set_target_properties(tfm_api_ns PROPERTIES INTERFACE_SOURCES "")
5838
# In case of using Mbed TLS library to provide the PSA Crypto APIs
5939
# implementation, the PSA Crypto APIs implemented and provided by
6040
# TF-M shall be renamed to start with a prefix of tfm_crypto__

components/security/trusted_firmware-m/integration/cmake/MergeTfmImages.cmake

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
33
# SPDX-License-Identifier: MIT
44

5-
include(ExternalProject)
6-
7-
ExternalProject_Get_Property(trusted_firmware-m-build BINARY_DIR)
8-
95
# To merge the bootloader image, TF-M secure image, non-secure user application image,
106
# secure and non-secure provsioning bundle images into one image, their addresses are
117
# needed. As the addresses are defined in their respective linker scripts, there is no
@@ -37,20 +33,17 @@ function(iot_reference_arm_corstone3xx_tf_m_merge_images target)
3733
find_program(srec_cat NAMES srec_cat REQUIRED)
3834
find_program(objcopy NAMES arm-none-eabi-objcopy objcopy REQUIRED)
3935
if(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone300" OR ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone310")
40-
add_custom_command(
41-
TARGET
42-
${target}
43-
POST_BUILD
36+
add_custom_target(${target}_merged
4437
DEPENDS
45-
$<TARGET_FILE_DIR:${target}>/${target}_signed.bin
38+
${target}_signed_bin
4639
COMMAND
47-
${srec_cat} ${BINARY_DIR}/api_ns/bin/bl2.bin -Binary -offset ${BL2_IMAGE_LOAD_ADDRESS}
48-
${BINARY_DIR}/api_ns/bin/tfm_s_signed.bin -Binary -offset ${S_IMAGE_LOAD_ADDRESS}
49-
$<TARGET_FILE_DIR:${target}>/${target}_signed.bin -Binary -offset ${NS_IMAGE_LOAD_ADDRESS}
40+
${srec_cat} ${CONFIG_SPE_PATH}/bin/bl2.bin -Binary -offset ${BL2_IMAGE_LOAD_ADDRESS}
41+
${CONFIG_SPE_PATH}/bin/tfm_s_signed.bin -Binary -offset ${S_IMAGE_LOAD_ADDRESS}
42+
${CMAKE_BINARY_DIR}/bin/${target}_signed.bin -Binary -offset ${NS_IMAGE_LOAD_ADDRESS}
5043
${ddr_binary_param}
5144
${ns_provisioning_data_param}
5245
${model_binary_param}
53-
${BINARY_DIR}/api_ns/bin/provisioning_bundle.bin -Binary -offset ${S_PROVISIONING_BUNDLE_LOAD_ADDRESS}
46+
${CONFIG_SPE_PATH}/bin/provisioning_bundle.bin -Binary -offset ${S_PROVISIONING_BUNDLE_LOAD_ADDRESS}
5447
-o $<TARGET_FILE_DIR:${target}>/${target}_merged.hex
5548
COMMAND
5649
${objcopy} -I ihex -O elf32-little
@@ -61,19 +54,16 @@ function(iot_reference_arm_corstone3xx_tf_m_merge_images target)
6154
VERBATIM
6255
)
6356
else()
64-
add_custom_command(
65-
TARGET
66-
${target}
67-
POST_BUILD
57+
add_custom_target(${target}_merged
6858
DEPENDS
69-
$<TARGET_FILE_DIR:${target}>/${target}_signed.bin
59+
${target}_signed_bin
7060
COMMAND
71-
${srec_cat} ${BINARY_DIR}/api_ns/bin/bl1_1.bin -Binary -offset ${BL1_IMAGE_LOAD_ADDRESS}
72-
${BINARY_DIR}/api_ns/bin/cm_provisioning_bundle.bin -Binary -offset ${S_CM_PROVISIONING_BUNDLE_LOAD_ADDRESS}
73-
${BINARY_DIR}/api_ns/bin/dm_provisioning_bundle.bin -Binary -offset ${S_DM_PROVISIONING_BUNDLE_LOAD_ADDRESS}
74-
${BINARY_DIR}/api_ns/bin/bl2_signed.bin -Binary -offset ${BL2_IMAGE_LOAD_ADDRESS}
75-
${BINARY_DIR}/api_ns/bin/tfm_s_signed.bin -Binary -offset ${S_IMAGE_LOAD_ADDRESS}
76-
$<TARGET_FILE_DIR:${target}>/${target}_signed.bin -Binary -offset ${NS_IMAGE_LOAD_ADDRESS}
61+
${srec_cat} ${CONFIG_SPE_PATH}/bin/bl1_1.bin -Binary -offset ${BL1_IMAGE_LOAD_ADDRESS}
62+
${CONFIG_SPE_PATH}/bin/cm_provisioning_bundle.bin -Binary -offset ${S_CM_PROVISIONING_BUNDLE_LOAD_ADDRESS}
63+
${CONFIG_SPE_PATH}/bin/dm_provisioning_bundle.bin -Binary -offset ${S_DM_PROVISIONING_BUNDLE_LOAD_ADDRESS}
64+
${CONFIG_SPE_PATH}/bin/bl2_signed.bin -Binary -offset ${BL2_IMAGE_LOAD_ADDRESS}
65+
${CONFIG_SPE_PATH}/bin/tfm_s_signed.bin -Binary -offset ${S_IMAGE_LOAD_ADDRESS}
66+
${CMAKE_BINARY_DIR}/bin/${target}_signed.bin -Binary -offset ${NS_IMAGE_LOAD_ADDRESS}
7767
${model_binary_param}
7868
${ddr_binary_param}
7969
${ns_provisioning_data_param}

components/security/trusted_firmware-m/integration/cmake/SignTfmImage.cmake

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
list(APPEND CMAKE_MODULE_PATH ${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/tools/cmake)
66
include(ConvertElfToBin)
7-
include(ExternalProject)
8-
9-
ExternalProject_Get_Property(trusted_firmware-m-build BINARY_DIR)
107

118
# This function is documented under `Image signing` section in `trusted_firmware-m.md` document located at
129
# `${IOT_REFERENCE_ARM_CORSTONE3XX_SOURCE_DIR}/docs/components/security/` directory.
@@ -25,10 +22,10 @@ function(iot_reference_arm_corstone3xx_tf_m_sign_image target unsigned_image_bin
2522
$<TARGET_FILE_DIR:${target}>/${target}.bin
2623
COMMAND
2724
# Sign the non-secure (application) image for TF-M bootloader (BL2)
28-
python3 ${BINARY_DIR}/api_ns/image_signing/scripts/wrapper/wrapper.py
25+
python3 ${CONFIG_SPE_PATH}/image_signing/scripts/wrapper/wrapper.py
2926
-v ${signed_bin_version}
3027
--layout ${signature_layout_file}
31-
-k ${BINARY_DIR}/api_ns/image_signing/keys/image_ns_signing_private_key.pem
28+
-k ${CONFIG_SPE_PATH}/image_signing/keys/image_ns_signing_private_key.pem
3229
--public-key-format full
3330
--align 1 --pad-header ${pad_option} -H 0x400 -s auto
3431
--measured-boot-record

0 commit comments

Comments
 (0)