From 60399f69fb9a4996cd8102fa06a799cfbed40734 Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 11 May 2017 10:20:34 -0600 Subject: [PATCH] sim: Implement flash_area_get_sectors for sim Implement the new flash sector query API for the simulator. This is generated from the data for the deprecated API. Once the old API is removed, the flash simulator can be changed to just return the new data directly. Signed-off-by: David Brown Signed-off-by: Marti Bolivar --- sim/csupport/run.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/sim/csupport/run.c b/sim/csupport/run.c index 5d6f6510..dc44c312 100644 --- a/sim/csupport/run.c +++ b/sim/csupport/run.c @@ -188,6 +188,37 @@ int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret) return 0; } +int flash_area_get_sectors(int fa_id, uint32_t *count, + struct flash_sector *sectors) +{ + int i; + struct area *slot; + + for (i = 0; i < flash_areas->num_slots; i++) { + if (flash_areas->slots[i].id == fa_id) + break; + } + if (i == flash_areas->num_slots) { + printf("Unsupported area\n"); + abort(); + } + + slot = &flash_areas->slots[i]; + + if (slot->num_areas > *count) { + printf("Too many areas in slot\n"); + abort(); + } + + for (i = 0; i < slot->num_areas; i++) { + sectors[i].fs_off = slot->areas[i].fa_off - + slot->whole.fa_off; + sectors[i].fs_size = slot->areas[i].fa_size; + } + *count = slot->num_areas; + + return 0; +} int bootutil_img_validate(struct image_header *hdr, const struct flash_area *fap,