From 2c52733f8db3bd6db82cf9d5c37e26834a83ed33 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Fri, 28 Oct 2022 12:08:16 +0200 Subject: [PATCH] dfu/boot/mcuboot: treat pristine image as confirmed In case of initial/pre-programed image. Such image can neither be reverted nor physically confirmed. Image like this should be recognized as confirmed by the boot_is_img_confirmed() for consistency. Signed-off-by: Andrzej Puzdrowski --- subsys/dfu/boot/mcuboot.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/subsys/dfu/boot/mcuboot.c b/subsys/dfu/boot/mcuboot.c index 87cf1d3e02eb24..b7da05f9f52230 100644 --- a/subsys/dfu/boot/mcuboot.c +++ b/subsys/dfu/boot/mcuboot.c @@ -185,21 +185,30 @@ int boot_request_upgrade_multi(int image_index, int permanent) bool boot_is_img_confirmed(void) { + struct boot_swap_state state; const struct flash_area *fa; int rc; - uint8_t flag_val; rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fa); if (rc) { return false; } - rc = boot_read_image_ok(fa, &flag_val); - if (rc) { + rc = boot_read_swap_state(fa, &state); + if (rc != 0) { return false; } - return flag_val == BOOT_FLAG_SET; + if (state.magic == BOOT_MAGIC_UNSET) { + /* This is initial/preprogramed image. + * Such image can neither be reverted nor physically confirmed. + * Treat this image as confirmed which ensures consistency + * with `boot_write_img_confirmed...()` procedures. + */ + return true; + } + + return state.image_ok == BOOT_FLAG_SET; } int boot_write_img_confirmed(void)