Add sim support for flash erased at 0

This extends the simulator to be able to test the bootloader in devices
which use flash technologies that erase flash at 0 instead of 0xff.
Two MCU devices that have this "property" are the STM32L0x and STM32L1x
lines from ST.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/sim/mcuboot-sys/csupport/flash_map.h b/sim/mcuboot-sys/csupport/flash_map.h
index 506f266..7622dd0 100644
--- a/sim/mcuboot-sys/csupport/flash_map.h
+++ b/sim/mcuboot-sys/csupport/flash_map.h
@@ -126,6 +126,11 @@
 uint8_t flash_area_align(const struct flash_area *);
 
 /*
+ * What is value is read from erased flash bytes.
+ */
+uint8_t flash_area_erased_val(const struct flash_area *);
+
+/*
  * Given flash area ID, return info about sectors within the area.
  */
 int flash_area_get_sectors(int fa_id, uint32_t *count,
diff --git a/sim/mcuboot-sys/csupport/run.c b/sim/mcuboot-sys/csupport/run.c
index ece8555..8238b39 100644
--- a/sim/mcuboot-sys/csupport/run.c
+++ b/sim/mcuboot-sys/csupport/run.c
@@ -52,6 +52,13 @@
     return sim_flash_align;
 }
 
+uint8_t sim_flash_erased_val = 0xff;
+uint8_t flash_area_erased_val(const struct flash_area *area)
+{
+    (void)area;
+    return sim_flash_erased_val;
+}
+
 struct area {
     struct flash_area whole;
     struct flash_area *areas;
diff --git a/sim/mcuboot-sys/src/c.rs b/sim/mcuboot-sys/src/c.rs
index 3400bc0..3b944c6 100644
--- a/sim/mcuboot-sys/src/c.rs
+++ b/sim/mcuboot-sys/src/c.rs
@@ -22,6 +22,7 @@
         raw::c_catch_asserts = if catch_asserts { 1 } else { 0 };
         raw::c_asserts = 0u8;
         raw::sim_flash_align = align;
+        raw::sim_flash_erased_val = flash.erased_val();
         raw::flash_counter = match counter {
             None => 0,
             Some(ref c) => **c as libc::c_int
@@ -73,6 +74,7 @@
         pub static mut c_catch_asserts: u8;
 
         pub static mut sim_flash_align: u8;
+        pub static mut sim_flash_erased_val: u8;
         pub fn boot_slots_trailer_sz(min_write_sz: u8) -> u32;
 
         pub static BOOT_MAGIC_SZ: u32;