zephyr: allow dynamic numeration of flash_areas
Zephyr flash_map reworks caused that areas id exact number are
assigned dynamically.
This patch i counterpart to
https://github.com/zephyrproject-rtos/zephyr/pull/8837
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c
index 5098012..0b56eeb 100644
--- a/boot/zephyr/flash_map_extended.c
+++ b/boot/zephyr/flash_map_extended.c
@@ -49,12 +49,20 @@
}
/*
- * This depends on the mappings defined in sysflash.h, and assumes
- * that slot 0, slot 1, and the scratch areas are contiguous.
+ * This depends on the mappings defined in sysflash.h.
+ * MCUBoot uses continuous numbering for slot 0, slot 1, and the scratch
+ * while zephyr might number it differently.
*/
int flash_area_id_from_image_slot(int slot)
{
- return slot + FLASH_AREA_IMAGE_0;
+ static const int area_id_tab[] = {FLASH_AREA_IMAGE_0, FLASH_AREA_IMAGE_1,
+ FLASH_AREA_IMAGE_SCRATCH};
+
+ if (slot >= 0 && slot < ARRAY_SIZE(area_id_tab)) {
+ return area_id_tab[slot];
+ }
+
+ return -EINVAL; /* flash_area_open will fail on that */
}
int flash_area_sector_from_off(off_t off, struct flash_sector *sector)