zephyr: erase flash pages progressively

This commit adds the option to erase flash pages while receiving
the firmware, opposed to bulk-erasing the whole image area at
the beginning of the DFU process. This is required on some
hardware that has long erase times, to prevent a long wait
and possibly a timeout during DFU.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c
index ee2320c..7133c99 100644
--- a/boot/zephyr/flash_map_extended.c
+++ b/boot/zephyr/flash_map_extended.c
@@ -11,7 +11,6 @@
 #include "target.h"
 
 #include <flash_map_backend/flash_map_backend.h>
-#include <hal/hal_flash.h>
 #include <sysflash/sysflash.h>
 
 #include "bootutil/bootutil_log.h"
@@ -24,6 +23,16 @@
 #define FLASH_DEVICE_ID SOC_FLASH_0_ID
 #define FLASH_DEVICE_BASE CONFIG_FLASH_BASE_ADDRESS
 
+static struct device *flash_dev;
+
+struct device *flash_device_get_binding(char *dev_name)
+{
+    if (!flash_dev) {
+        flash_dev = device_get_binding(dev_name);
+    }
+    return flash_dev;
+}
+
 int flash_device_base(uint8_t fd_id, uintptr_t *ret)
 {
     if (fd_id != FLASH_DEVICE_ID) {
@@ -43,3 +52,19 @@
 {
     return slot + FLASH_AREA_IMAGE_0;
 }
+
+int flash_area_sector_from_off(off_t off, struct flash_sector *sector)
+{
+    int rc;
+    struct flash_pages_info page;
+
+    rc = flash_get_page_info_by_offs(flash_dev, off, &page);
+    if (rc) {
+        return rc;
+    }
+
+    sector->fs_off = page.start_offset;
+    sector->fs_size = page.size;
+
+    return rc;
+}
\ No newline at end of file