@@ -446,6 +446,7 @@ if (CONFIG_BUILD_WITH_TFM)
446
446
447
447
dt_chosen(chosen_flash PROPERTY "zephyr,flash" )
448
448
dt_prop(flash_write_block_size PATH ${chosen_flash} PROPERTY write-block-size)
449
+ dt_prop(flash_erase_block_size PATH ${chosen_flash} PROPERTY erase-block-size)
449
450
# The alignment is determined by the minimal amount of bytes necessary to
450
451
# be written in the flash sector. Ex., assuming that the sector erase
451
452
# operation is 1KiB and, on that sector, the minimal amount of bytes that
@@ -463,8 +464,15 @@ if (CONFIG_BUILD_WITH_TFM)
463
464
else ()
464
465
set (image_alignment 1)
465
466
endif ()
467
+ # Calculate the maximum number of sectors necessary to store the image.
468
+ dt_nodelabel(s_partition_node NODELABEL "slot0_partition" )
469
+ dt_nodelabel(ns_partition_node NODELABEL "slot0_ns_partition" )
470
+ dt_reg_size(s_partition_size PATH ${s_partition_node} )
471
+ dt_reg_size(ns_partition_size PATH ${ns_partition_node} )
472
+ math (EXPR S_MAX_SECTORS "${s_partition_size} / ${flash_erase_block_size} " )
473
+ math (EXPR NS_MAX_SECTORS "${ns_partition_size} / ${flash_erase_block_size} " )
466
474
467
- function (tfm_sign OUT_ARG SUFFIX PAD INPUT_FILE OUTPUT_FILE)
475
+ function (tfm_sign OUT_ARG SUFFIX PAD MAX_SECTORS INPUT_FILE OUTPUT_FILE)
468
476
if (PAD)
469
477
set (pad_args --pad --pad-header)
470
478
endif ()
@@ -484,6 +492,7 @@ if (CONFIG_BUILD_WITH_TFM)
484
492
-k ${CONFIG_TFM_KEY_FILE_${SUFFIX} }
485
493
--public -key-format ${TFM_PUBLIC_KEY_FORMAT}
486
494
--align ${image_alignment}
495
+ --max-sectors ${MAX_SECTORS}
487
496
-v ${CONFIG_TFM_IMAGE_VERSION_${SUFFIX} }
488
497
${pad_args}
489
498
${HEX_ADDR_ARGS_${SUFFIX} }
@@ -524,7 +533,7 @@ if (CONFIG_BUILD_WITH_TFM)
524
533
)
525
534
526
535
elseif (CONFIG_TFM_MCUBOOT_IMAGE_NUMBER STREQUAL "1" )
527
- tfm_sign(sign_cmd S_NS TRUE ${S_NS_FILE} ${S_NS_SIGNED_FILE} )
536
+ tfm_sign(sign_cmd S_NS TRUE ${S_MAX_SECTORS} ${ S_NS_FILE} ${S_NS_SIGNED_FILE} )
528
537
529
538
set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
530
539
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE} /scripts/build /mergehex.py
@@ -549,12 +558,12 @@ if (CONFIG_BUILD_WITH_TFM)
549
558
550
559
else ()
551
560
if (CONFIG_TFM_USE_NS_APP)
552
- tfm_sign(sign_cmd_ns NS TRUE ${NS_APP_FILE} ${NS_SIGNED_FILE} )
561
+ tfm_sign(sign_cmd_ns NS TRUE ${NS_MAX_SECTORS} ${ NS_APP_FILE} ${NS_SIGNED_FILE} )
553
562
else ()
554
- tfm_sign(sign_cmd_ns NS FALSE ${NS_APP_FILE} ${NS_SIGNED_FILE} )
563
+ tfm_sign(sign_cmd_ns NS FALSE ${NS_MAX_SECTORS} ${ NS_APP_FILE} ${NS_SIGNED_FILE} )
555
564
endif ()
556
565
557
- tfm_sign(sign_cmd_s S TRUE $<TARGET_PROPERTY:tfm,TFM_S_HEX_FILE> ${S_SIGNED_FILE} )
566
+ tfm_sign(sign_cmd_s S TRUE ${S_MAX_SECTORS} $ <TARGET_PROPERTY:tfm,TFM_S_HEX_FILE> ${S_SIGNED_FILE} )
558
567
559
568
#Create and sign for concatenated binary image, should align with the TF-M BL2
560
569
set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
0 commit comments