Skip to content

Conversation

tomchy
Copy link
Contributor

@tomchy tomchy commented Jul 24, 2025

In some cases, a Zephyr platform is not able to use the RAM-based retention subsystem. This results in no ability to communicate with the bootloader to:

  • Request the recovery mode from the main application
  • Request the firmware loader mode from the main application

The other case in which the application wants to communicate with the bootloader are platforms that want to have the active slot configured as read-only. In such case, the following flow can be introduced to mitigate this restriction:

  • The main application sends a request to the bootloader informing which image should be confirmed.
  • The main application reboots the device.
  • The device reboots and resets memory permissions so that the bootloader can perform the updates.
  • In the permitted state, the bootloader processes the confirmation requests, before analyzing the state of the slots.
  • The bootloader continues the logic as if the application had confirmed the slot.

There is also a third use case for the application requests in the Direct XIP mode:

  • Currently, the decision of which slot to boot is based only on the version number.
  • Even if there are two valid slots on the device, a user cannot request a temporary rollback to the previous firmware.
  • By introducing a request for slot preference, the slot selection logic may be extended with custom logic that runs as part of the main application and sends such a request to the bootloader to alter the default behavior.

This PR introduces an API that can be used to collect all of the above requests in a single module.
The Kconfig to select or extend the boot request format is located in the configuration file of the mcuboot module in the Zephyr repository.
In addition, a simple integration with bootutil library is included, allowing this feature to be used with an existing MCUmgr implementation.

manifest-pr-skip

@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from 832b4c9 to ce1a921 Compare July 25, 2025 12:15
@tomchy tomchy requested a review from ahasztag July 25, 2025 12:23
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from ce1a921 to f6f21a3 Compare July 28, 2025 10:50
@tomchy tomchy marked this pull request as ready for review July 28, 2025 11:07
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from f6f21a3 to 0b5d331 Compare July 28, 2025 14:30
@tomchy tomchy requested a review from nordicjm July 28, 2025 14:34
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from 0b5d331 to 911bb8c Compare July 29, 2025 09:38
@tomchy tomchy requested a review from ahasztag July 29, 2025 09:38
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from 911bb8c to 2be0d3d Compare July 29, 2025 10:31
@tomchy tomchy requested a review from ahasztag July 29, 2025 10:35
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch 3 times, most recently from 4e1ece5 to 9be377a Compare July 31, 2025 14:48
* @return 0 on success; nonzero on failure.
*/
static int
boot_request_slot_find(enum boot_request_type type, boot_request_img_t image, size_t *slot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slot term is used for image partitions in MCUboot.
Can we have different name there - index, reqest_idx, req_idx, entry_idx?
And so one for any code related to request entries?

Copy link
Contributor Author

@tomchy tomchy Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to go with the entry name instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wonder whether flash_area_to_image() -> flash_area_to_image() can more associated with a upstream patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet I do not have an argument, why this change is needed there...

@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch 2 times, most recently from ad1c9eb to dc8f8c6 Compare August 1, 2025 11:14
@tomchy tomchy requested review from nordicjm and nvlsianpu August 1, 2025 11:21
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from dc8f8c6 to cb3eee7 Compare August 1, 2025 14:16
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from cb3eee7 to 0ac02e0 Compare August 1, 2025 15:19
@ahasztag ahasztag force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch 3 times, most recently from 17ac549 to 3e1a300 Compare August 19, 2025 15:12
tomchy added 3 commits August 28, 2025 12:44
Add a bootloader hook to alter the logic of the active slot selection in
Direct XIP modes.

Signed-off-by: Tomasz Chyrowicz <[email protected]>
(cherry picked from commit 7c4ec9a)
Add a Kconfig option to enable a bootloader hook to alter
the logic of the active slot selection in Direct XIP modes.

Signed-off-by: Tomasz Chyrowicz <[email protected]>
(cherry picked from commit d5f84b4)
Add a capability inside the Zephyr bootloader to handle memory-based
bootloader requests to:
 - Boot recovery firmware
 - Boot firmware loader
 - Confirm an image
 - Set the slot preference

Ref: NCSDK-34429

Signed-off-by: Tomasz Chyrowicz <[email protected]>
@tomchy tomchy force-pushed the feature/zephyr/NCSDK-NONE_boot_requests_nrf branch from 3e1a300 to f5c7d73 Compare August 28, 2025 10:44
Copy link

@anangl anangl merged commit e1f2ab3 into nrfconnect:main Aug 29, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants