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 <david.brown@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
diff --git a/sim/csupport/run.c b/sim/csupport/run.c
index 5d6f651..dc44c31 100644
--- a/sim/csupport/run.c
+++ b/sim/csupport/run.c
@@ -188,6 +188,37 @@
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,