Boot: Extend flash layout for multiple images
This patch introduces the BOOT_IMAGE_NUMBER macro and current_image
variable to support multiple updatable images and the associated
extended flash layout.
The FLASH_AREA_IMAGE_* object-like macros are replaced with
function-like ones and therefore some functions have been updated,
because the labels of a switch statement and the initialization
values of objects with static storage duration have to be constant
expressions.
Change-Id: Ib7b26ec3c94233e52db4f97825ddb6a3e55bb1d3
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c
index 543a467..535e69a 100644
--- a/boot/zephyr/flash_map_extended.c
+++ b/boot/zephyr/flash_map_extended.c
@@ -55,9 +55,12 @@
*/
int flash_area_id_from_image_slot(int slot)
{
- static const int area_id_tab[] = {FLASH_AREA_IMAGE_PRIMARY,
- FLASH_AREA_IMAGE_SECONDARY,
- FLASH_AREA_IMAGE_SCRATCH};
+#if (MCUBOOT_IMAGE_NUMBER == 1)
+ static
+#endif
+ const int area_id_tab[] = {FLASH_AREA_IMAGE_PRIMARY,
+ FLASH_AREA_IMAGE_SECONDARY,
+ FLASH_AREA_IMAGE_SCRATCH};
if (slot >= 0 && slot < ARRAY_SIZE(area_id_tab)) {
return area_id_tab[slot];
@@ -68,15 +71,15 @@
int flash_area_id_to_image_slot(int area_id)
{
- switch (area_id) {
- case FLASH_AREA_IMAGE_PRIMARY:
+ if (area_id == FLASH_AREA_IMAGE_PRIMARY) {
return 0;
- case FLASH_AREA_IMAGE_SECONDARY:
- return 1;
- default:
- BOOT_LOG_ERR("invalid flash area ID");
- return -1;
}
+ if (area_id == FLASH_AREA_IMAGE_SECONDARY) {
+ return 1;
+ }
+
+ BOOT_LOG_ERR("invalid flash area ID");
+ return -1;
}
int flash_area_sector_from_off(off_t off, struct flash_sector *sector)