Skip to content

Commit 4625673

Browse files
committed
trusted-firmware-m: Create multi image bin files
A fundamental use of Trusted Firmware-M is to provide security for IoT applications, where firmware upgrades (FOTA) are almost always mandatory. The current file signing process does not produce the necessary binaries for multi-image S/NS FWU, since hex images are not suitable for this use case. This introduces the missing signed binary files for use by the FWU partition. The changes were tested in multi-image FWU scenarios, and support for single-image scenarios can be easily added in the future. Signed-off-by: BUDKE Gerson Fernando <[email protected]>
1 parent ab04b7f commit 4625673

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

modules/trusted-firmware-m/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ if (CONFIG_BUILD_WITH_TFM)
183183
set(TFM_S_ELF_FILE ${TFM_BINARY_DIR}/bin/tfm_s.elf)
184184
set(TFM_S_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s.bin)
185185
set(TFM_S_HEX_FILE ${TFM_BINARY_DIR}/bin/tfm_s.hex)
186-
set(TFM_NS_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_ns.bin)
186+
set(TFM_NS_BIN_FILE ${CMAKE_BINARY_DIR}/tfm_ns/bin/tfm_ns.bin)
187187
set(TFM_NS_HEX_FILE ${CMAKE_BINARY_DIR}/tfm_ns/bin/tfm_ns.hex)
188188
set(TFM_S_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s_signed.bin)
189189
set(TFM_NS_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_ns_signed.bin)
@@ -549,13 +549,17 @@ if (CONFIG_BUILD_WITH_TFM)
549549
set(S_NS_SIGNED_HEX_FILE ${CMAKE_BINARY_DIR}/zephyr/tfm_s_zephyr_ns_signed.hex)
550550
set(NS_SIGNED_HEX_FILE ${CMAKE_BINARY_DIR}/zephyr/zephyr_ns_signed.hex)
551551
set(S_SIGNED_HEX_FILE ${CMAKE_BINARY_DIR}/zephyr/tfm_s_signed.hex)
552+
set(NS_SIGNED_BIN_FILE ${CMAKE_BINARY_DIR}/zephyr/zephyr_ns_signed.bin)
553+
set(S_SIGNED_BIN_FILE ${CMAKE_BINARY_DIR}/zephyr/tfm_s_signed.bin)
552554

553555
if (CONFIG_TFM_USE_NS_APP)
554556
# Use the TF-M NS binary as the Non-Secure application firmware image
555557
set(NS_HEX_APP_FILE $<TARGET_PROPERTY:tfm,TFM_NS_HEX_FILE>)
558+
set(NS_BIN_APP_FILE $<TARGET_PROPERTY:tfm,TFM_NS_BIN_FILE>)
556559
else()
557560
# Use the Zephyr binary as the Non-Secure application firmware image
558561
set(NS_HEX_APP_FILE ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_HEX_NAME})
562+
set(NS_BIN_APP_FILE ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_BIN_NAME})
559563
endif()
560564

561565
if (NOT CONFIG_TFM_BL2)
@@ -600,18 +604,26 @@ if (CONFIG_BUILD_WITH_TFM)
600604
if (CONFIG_TFM_USE_NS_APP)
601605
tfm_sign(sign_cmd_ns_hex NS TRUE TRUE TRUE ${S_NS_MAX_SECTORS} ${NS_HEX_APP_FILE}
602606
${NS_SIGNED_HEX_FILE})
607+
tfm_sign(sign_cmd_ns_bin NS TRUE TRUE FALSE ${S_NS_MAX_SECTORS} ${NS_BIN_APP_FILE}
608+
${NS_SIGNED_BIN_FILE})
603609
else()
604610
tfm_sign(sign_cmd_ns NS FALSE TRUE TRUE ${S_NS_MAX_SECTORS} ${NS_HEX_APP_FILE}
605611
${NS_SIGNED_HEX_FILE})
612+
tfm_sign(sign_cmd_ns_bin NS FALSE FALSE FALSE ${S_NS_MAX_SECTORS} ${NS_BIN_APP_FILE}
613+
${NS_SIGNED_BIN_FILE})
606614
endif()
607615

608616
tfm_sign(sign_cmd_s_hex S TRUE TRUE TRUE ${S_NS_MAX_SECTORS}
609617
$<TARGET_PROPERTY:tfm,TFM_S_HEX_FILE> ${S_SIGNED_HEX_FILE})
618+
tfm_sign(sign_cmd_s_bin S TRUE TRUE FALSE ${S_NS_MAX_SECTORS}
619+
$<TARGET_PROPERTY:tfm,TFM_S_BIN_FILE> ${S_SIGNED_BIN_FILE})
610620

611621
#Create and sign for concatenated binary image, should align with the TF-M BL2
612622
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
613623
COMMAND ${sign_cmd_ns_hex}
624+
COMMAND ${sign_cmd_ns_bin}
614625
COMMAND ${sign_cmd_s_hex}
626+
COMMAND ${sign_cmd_s_bin}
615627

616628
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/mergehex.py
617629
-o ${MERGED_HEX_FILE}
@@ -623,7 +635,9 @@ if (CONFIG_BUILD_WITH_TFM)
623635

624636
set_property(GLOBAL APPEND PROPERTY extra_post_build_byproducts
625637
${S_SIGNED_HEX_FILE}
638+
${S_SIGNED_BIN_FILE}
626639
${NS_SIGNED_HEX_FILE}
640+
${NS_SIGNED_BIN_FILE}
627641
${MERGED_HEX_FILE}
628642
)
629643
endif()

0 commit comments

Comments
 (0)