zephry: 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/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c
index b4d0a3e..7c41f8b 100644
--- a/boot/zephyr/flash_map_extended.c
+++ b/boot/zephyr/flash_map_extended.c
@@ -135,3 +135,24 @@
(void)fap;
return ERASED_VAL;
}
+
+int flash_area_get_sector(const struct flash_area *fap, off_t off,
+ struct flash_sector *fsp)
+{
+ struct flash_pages_info fpi;
+ int rc;
+
+ if (off >= fap->fa_size) {
+ return -ERANGE;
+ }
+
+ rc = flash_get_page_info_by_offs(fap->fa_dev, fap->fa_off + off,
+ &fpi);
+
+ if (rc == 0) {
+ fsp->fs_off = fpi.start_offset - fap->fa_off;
+ fsp->fs_size = fpi.size;
+ }
+
+ return rc;
+}
diff --git a/boot/zephyr/include/flash_map_backend/flash_map_backend.h b/boot/zephyr/include/flash_map_backend/flash_map_backend.h
index fa08ac4..e5408a1 100644
--- a/boot/zephyr/include/flash_map_backend/flash_map_backend.h
+++ b/boot/zephyr/include/flash_map_backend/flash_map_backend.h
@@ -95,6 +95,17 @@
return fs->fs_size;
}
+/* Retrieve the flash sector withing given flash area, at a given offset.
+ *
+ * @param fa flash area where the sector is taken from.
+ * @param off offset within flash area.
+ * @param sector structure of sector information.
+ * Returns 0 on success, -ERANGE if @p off is beyond flash area size,
+ * other negative errno code on failure.
+ */
+int flash_area_get_sector(const struct flash_area *fa, off_t off,
+ struct flash_sector *fs);
+
#ifdef __cplusplus
}
#endif