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/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 0ec8605..0b8b671 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -25,7 +25,9 @@
 #include "sysflash/sysflash.h"
 #include "hal/hal_bsp.h"
 #include "hal/hal_flash.h"
-#include "flash_map/flash_map.h"
+
+#include "flash_map_backend/flash_map_backend.h"
+
 #include "os/os.h"
 #include "bootutil/image.h"
 #include "bootutil/bootutil.h"
@@ -356,7 +358,7 @@
         return BOOT_EBADARGS;
     }
 
-    align = hal_flash_align(fap->fa_device_id);
+    align = flash_area_align(fap);
     assert(align <= BOOT_MAX_ALIGN);
     memset(buf, 0xFF, BOOT_MAX_ALIGN);
     buf[0] = BOOT_FLAG_SET;
@@ -390,7 +392,7 @@
     uint8_t align;
 
     off = boot_swap_size_off(fap);
-    align = hal_flash_align(fap->fa_device_id);
+    align = flash_area_align(fap);
     assert(align <= BOOT_MAX_ALIGN);
     if (align < sizeof swap_size) {
         align = sizeof swap_size;
diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h
index d2ee6fc..c5c23aa 100644
--- a/boot/bootutil/src/bootutil_priv.h
+++ b/boot/bootutil/src/bootutil_priv.h
@@ -21,7 +21,9 @@
 #define H_BOOTUTIL_PRIV_
 
 #include "sysflash/sysflash.h"
-#include "flash_map/flash_map.h"
+
+#include <flash_map_backend/flash_map_backend.h>
+
 #include "bootutil/image.h"
 #include "mcuboot_config/mcuboot_config.h"
 
@@ -181,18 +183,6 @@
     return &state->imgs[slot].hdr;
 }
 
-static inline uint8_t
-boot_img_fa_device_id(struct boot_loader_state *state, size_t slot)
-{
-    return state->imgs[slot].area->fa_device_id;
-}
-
-static inline uint8_t
-boot_scratch_fa_device_id(struct boot_loader_state *state)
-{
-    return state->scratch_area->fa_device_id;
-}
-
 static inline size_t
 boot_img_num_sectors(struct boot_loader_state *state, size_t slot)
 {
diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c
index 496ed27..f9dcde3 100644
--- a/boot/bootutil/src/image_validate.c
+++ b/boot/bootutil/src/image_validate.c
@@ -23,7 +23,9 @@
 #include <string.h>
 
 #include "hal/hal_flash.h"
-#include "flash_map/flash_map.h"
+
+#include <flash_map_backend/flash_map_backend.h>
+
 #include "bootutil/image.h"
 #include "bootutil/sha256.h"
 #include "bootutil/sign_key.h"
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index a76d056..a08bda2 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -318,8 +318,8 @@
      * on what the minimum write size is for scratch area, active image slot.
      * We need to use the bigger of those 2 values.
      */
-    elem_sz = hal_flash_align(boot_img_fa_device_id(&boot_data, 0));
-    align = hal_flash_align(boot_scratch_fa_device_id(&boot_data));
+    elem_sz = flash_area_align(boot_data.imgs[0].area);
+    align = flash_area_align(boot_data.scratch_area);
     if (align > elem_sz) {
         elem_sz = align;
     }
@@ -547,8 +547,7 @@
     off = boot_status_off(fap) +
           boot_status_internal_off(bs->idx, bs->state,
                                    BOOT_WRITE_SZ(&boot_data));
-
-    align = hal_flash_align(fap->fa_device_id);
+    align = flash_area_align(fap);
     memset(buf, 0xFF, BOOT_MAX_ALIGN);
     buf[0] = bs->state;
 
@@ -1451,7 +1450,7 @@
 #endif
 
     /* Always boot from the primary slot. */
-    rsp->br_flash_dev_id = boot_img_fa_device_id(&boot_data, 0);
+    rsp->br_flash_dev_id = boot_data.imgs[0].area->fa_device_id;
     rsp->br_image_off = boot_img_slot_off(&boot_data, 0);
     rsp->br_hdr = boot_img_hdr(&boot_data, slot);