sim: Add flash_area_get_sector

Commits adds implementation of flash_area_get_sector that
is supposed to replace flash_area_sector_from_off.
The flash_area_get_sector gets additional parameter of flash_area
type, while flash_area_sector_from_off uses hardcoded flash_area.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/sim/mcuboot-sys/csupport/run.c b/sim/mcuboot-sys/csupport/run.c
index df62cb4..9868996 100644
--- a/sim/mcuboot-sys/csupport/run.c
+++ b/sim/mcuboot-sys/csupport/run.c
@@ -481,6 +481,40 @@
     return (i < slot->num_areas) ? 0 : -1;
 }
 
+int flash_area_get_sector(const struct flash_area *fa, uint32_t off,
+                          struct flash_sector *sector)
+{
+    uint32_t i, sec_off, sec_size;
+    struct area *slot;
+    struct area_desc *flash_areas;
+
+    flash_areas = sim_get_flash_areas();
+    for (i = 0; i < flash_areas->num_slots; i++) {
+        if (&flash_areas->slots[i].whole == fa)
+            break;
+    }
+
+    if (i == flash_areas->num_slots) {
+        printf("Unsupported area\n");
+        abort();
+    }
+
+    slot = &flash_areas->slots[i];
+
+    for (i = 0; i < slot->num_areas; i++) {
+        sec_off = slot->areas[i].fa_off - slot->whole.fa_off;
+        sec_size = slot->areas[i].fa_size;
+
+        if (off >= sec_off && off < (sec_off + sec_size)) {
+            sector->fs_off = sec_off;
+            sector->fs_size = sec_size;
+            break;
+        }
+    }
+
+    return (i < slot->num_areas) ? 0 : -1;
+}
+
 void sim_assert(int x, const char *assertion, const char *file, unsigned int line, const char *function)
 {
     if (!(x)) {
diff --git a/sim/mcuboot-sys/csupport/storage/flash_map.h b/sim/mcuboot-sys/csupport/storage/flash_map.h
index bf53b2a..1c54597 100644
--- a/sim/mcuboot-sys/csupport/storage/flash_map.h
+++ b/sim/mcuboot-sys/csupport/storage/flash_map.h
@@ -143,6 +143,16 @@
  */
 int flash_area_sector_from_off(uint32_t off, struct flash_sector *sector);
 
+/* Retrieve the flash sector a given offset, within flash area.
+ *
+ * @param fa        flash area.
+ * @param off       offset of sector.
+ * @param sector    pointer to structure for obtained information.
+ * Returns 0 on success, or an error code on failure.
+ */
+int flash_area_get_sector(const struct flash_area *fa, uint32_t off,
+  struct flash_sector *sector);
+
 /*
  * Similar to flash_area_get_sectors(), but return the values in an
  * array of struct flash_area instead.