Skip to content

Commit 1bbfbef

Browse files
JordanYatesnashif
authored andcommitted
modules: tfm: fix TFM_MCUBOOT_IMAGE_NUMBER == 1
Fix builds with `CONFIG_TFM_MCUBOOT_IMAGE_NUMBER=1`. The merged binary should be signed with the same argumements as a secure build, not a non-secure build, except with a different layout file generated by the TF-M build system. Fixes #68345. Signed-off-by: Jordan Yates <[email protected]>
1 parent 0155c6f commit 1bbfbef

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

modules/trusted-firmware-m/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ if (CONFIG_BUILD_WITH_TFM)
393393

394394
if (CONFIG_TFM_BL2)
395395
set(PREPROCESSED_FILE_S "${TFM_BINARY_DIR}/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s.o")
396+
set(PREPROCESSED_FILE_S_NS "${TFM_BINARY_DIR}/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s_ns.o")
396397
set(PREPROCESSED_FILE_NS "${TFM_BINARY_DIR}/bl2/ext/mcuboot/CMakeFiles/signing_layout_ns.dir/signing_layout_ns.o")
397398
set(TFM_MCUBOOT_DIR "${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/bl2/ext/mcuboot")
398399
endif()
@@ -415,13 +416,19 @@ if (CONFIG_BUILD_WITH_TFM)
415416
if(PAD)
416417
set(pad_args --pad --pad-header)
417418
endif()
419+
# Secure + Non-secure images are signed the same way as a secure only
420+
# build, but with a different layout file.
421+
set(layout_file ${PREPROCESSED_FILE_${SUFFIX}})
422+
if(SUFFIX STREQUAL "S_NS")
423+
set(SUFFIX "S")
424+
endif()
418425
set (${OUT_ARG}
419426
# Add the MCUBoot script to the path so that if there is a version of imgtool in there then
420427
# it gets used over the system imgtool. Used so that imgtool from upstream
421428
# mcuboot is preferred over system imgtool
422429
${CMAKE_COMMAND} -E env PYTHONPATH=${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts
423430
${PYTHON_EXECUTABLE} ${TFM_MCUBOOT_DIR}/scripts/wrapper/wrapper.py
424-
--layout ${PREPROCESSED_FILE_${SUFFIX}}
431+
--layout ${layout_file}
425432
-k ${CONFIG_TFM_KEY_FILE_${SUFFIX}}
426433
--public-key-format ${TFM_PUBLIC_KEY_FORMAT}
427434
--align 1
@@ -465,7 +472,7 @@ if (CONFIG_BUILD_WITH_TFM)
465472
)
466473

467474
elseif(CONFIG_TFM_MCUBOOT_IMAGE_NUMBER STREQUAL "1")
468-
tfm_sign(sign_cmd NS TRUE ${S_NS_FILE} ${S_NS_SIGNED_FILE})
475+
tfm_sign(sign_cmd S_NS TRUE ${S_NS_FILE} ${S_NS_SIGNED_FILE})
469476

470477
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
471478
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/mergehex.py

modules/trusted-firmware-m/Kconfig.tfm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ config TFM_IMAGE_VERSION_S
192192
help
193193
MCUBoot may be configured to prevent rollback prevention based on image
194194
versions of both the secure firmware and non-secure firmware. This sets
195-
the secure firmware's version for rollback prevention.
195+
the secure firmware's version for rollback prevention. This version is
196+
also used for merged secure + non-secure builds
197+
(TFM_MCUBOOT_IMAGE_NUMBER == 1).
196198

197199
config TFM_IMAGE_VERSION_NS
198200
string "Version of the Non-Secure Image"
@@ -250,7 +252,8 @@ config TFM_KEY_FILE_S
250252
help
251253
The path and filename for the .pem file containing the private key
252254
that should be used by the BL2 bootloader when signing secure
253-
firmware images.
255+
firmware images. This key file is also used for merged secure +
256+
non-secure builds (TFM_MCUBOOT_IMAGE_NUMBER == 1).
254257

255258
config TFM_KEY_FILE_NS
256259
string "Path to private key used to sign non-secure firmware images."

0 commit comments

Comments
 (0)