Skip to content

Commit 6c9b416

Browse files
davidvinczed3zd3z
authored andcommitted
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 <[email protected]>
1 parent e245347 commit 6c9b416

File tree

1 file changed

+12
-1
lines changed
  • sim/mcuboot-sys/csupport

1 file changed

+12
-1
lines changed

sim/mcuboot-sys/csupport/run.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_ERROR
2626
#include <bootutil/bootutil_log.h>
2727

28+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29+
2830
extern int sim_flash_erase(uint8_t flash_id, uint32_t offset, uint32_t size);
2931
extern int sim_flash_read(uint8_t flash_id, uint32_t offset, uint8_t *dest,
3032
uint32_t size);
@@ -242,7 +244,16 @@ void *os_malloc(size_t size)
242244

243245
int flash_area_id_from_image_slot(int slot)
244246
{
245-
return slot + 1;
247+
const int area_id_tab[] = {FLASH_AREA_IMAGE_PRIMARY,
248+
FLASH_AREA_IMAGE_SECONDARY,
249+
FLASH_AREA_IMAGE_SCRATCH};
250+
251+
if (slot >= 0 && (unsigned)slot < ARRAY_SIZE(area_id_tab)) {
252+
return area_id_tab[slot];
253+
}
254+
255+
printf("Image flash area ID not found\n");
256+
return -1; /* flash_area_open will fail on that */
246257
}
247258

248259
int flash_area_open(uint8_t id, const struct flash_area **area)

0 commit comments

Comments
 (0)