|
57 | 57 |
|
58 | 58 | #ifdef __ZEPHYR__
|
59 | 59 | #include <zephyr/sys/reboot.h>
|
| 60 | +#if defined(CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS) |
| 61 | +#include <zephyr/kernel.h> |
| 62 | +#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS */ |
60 | 63 | #endif
|
61 | 64 |
|
62 | 65 | #if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
|
@@ -862,14 +865,42 @@ boot_image_check(struct boot_loader_state *state, struct image_header *hdr,
|
862 | 865 | }
|
863 | 866 | #endif
|
864 | 867 |
|
| 868 | + for (int i = 1; i <= CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT; i++ ) { |
| 869 | +#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 |
| 870 | + BOOT_LOG_DBG("Image validation attempt %d/%d", i, CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT); |
| 871 | +#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 */ |
| 872 | + |
865 | 873 | #if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_SERIAL_RECOVERY)
|
866 |
| - FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ, |
867 |
| - NULL, 0, NULL, 0); |
| 874 | + FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ, |
| 875 | + NULL, 0, NULL, 0); |
868 | 876 | #else
|
869 |
| - FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ, |
870 |
| - NULL, 0, NULL); |
| 877 | + FIH_CALL(bootutil_img_validate, fih_rc, state, hdr, fap, tmpbuf, BOOT_TMPBUF_SZ, |
| 878 | + NULL, 0, NULL); |
871 | 879 | #endif
|
872 | 880 |
|
| 881 | + if (FIH_EQ(fih_rc, FIH_SUCCESS)) { |
| 882 | +#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 |
| 883 | + BOOT_LOG_DBG("Image validation attempt %d/%d success", i, CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT); |
| 884 | +#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 */ |
| 885 | + break; |
| 886 | + } else { |
| 887 | +#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 |
| 888 | + BOOT_LOG_WRN("Image validation attempt %d/%d failure: %d", |
| 889 | + i, |
| 890 | + CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT, fih_rc); |
| 891 | +#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 */ |
| 892 | + |
| 893 | + if (i < CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT) { |
| 894 | +#if defined(CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS) |
| 895 | +#if CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 |
| 896 | + BOOT_LOG_DBG("Waiting %d ms before next attempt", |
| 897 | + CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS); |
| 898 | +#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_COUNT > 1 */ |
| 899 | + k_busy_wait(CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS * 1000); |
| 900 | +#endif /* CONFIG_NRF_MCUBOOT_IMG_VALIDATE_ATTEMPT_WAIT_MS */ |
| 901 | + } |
| 902 | + } |
| 903 | + } |
873 | 904 | FIH_RET(fih_rc);
|
874 | 905 | }
|
875 | 906 |
|
|
0 commit comments