Replace mcuboot flash_map by zephyr flash_map

The patch introduce usage of zephyr flas_map module instead
of mcuboot zephyr-only implementation. Unused flash_area_to_sectors
API of former flash_map was removed as well.
Size of sector-status-update-map entry is now defined thanks to the
minimum write size supported by the flash driver.

For avoid ambiguity former zephyr-only files flash_map.c
were renamed to flash_map_extended.c (its code now implements
only addition to this what zephyr flash_map implements).

flash_map.h header include is now warped by flash_map_backedn.h headre
because implementations and include pathes are diferent in Zephyr and Mynewt.

Usage of hal_flash_align() were replaced by usage flash_area_align().
This provide consistency between MyNewt and Zephyr implementation as
this API is available in both RTOSes.

flash_map.h was moved to the simulator c-support files as now missing in
the boot/zephyr subdirectories.

f. boot_scratch_fa_device_id was removed as unused.
f. boot_img_fa_device_id was and expanded the only use of it
(on loader.c).

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/zephyr/flash_map_legacy.c b/boot/zephyr/flash_map_legacy.c
index 2bfa182..e7daa41 100644
--- a/boot/zephyr/flash_map_legacy.c
+++ b/boot/zephyr/flash_map_legacy.c
@@ -40,7 +40,7 @@
 #define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
 #include "bootutil/bootutil_log.h"
 
-#include <flash_map/flash_map.h>
+#include <flash_map_backend/flash_map_backend.h>
 #include <inttypes.h>
 #include <target.h>
 
@@ -50,49 +50,6 @@
 #define FLASH_AREA_IMAGE_SECTOR_SIZE FLASH_AREA_IMAGE_SCRATCH_SIZE
 #endif
 
-extern int flash_area_get_bounds(int idx, uint32_t *off, uint32_t *len);
-
-int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
-{
-    uint32_t off;
-    uint32_t len;
-    uint32_t max_cnt = *cnt;
-    uint32_t rem_len;
-
-    if (flash_area_get_bounds(idx, &off, &len)) {
-        return -1;
-    }
-
-    if (*cnt < 1) {
-        return -1;
-    }
-
-    rem_len = len;
-    *cnt = 0;
-    while (rem_len > 0 && *cnt < max_cnt) {
-        if (rem_len < FLASH_AREA_IMAGE_SECTOR_SIZE) {
-            BOOT_LOG_ERR("area %d size 0x%x not divisible by sector size 0x%x",
-                     idx, len, FLASH_AREA_IMAGE_SECTOR_SIZE);
-            return -1;
-        }
-
-        ret[*cnt].fa_id = idx;
-        ret[*cnt].fa_device_id = 0;
-        ret[*cnt].pad16 = 0;
-        ret[*cnt].fa_off = off + (FLASH_AREA_IMAGE_SECTOR_SIZE * (*cnt));
-        ret[*cnt].fa_size = FLASH_AREA_IMAGE_SECTOR_SIZE;
-        *cnt = *cnt + 1;
-        rem_len -= FLASH_AREA_IMAGE_SECTOR_SIZE;
-    }
-
-    if (*cnt >= max_cnt) {
-        BOOT_LOG_ERR("flash area %d sector count overflow", idx);
-        return -1;
-    }
-
-    return 0;
-}
-
 /*
  * Lookup the sector map for a given flash area.  This should fill in
  * `ret` with all of the sectors in the area.  `*cnt` will be set to
@@ -101,26 +58,29 @@
  */
 int flash_area_get_sectors(int idx, uint32_t *cnt, struct flash_sector *ret)
 {
-    uint32_t off;
-    uint32_t len;
+    const struct flash_area *fa;
     uint32_t max_cnt = *cnt;
     uint32_t rem_len;
+    int rc = -1;
 
-    if (flash_area_get_bounds(idx, &off, &len)) {
-        return -1;
+    if (flash_area_open(idx, &fa))  {
+        goto out;
     }
 
+    BOOT_LOG_DBG("area %d: offset=0x%x, length=0x%x", idx, fa->fa_off,
+                 fa->fa_size);
+
     if (*cnt < 1) {
-        return -1;
+        goto fa_close_out;
     }
 
-    rem_len = len;
+    rem_len = fa->fa_size;
     *cnt = 0;
     while (rem_len > 0 && *cnt < max_cnt) {
         if (rem_len < FLASH_AREA_IMAGE_SECTOR_SIZE) {
             BOOT_LOG_ERR("area %d size 0x%x not divisible by sector size 0x%x",
-                         idx, len, FLASH_AREA_IMAGE_SECTOR_SIZE);
-            return -1;
+                         idx, fa->fa_size, FLASH_AREA_IMAGE_SECTOR_SIZE);
+            goto fa_close_out;
         }
 
         ret[*cnt].fs_off = FLASH_AREA_IMAGE_SECTOR_SIZE * (*cnt);
@@ -131,8 +91,13 @@
 
     if (*cnt >= max_cnt) {
         BOOT_LOG_ERR("flash area %d sector count overflow", idx);
-        return -1;
+        goto fa_close_out;
     }
 
-    return 0;
+    rc = 0;
+
+fa_close_out:
+    flash_area_close(fa);
+out:
+    return rc;
 }