Boot: Sync MCUBoot code base

The MCUBoot files were added from the original MCUBoot
repository with version 1.0.0 and since then the code bases
have diverged from each other significantly. This patch
performs a partial synchronization between the MCUBoot files
in TF-M and in the original repo.
The hash of source commit in the original MCUBoot repo:
178be54bd6e5f035cc60e98205535682acd26e64.

The flash interface has also been extended and this patch
includes the implementation of these new functions too.

Change-Id: I16897ba884b56f90c9d35f99b709de86704a11ad
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/bl2/ext/mcuboot/flash_map.c b/bl2/ext/mcuboot/flash_map.c
index b476517..09d0ad0 100644
--- a/bl2/ext/mcuboot/flash_map.c
+++ b/bl2/ext/mcuboot/flash_map.c
@@ -17,6 +17,13 @@
  * under the License.
  */
 
+/*
+ * Original code taken from mcuboot project at:
+ * https://github.com/JuulLabs-OSS/mcuboot
+ * Git SHA of the original version: b69841820462fa0227d7fb407620405f6426bb4b
+ * Modifications are Copyright (c) 2018-2019 Arm Limited.
+ */
+
 #include <errno.h>
 #include <stdbool.h>
 
@@ -155,13 +162,46 @@
     }
 }
 
-int flash_area_read(const struct flash_area *area, uint32_t off, void *dst,
-            uint32_t len)
+uint8_t flash_area_erased_val(const struct flash_area *area)
 {
-    BOOT_LOG_DBG("read  area=%d, off=%#x, len=%#x", area->fa_id, off, len);
+    (void)area;
+
+    return FLASH_DEV_NAME.GetInfo()->erased_value;
+}
+
+int flash_area_read(const struct flash_area *area, uint32_t off, void *dst,
+                    uint32_t len)
+{
+    BOOT_LOG_DBG("read area=%d, off=%#x, len=%#x", area->fa_id, off, len);
     return FLASH_DEV_NAME.ReadData(area->fa_off + off, dst, len);
 }
 
+int flash_area_read_is_empty(const struct flash_area *area, uint32_t off,
+                             void *dst, uint32_t len)
+{
+    uint32_t i;
+    uint8_t *u8dst;
+    int rc;
+
+    BOOT_LOG_DBG("read_is_empty area=%d, off=%#x, len=%#x",
+                 area->fa_id, off, len);
+
+    rc = FLASH_DEV_NAME.ReadData(area->fa_off + off, dst, len);
+    if(rc != 0) {
+        return -1;
+    }
+
+    u8dst = (uint8_t*)dst;
+
+    for (i = 0; i < len; i++) {
+        if (u8dst[i] != flash_area_erased_val(area)) {
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
 int flash_area_write(const struct flash_area *area, uint32_t off,
                      const void *src, uint32_t len)
 {