@@ -58,36 +58,46 @@ function(zephyr_mcuboot_tasks)
5858 # Fetch devicetree details for flash and slot information
5959 dt_chosen(flash_node PROPERTY "zephyr,flash" )
6060 dt_nodelabel(slot0_flash NODELABEL "slot0_partition" REQUIRED)
61- dt_prop (slot_size PATH "${slot0_flash} " PROPERTY "reg" INDEX 1 REQUIRED)
61+ dt_reg_size (slot_size PATH "${slot0_flash} " REQUIRED)
6262 dt_prop(write_block_size PATH "${flash_node} " PROPERTY "write-block-size" )
6363
6464 if (NOT write_block_size)
6565 set (write_block_size 4)
6666 message (WARNING "slot0_partition write block size devicetree parameter is missing, assuming write block size is 4" )
6767 endif ()
6868
69- set (imgtool_directxip_hex_command )
70-
71- if (CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP)
72- # XIP image, need to use the fixed address for this slot
73- if (CONFIG_NCS_IS_VARIANT_IMAGE )
74- set (imgtool_rom_command --rom-fixed @PM_MCUBOOT_SECONDARY_ADDRESS@ )
75- else ( )
76- set (imgtool_rom_command --rom-fixed @PM_MCUBOOT_PRIMARY_ADDRESS@ )
69+ if (CONFIG_PARTITION_MANAGER_ENABLED )
70+ if (CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP)
71+ # XIP image, need to use the fixed address for this slot
72+ if (CONFIG_NCS_IS_VARIANT_IMAGE)
73+ set (imgtool_rom_command --rom-fixed @PM_MCUBOOT_SECONDARY_ADDRESS@ )
74+ else ( )
75+ set (imgtool_rom_command --rom-fixed @PM_MCUBOOT_PRIMARY_ADDRESS@ )
76+ endif ( )
7777 endif ()
7878
79- if (CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
80- set (imgtool_directxip_hex_command --confirm)
79+ # Split fields, imgtool_sign_sysbuild is stored in cache which will have fields updated by
80+ # sysbuild, imgtool_sign must not be stored in cache because it would then prevent those fields
81+ # from being updated without a pristine build
82+ # TODO: NCSDK-28461 sysbuild PM fields cannot be updated without a pristine build, will become
83+ # invalid if a static PM file is updated without pristine build
84+ set (imgtool_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_rom_command} CACHE STRING "imgtool sign sysbuild replacement" )
85+ set (imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild} )
86+ else ()
87+ set (imgtool_rom_command)
88+ if (CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP)
89+ dt_chosen(code_partition PROPERTY "zephyr,code-partition" )
90+ dt_reg_addr(code_partition_offset PATH "${code_partition} " REQUIRED)
91+ set (imgtool_rom_command --rom-fixed ${code_partition_offset} )
8192 endif ()
93+ set (imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} --slot-size ${slot_size} --header-size ${CONFIG_ROM_START_OFFSET} ${imgtool_rom_command} )
8294 endif ()
8395
84- # Split fields, imgtool_sign_sysbuild is stored in cache which will have fields updated by
85- # sysbuild, imgtool_sign must not be stored in cache because it would then prevent those fields
86- # from being updated without a pristine build
87- # TODO: NCSDK-28461 sysbuild PM fields cannot be updated without a pristine build, will become
88- # invalid if a static PM file is updated without pristine build
89- set (imgtool_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_rom_command} CACHE STRING "imgtool sign sysbuild replacement" )
90- set (imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild} )
96+ set (imgtool_directxip_hex_command)
97+
98+ if (CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
99+ set (imgtool_directxip_hex_command --confirm)
100+ endif ()
91101
92102 # Arguments to imgtool.
93103 if (NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "" )
@@ -197,9 +207,11 @@ function(zephyr_mcuboot_tasks)
197207 set (unconfirmed_args ${input} .hex ${output} .hex)
198208 list (APPEND byproducts ${output} .hex)
199209
200- # Do not run zephyr_runner_file here as PM will provide the merged hex file from
201- # sysbuild's scope unless this is a variant image
202- if (CONFIG_NCS_IS_VARIANT_IMAGE)
210+ # If using partition manager do not run zephyr_runner_file here as PM will
211+ # provide the merged hex file from sysbuild's scope unless this is a variant image
212+ # Otherwise run zephyr_runner_file for both images to ensure the signed hex file
213+ # is used for flashing
214+ if ((NOT CONFIG_PARTITION_MANAGER_ENABLED) OR CONFIG_NCS_IS_VARIANT_IMAGE)
203215 zephyr_runner_file(hex ${output} .hex)
204216 endif ()
205217
0 commit comments