Skip to content

Commit bc7bd49

Browse files
committed
trusted-firmware-m: Set --align when signing
The current version of TF-M script that sign MCUboot image uses a default alignment of 1. This value varies between flash devices and not all accept the default 1. This improve the script picking the write-block-size property from the current flash controller and pass as the --align parameter when signing an image. Note: This solution works out-of-box for the vast majority of devices in the Zephyr tree and an exception will throw when a device is not supported. Signed-off-by: BUDKE Gerson Fernando <[email protected]>
1 parent b82a8eb commit bc7bd49

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

modules/trusted-firmware-m/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,26 @@ if (CONFIG_BUILD_WITH_TFM)
444444
set(HEX_ADDR_ARGS_NS "--hex-addr=${TFM_HEX_BASE_ADDRESS_NS}")
445445
endif()
446446

447+
dt_chosen(chosen_flash PROPERTY "zephyr,flash")
448+
dt_prop(flash_write_block_size PATH ${chosen_flash} PROPERTY write-block-size)
449+
# The alignment is determined by the minimal amount of bytes necessary to
450+
# be written in the flash sector. Ex., assuming that the sector erase
451+
# operation is 1KiB and, on that sector, the minimal amount of bytes that
452+
# must be writen is 8 bytes than the alignment is 8.
453+
#
454+
# Current MCUboot maximum alignment is 32 bytes.
455+
if(flash_write_block_size GREATER 0)
456+
if(flash_write_block_size GREATER 32)
457+
message(FATAL_ERROR
458+
"imgtool max alignment is 32 and current value is
459+
{$flash_write_block_size}"
460+
)
461+
endif()
462+
set(image_alignment ${flash_write_block_size})
463+
else()
464+
set(image_alignment 1)
465+
endif()
466+
447467
function(tfm_sign OUT_ARG SUFFIX PAD INPUT_FILE OUTPUT_FILE)
448468
if(PAD)
449469
set(pad_args --pad --pad-header)
@@ -463,7 +483,7 @@ if (CONFIG_BUILD_WITH_TFM)
463483
--layout ${layout_file}
464484
-k ${CONFIG_TFM_KEY_FILE_${SUFFIX}}
465485
--public-key-format ${TFM_PUBLIC_KEY_FORMAT}
466-
--align 1
486+
--align ${image_alignment}
467487
-v ${CONFIG_TFM_IMAGE_VERSION_${SUFFIX}}
468488
${pad_args}
469489
${HEX_ADDR_ARGS_${SUFFIX}}

0 commit comments

Comments
 (0)