From 6c9b416cd88fbc2ad0dec76236d287d254271e86 Mon Sep 17 00:00:00 2001 From: David Vincze Date: Thu, 21 Mar 2019 19:18:08 +0100 Subject: [PATCH] sim: Support non-continuous area ID mapping Support non-continuous image flash area ID mapping. It was assumed that the flash area IDs are subsequent and increasing numbers which might not be true in all cases. Change-Id: I0d1285d6fcf1e83a64611c9ad4f65abd002c25d3 Signed-off-by: David Vincze --- sim/mcuboot-sys/csupport/run.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sim/mcuboot-sys/csupport/run.c b/sim/mcuboot-sys/csupport/run.c index fdee14c1..8f2a01ca 100644 --- a/sim/mcuboot-sys/csupport/run.c +++ b/sim/mcuboot-sys/csupport/run.c @@ -25,6 +25,8 @@ #define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_ERROR #include +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + extern int sim_flash_erase(uint8_t flash_id, uint32_t offset, uint32_t size); extern int sim_flash_read(uint8_t flash_id, uint32_t offset, uint8_t *dest, uint32_t size); @@ -242,7 +244,16 @@ void *os_malloc(size_t size) int flash_area_id_from_image_slot(int slot) { - return slot + 1; + const int area_id_tab[] = {FLASH_AREA_IMAGE_PRIMARY, + FLASH_AREA_IMAGE_SECONDARY, + FLASH_AREA_IMAGE_SCRATCH}; + + if (slot >= 0 && (unsigned)slot < ARRAY_SIZE(area_id_tab)) { + return area_id_tab[slot]; + } + + printf("Image flash area ID not found\n"); + return -1; /* flash_area_open will fail on that */ } int flash_area_open(uint8_t id, const struct flash_area **area)