Skip to content

Commit

Permalink
dfu/boot/mcuboot: treat pristine image as confirmed
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nvlsianpu authored and carlescufi committed Nov 7, 2022
1 parent 8665db1 commit 2c52733
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions subsys/dfu/boot/mcuboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c52733

Please sign in to comment.