-
Notifications
You must be signed in to change notification settings - Fork 247
[nrf noup] boot/bootutil/loader: image discovery by ih_load_address #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
dda8a3b to
db3fe90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a configuration option to use the image header’s load address for slot discovery instead of the reset handler address.
- Introduce
MCUBOOT_USE_CHECK_LOAD_ADDRKconfig option and adjust dependencies forMCUBOOT_VERIFY_IMG_ADDRESS - Refactor
boot_validate_slotandboot_validated_swap_typeto readih_load_addrwhen enabled - Define new
IS_IN_RANGE_*macros for address range checks
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| boot/zephyr/Kconfig | Add new config MCUBOOT_USE_CHECK_LOAD_ADDR and update dependencies |
| boot/bootutil/src/loader.c | Conditional read of ih_load_addr, macro definitions, and slot validation updates |
Comments suppressed due to low confidence (3)
boot/bootutil/src/loader.c:1264
- Mismatched
#ifdef/#elseguards—this#elsedoes not match the preceding#ifdef CONFIG_MCUBOOT_USE_CHECK_LOAD_ADDRcorrectly and will break compilation.
#else /* BOOT_USE_CHECK_LOAD_ADDR */
boot/bootutil/src/loader.c:1522
- Extra closing parenthesis in macro definition leads to a syntax error; remove the surplus
)at the end.
#define IS_IN_RANGE_CPUNET_APP_ADDR(_addr) ((_addr) >= PM_CPUNET_APP_ADDRESS && (_addr) < PM_CPUNET_APP_END_ADDRESS))
boot/bootutil/src/loader.c:1595
- The
IS_IN_RANGE_S_VARIANT_ADDRmacro expects two parameters but is invoked with one; useIS_IN_RANGE_S_ALTERNATE_ADDRorIS_IN_RANGE_S_CURRENT_ADDRinstead.
if (IS_IN_RANGE_S_VARIANT_ADDR(internal_img_addr)) {
boot/zephyr/Kconfig
Outdated
| If y, the bootloader will use the load address form image header | ||
| for checking to which slot image belongs instead of usage of reset | ||
| handler addres reading form the image. |
Copilot
AI
Jul 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Typo in help text: replace “form image header” with “from image header” and correct “addres” to “address”.
| If y, the bootloader will use the load address form image header | |
| for checking to which slot image belongs instead of usage of reset | |
| handler addres reading form the image. | |
| If y, the bootloader will use the load address from image header | |
| for checking to which slot image belongs instead of usage of reset | |
| handler address reading from the image. |
db3fe90 to
2fb0029
Compare
2fb0029 to
5155061
Compare
|
nordicjm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add nrf-squash! [nrf noup] treewide: Add support for sysbuild assigned images to commit message
boot/bootutil/src/loader.c
Outdated
| struct image_header *secondary_hdr = boot_img_hdr(state, slot); | ||
| uint32_t reset_value = 0; | ||
| uint32_t reset_addr = secondary_hdr->ih_hdr_size + sizeof(reset_value); | ||
| uint32_t internal_img_addr = 0; /* either the reset handler addres or the image beginning addres */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*address
boot/zephyr/Kconfig
Outdated
| bool | ||
|
|
||
| config MCUBOOT_USE_CHECK_LOAD_ADDR | ||
| bool "use check of load address" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| bool "use check of load address" | |
| bool "Use check of load address" |
if we're adding to all new images, do we want to default y this? Or I guess not right away so other things e.g. qspi xip can be updated
boot/bootutil/src/loader.c
Outdated
|
|
||
| #define IS_IN_RANGE_CPUNET_APP_ADDR(_addr) ((_addr) >= PM_CPUNET_APP_ADDRESS && (_addr) < PM_CPUNET_APP_END_ADDRESS) | ||
| #define _IS_IN_RANGE_S_VARIANT_ADDR(_addr, x) ((_addr) >= PM_S##x_ADDRESS && (_addr) <= (PM_S##x_ADDRESS + PM_S##x_SIZE)) | ||
| #if (CONFIG_NCS_IS_VARIANT_IMAGE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ifdef
5155061 to
aa627f8
Compare
aa627f8 to
900c495
Compare
566d3f3 to
e1d9d3f
Compare
Application need special support in the bootloader in order to resume for suspend to RAM. MCUboot is immediate actor which redirects execution to the application (application reset vector) when wake-up from S2RAM is detected. Detection is based on HW (NRF_RESETINFO) and hardened using additional check over independent source of truth (variable with magic value). Thanks to above the application is resuming using its routines - instead of mocking that by routines compiled in by the MCUboot. Implementation is able to support only MCUboot modes with a swap. Direct-XIP is not handled as it require a way to run-time recognization of active application slot. Signed-off-by: Karol Lasończyk <[email protected]> Signed-off-by: Tomasz Chyrowicz <[email protected]> Signed-off-by: Andrzej Puzdrowski <[email protected]>
Added configuration which pre-configures MCUboot so It is able to support operation of resuming the App from S2RAM by the application itself. Signed-off-by: Andrzej Puzdrowski <[email protected]>
Previously reopening of PR did not reopen manifest PR. This commit will enable reopening of manifest PR in such case. Signed-off-by: Kari Hamalainen <[email protected]>
This reverts commit d0796dc. Signed-off-by: Jukka Rissanen <[email protected]>
This reverts commit c390295. Signed-off-by: Jukka Rissanen <[email protected]>
This reverts commit b26db4d. Signed-off-by: Jukka Rissanen <[email protected]>
89a583a to
2d42059
Compare
Use the dedicated type to specify the slot number. Signed-off-by: Tomasz Chyrowicz <[email protected]> (cherry picked from commit d5b0dcb9aaee397fc105ae2228e8030038c3d871)
nrf-squash! [nrf noup] bootloader: Add bootloader requests Change bootloader request module, so it uses the new, dedicated type to point to the specific slot. Ref: NCSDK-35199 Signed-off-by: Tomasz Chyrowicz <[email protected]>
fixes missing array bug. Signed-off-by: Mateusz Michalek <[email protected]> (cherry picked from commit 5e1be19fbc2afde8f7a6eb2ad8e3b31e5c3921cd)
bd80231 to
e4fd441
Compare
Fix uninitialized variable warning as well as compile time issue, when the slotted dependencies are enabled. Signed-off-by: Tomasz Chyrowicz <[email protected]> (cherry picked from commit 9ca088179e611ebd0054b0ef503039132c7a0ad1)
nrf-squash! [nrf noup] bootloader: Add bootloader requests Fix a warning for uninitialized variable. Ref: NCSDK-35733 Signed-off-by: Tomasz Chyrowicz <[email protected]>
If a device uses RESETINFO, than there are some bits set in the resetinfo, even for reboots that should allow to interpret and enter the device recovery. That way it is possible to recover a device through serial recovery if the main application resets due to i.e. watchdog. Signed-off-by: Tomasz Chyrowicz <[email protected]> (cherry picked from commit cc9852984f799d8d992594f966c472173925731f)
e4fd441 to
3b21cec
Compare
Added direct-xip support: * new API for marking active slot to be used by boot_go() routines. * jump vector assignment which is basing on above designation. Signed-off-by: Andrzej Puzdrowski <[email protected]>
Added call which designate active slot so MCUBoot can jump to proper slot when CPU is resuming from S2RAM. Signed-off-by: Andrzej Puzdrowski <[email protected]>
nrf-squash! [nrf noup] bootutil: Add support for KMU stored ED25519 signature key Will instead use the immutable bootloader key slot IDs if b0 is not enabled, adds a Kconfig which can be used to fall back to the previous slot IDs for previously deployed bootloaders Signed-off-by: Jamie McCrae <[email protected]>
6460f21 to
4752c56
Compare
nrf-squash! [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM (hardened) CONFIG_ARM_SOC_START_HOOK=y allow to rework the resume from S2RAM code to work without PM_S2RAM mocking. It allows to implement only what really needed from the MCUboot perspective. Signed-off-by: Andrzej Puzdrowski <[email protected]>
nrf-squash! [nrf noup] boot/zephyr/socs: nrf54h20 prj.conf for S2RAM Updated in order to use optimized configuration. Signed-off-by: Andrzej Puzdrowski <[email protected]>
0f013f2 to
d91e83e
Compare
nrf-squash! [nrf noup] treewide: Add support for sysbuild assigned images Introduce alternative procedure for detecting to which partition image candidate belongs. This method uses ih_load_address field of the image header instead of reset vector address. This allows to match incoming image to the partition even when it is for instance encrypted, as the image header is always plain-text. This new procedure can be enabled using CONFIG_MCUBOOT_CHECK_HEADER_LOAD_ADDRES =y. Firmware need to be signed with imgtool.py sign --rom-fixed <partition_address> parameter. ref.: NCSIDB-1173 Signed-off-by: Andrzej Puzdrowski <[email protected]>
d91e83e to
6435279
Compare
|
| */ | ||
| #ifdef PM_CPUNET_APP_ADDRESS | ||
| if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER) { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| check_addresses = true; | ||
| } else | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
| #endif /* CHECK_MCUBOOT_IMAGE */ | ||
|
|
||
| #if CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER != -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER != -1 |
there is always an app update image
| #endif | ||
| check_addresses = true; | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #endif |
| #else | ||
| min_addr = pri_fa->fa_off; | ||
| max_addr = pri_fa->fa_off + pri_fa->fa_size; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if CHECK_MCUBOOT_IMAGE == 1 | ||
| min_addr = MIN(min_addr, NCS_VARIANT_SLOT_MIN_ADDR); | ||
| max_addr = MAX(max_addr, NCS_VARIANT_SLOT_MAX_ADDR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to preset an unintended side effect, an image that spans across both the s0/s1 and the application partitions would pass this validation
| BOOT_LOG_ERR("Cleaned-up secondary slot of image %d", BOOT_CURR_IMG(state)); | ||
| return BOOT_SWAP_TYPE_FAIL; | ||
| } else if (reset_addr < primary_fa->fa_off || reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) { | ||
| } else if (!IS_IN_RANGE_IMAGE_ADDR(internal_img_addr, primary_fa)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the primary and secondary slots are located in e.g. SPI or QSPI? This is how QSPI XIP split image support works and an upcoming extra DFU slot system will work



Introduce alternative procedure for detecting to which partition
image candidate belongs. This method uses ih_load_address field of the
image header instead of reset vector address. This allows to match
incoming image to the partition even when it is for instance encrypted,
as the image header is always plain-text.
This new procedure can be enabled using
CONFIG_MCUBOOT_USE_CHECK_LOAD_ADDR=y. Firmware need to be signed with
imgtool.py sign --rom-fixed <partition_address> parameter.
ref.: NCSIDB-1173
manifest-pr-skip