Skip to content

[nrf noup] boot: Introduce retry mechanism for image verification #467

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adsz-nordic
Copy link

@adsz-nordic adsz-nordic commented Jul 8, 2025

Intended mainly for direct-xip mode.
Allows to control:

  • number of image validation attempts performed before considering the image invalid
  • time before next attempt is made

This is requested by customer who doesn't like the fact that a single, temporary bit flip may lead to deletion of an image.

@maciejpietras maciejpietras requested a review from nvlsianpu July 8, 2025 07:18
@adsz-nordic adsz-nordic changed the title boot: Introduce retry mechanism for image verification [nrf noup] boot: Introduce retry mechanism for image verification Jul 8, 2025
Copy link
Contributor

@nvlsianpu nvlsianpu left a comment

Choose a reason for hiding this comment

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

I'm fine with this feature.

@adsz-nordic adsz-nordic marked this pull request as ready for review July 11, 2025 05:17
@@ -1213,4 +1213,22 @@ config MCUBOOT_VERIFY_IMG_ADDRESS
also be useful when BOOT_DIRECT_XIP is enabled, to ensure that the image
linked at the correct address is loaded.


config MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we standardize to use NRF_ prefix on MCUboot options that are added as NRF noup things?
Here it would be NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT. This way we can avoid any collisions with upstream added features.

Copy link
Author

Choose a reason for hiding this comment

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

My initial thought was that the PR was going to be "noup" but that has changed and PR needs to go to upstream. Sorry for confusion - I am going to update the tag and description.
I presume the config name will not need a change in such case, right?

Copy link
Author

Choose a reason for hiding this comment

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

It turns out that after all, this PR is going to be downstream-only.
I applied the suggested changes.
Please review again.

@adsz-nordic
Copy link
Author

adsz-nordic commented Jul 14, 2025

It turns out that this feature will be added only for downstream.
PR for mcuboot revision update in sdk-nrf: nrfconnect/sdk-nrf#23291

@adsz-nordic adsz-nordic requested a review from de-nordic July 14, 2025 12:16
Comment on lines +870 to +887
BOOT_LOG_DBG("Image validation attempt %d/%d", i, CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT);
#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 */

#if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_SERIAL_RECOVERY)
FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ,
NULL, 0, NULL, 0);
FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ,
NULL, 0, NULL, 0);
#else
FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ,
NULL, 0, NULL);
FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ,
NULL, 0, NULL);
#endif

if (FIH_EQ(fih_rc, FIH_SUCCESS)) {
#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1
BOOT_LOG_DBG("Image validation attempt %d/%d success", i, CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT);
#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 */
break;
} else {
#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1
Copy link
Contributor

Choose a reason for hiding this comment

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

As per upstream comments, only show messages if NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1

Copy link
Author

Choose a reason for hiding this comment

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

I thought you only meant messages showing attempt numbers, not all the messages.
Now each new log will be wrapped with #if, although this reduces readability of code.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's already output by other functions if this function fails so doesn't make sense to duplicate it again here

break;
} else {
#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1
BOOT_LOG_WRN("Image validation attempt %d/%d failure: %d", i, CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT, fih_rc);
Copy link
Contributor

Choose a reason for hiding this comment

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

line too long

Copy link
Author

Choose a reason for hiding this comment

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

Changed. Are there no automatic CI jobs for checks like this for mcuboot?

Copy link
Contributor

Choose a reason for hiding this comment

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

there isn't since checkpatch which zepyhyr uses is a linux kernel script (and has so many issues)

Intended mainly for direct-xip mode.
Allows to control:
- number of image validation attempts performed before considering the image invalid
- time before next attempt is made

Signed-off-by: Adam Szczygieł <adam.szczygiel@nordicsemi.no>
Copy link

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.

6 participants