This closes #19.

Merge remote-tracking branch 'd3zd3z/fix-slot0'

* d3zd3z/fix-slot0:
  Fix slot0 validation
diff --git a/boot/zephyr/flash_map.c b/boot/zephyr/flash_map.c
index 502e30d..872c80d 100644
--- a/boot/zephyr/flash_map.c
+++ b/boot/zephyr/flash_map.c
@@ -104,9 +104,14 @@
 
 int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)
 {
+	int rc;
+
 	BOOT_LOG_DBG("%s: area=%d, off=%x, len=%x", __func__,
-		     area->fa_id, off, len);
-	return flash_erase(boot_flash_device, area->fa_off + off, len);
+			area->fa_id, off, len);
+	flash_write_protection_set(boot_flash_device, false);
+	rc = flash_erase(boot_flash_device, area->fa_off + off, len);
+	flash_write_protection_set(boot_flash_device, true);
+	return rc;
 }
 
 uint8_t flash_area_align(const struct flash_area *area)
diff --git a/boot/zephyr/hal_flash.c b/boot/zephyr/hal_flash.c
index cebf161..9a78163 100644
--- a/boot/zephyr/hal_flash.c
+++ b/boot/zephyr/hal_flash.c
@@ -23,7 +23,6 @@
 
 #include "hal/hal_flash.h"
 
-/* All of the currently supported devices allow single byte writes. */
 uint8_t hal_flash_align(uint8_t flash_id)
 {
 	return FLASH_ALIGN;
diff --git a/boot/zephyr/include/flash_map/flash_map.h b/boot/zephyr/include/flash_map/flash_map.h
index c0c9489..271c50c 100644
--- a/boot/zephyr/include/flash_map/flash_map.h
+++ b/boot/zephyr/include/flash_map/flash_map.h
@@ -51,15 +51,6 @@
     uint32_t fa_size;
 };
 
-extern const struct flash_area *flash_map;
-extern int flash_map_entries;
-
-/*
- * Initializes flash map. Memory will be referenced by flash_map code
- * from this on.
- */
-void flash_map_init(void);
-
 /*
  * Start using flash area.
  */
diff --git a/boot/zephyr/targets/96b_carbon.h b/boot/zephyr/targets/96b_carbon.h
index 6d8b248..8243f35 100644
--- a/boot/zephyr/targets/96b_carbon.h
+++ b/boot/zephyr/targets/96b_carbon.h
@@ -19,7 +19,12 @@
  * @brief Bootloader device specific configuration.
  */
 
+/* TEMP: maintain compatibility with old STM flash driver */
+#ifndef CONFIG_SOC_FLASH_STM32_DEV_NAME
 #define FLASH_DRIVER_NAME		"STM32F4_FLASH"
+#else
+#define FLASH_DRIVER_NAME		CONFIG_SOC_FLASH_STM32_DEV_NAME
+#endif
 #define FLASH_ALIGN			1
 #define FLASH_AREA_IMAGE_0_OFFSET	0x20000
 #define FLASH_AREA_IMAGE_0_SIZE		0x20000
diff --git a/boot/zephyr/targets/96b_nitrogen.h b/boot/zephyr/targets/96b_nitrogen.h
index 9a0443d..9982ec0 100644
--- a/boot/zephyr/targets/96b_nitrogen.h
+++ b/boot/zephyr/targets/96b_nitrogen.h
@@ -19,7 +19,7 @@
  * @brief Bootloader device specific configuration.
  */
 
-#define FLASH_DRIVER_NAME		"NRF5_FLASH"
+#define FLASH_DRIVER_NAME		CONFIG_SOC_FLASH_NRF5_DEV_NAME
 #define FLASH_ALIGN			4
 #define FLASH_AREA_IMAGE_0_OFFSET	0x08000
 #define FLASH_AREA_IMAGE_0_SIZE		0x3A000
diff --git a/boot/zephyr/targets/frdm_k64f.h b/boot/zephyr/targets/frdm_k64f.h
index 590b1cb..9270399 100644
--- a/boot/zephyr/targets/frdm_k64f.h
+++ b/boot/zephyr/targets/frdm_k64f.h
@@ -19,7 +19,7 @@
  * @brief Bootloader device specific configuration.
  */
 
-#define FLASH_DRIVER_NAME		"MCUX_FLASH"
+#define FLASH_DRIVER_NAME		CONFIG_SOC_FLASH_MCUX_DEV_NAME
 #define FLASH_ALIGN			8
 #define FLASH_AREA_IMAGE_0_OFFSET	0x20000
 #define FLASH_AREA_IMAGE_0_SIZE		0x20000
diff --git a/boot/zephyr/targets/nucleo_f401re.h b/boot/zephyr/targets/nucleo_f401re.h
index 6d8b248..b8328be 100644
--- a/boot/zephyr/targets/nucleo_f401re.h
+++ b/boot/zephyr/targets/nucleo_f401re.h
@@ -19,7 +19,7 @@
  * @brief Bootloader device specific configuration.
  */
 
-#define FLASH_DRIVER_NAME		"STM32F4_FLASH"
+#define FLASH_DRIVER_NAME		CONFIG_SOC_FLASH_STM32_DEV_NAME
 #define FLASH_ALIGN			1
 #define FLASH_AREA_IMAGE_0_OFFSET	0x20000
 #define FLASH_AREA_IMAGE_0_SIZE		0x20000
diff --git a/scripts/zep2newt.py b/scripts/zep2newt.py
index e9904f8..efa4b66 100755
--- a/scripts/zep2newt.py
+++ b/scripts/zep2newt.py
@@ -16,8 +16,7 @@
 DEBUG = False
 
 def get_args():
-    parser = ArgumentParser(description='Script to create images on a format \
-                            that Mynewts bootloader expects')
+    parser = ArgumentParser(description='Convert Zephyr binaries to mcuboot format')
 
     parser.add_argument('--bin', required=True, dest='binary_file', \
                         help='Name of *.bin file (input)')
@@ -33,11 +32,6 @@
                         default='SHA256', \
                         help='Type of signature <SHA256|RSA|EC>')
 
-    parser.add_argument('--off', required=False, dest='flash_offs_addr', \
-                        default='0x08020000', \
-                        help='Offset for the binary in flash (at what address \
-                        should it be flashed?)')
-
     parser.add_argument('--word-size', required=False, dest='word_size',
             default=1,
             help='Writable size of flash device (1, 2, 4, or 8)')
@@ -215,7 +209,6 @@
 
 def main(argv):
     args = get_args()
-    erase = False
 
     conv = Convert(args)