Skip to content

Commit

Permalink
bootutil: Provide flash_area_to_image
Browse files Browse the repository at this point in the history
The flash_area_id_to_image has been replaced with flash_area_to_image
that moves flash_area_get_id inside the flash_area_id_to_image
and changes the logic so that it is now independent from
image numbers and should not require updates when BOOT_IMAGE_NUMBER
gets increased.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
de-nordic committed Aug 7, 2023
1 parent 0540d0f commit a538a17
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions boot/bootutil/src/bootutil_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,18 @@ boot_swap_type_multi(int image_index)
return BOOT_SWAP_TYPE_NONE;
}

static int flash_area_id_to_image(int id)
static int flash_area_to_image(const struct flash_area *fa)
{
#if BOOT_IMAGE_NUMBER > 2
#error "BOOT_IMAGE_NUMBER > 2 requires change to flash_area_id_to_image"
#elif BOOT_IMAGE_NUMBER > 1
if (FLASH_AREA_IMAGE_PRIMARY(1) == id || (FLASH_AREA_IMAGE_SECONDARY(1) == id)) {
return 1;
int i = 0;
int id = flash_area_get_id(fa);

while (BOOT_IMAGE_NUMBER > 1 && i < BOOT_IMAGE_NUMBER) {
if (FLASH_AREA_IMAGE_PRIMARY(i) == id || (FLASH_AREA_IMAGE_SECONDARY(i) == id)) {
break;
}
++i;
}
#else
(void)id;
#endif
return 0;
return i;
}

int
Expand Down Expand Up @@ -517,8 +517,7 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
} else {
swap_type = BOOT_SWAP_TYPE_TEST;
}
rc = boot_write_swap_info(fa, swap_type,
flash_area_id_to_image(flash_area_get_id(fa)));
rc = boot_write_swap_info(fa, swap_type, flash_area_to_image(fa));
}
}
break;
Expand Down

0 comments on commit a538a17

Please sign in to comment.