Update trailer format

This implements changes according to MCUB-14, easing the process
of making external apps parse and read/write the trailer.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/sim/src/c.rs b/sim/src/c.rs
index 4de9553..a770ca6 100644
--- a/sim/src/c.rs
+++ b/sim/src/c.rs
@@ -33,6 +33,14 @@
     unsafe { raw::sim_flash_align = align };
 }
 
+pub fn boot_magic_sz() -> usize {
+    unsafe { raw::BOOT_MAGIC_SZ as usize }
+}
+
+pub fn boot_max_align() -> usize {
+    unsafe { raw::BOOT_MAX_ALIGN as usize }
+}
+
 mod raw {
     use area::CAreaDesc;
     use libc;
@@ -46,5 +54,8 @@
 
         pub static mut sim_flash_align: u8;
         pub fn boot_slots_trailer_sz(min_write_sz: u8) -> u32;
+
+        pub static BOOT_MAGIC_SZ: u32;
+        pub static BOOT_MAX_ALIGN: u32;
     }
 }
diff --git a/sim/src/main.rs b/sim/src/main.rs
index d970ef2..086cc21 100644
--- a/sim/src/main.rs
+++ b/sim/src/main.rs
@@ -220,11 +220,10 @@
 
         // Set an alignment, and position the magic value.
         c::set_sim_flash_align(align);
-        let trailer_size = c::boot_trailer_sz();
 
         // Mark the upgrade as ready to install.  (This looks like it might be a bug in the code,
         // however.)
-        mark_upgrade(&mut flash, scratch_base - trailer_size as usize);
+        mark_upgrade(&mut flash, scratch_base - c::boot_magic_sz() as usize);
 
         let (fl2, total_count) = try_upgrade(&flash, &areadesc, None);
         info!("First boot, count={}", total_count);
@@ -324,7 +323,7 @@
     let ok = [1u8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
     let (base, _) = areadesc.find(FlashId::ImageScratch);
     let align = c::get_sim_flash_align() as usize;
-    fl.write(base - align, &ok[..align]).unwrap();
+    fl.write(base - c::boot_magic_sz() - c::boot_max_align(), &ok[..align]).unwrap();
 
     c::set_flash_counter(stop.unwrap_or(0));
     let (first_interrupted, cnt1) = match c::boot_go(&mut fl, &areadesc) {
@@ -369,7 +368,8 @@
     // Write boot_ok
     let ok = [1u8, 0, 0, 0, 0, 0, 0, 0];
     let (slot0_base, slot0_len) = areadesc.find(FlashId::Image0);
-    fl.write(slot0_base + slot0_len - align, &ok[..align]).unwrap();
+    fl.write(slot0_base + slot0_len - c::boot_magic_sz() - c::boot_max_align(),
+             &ok[..align]).unwrap();
     assert_eq!(c::boot_go(&mut fl, &areadesc), 0);
     fl
 }
@@ -382,7 +382,7 @@
     let ok = [1u8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
     let (base, _) = areadesc.find(FlashId::ImageScratch);
     let align = c::get_sim_flash_align() as usize;
-    fl.write(base - align, &ok[..align]).unwrap();
+    fl.write(base - c::boot_magic_sz() - c::boot_max_align(), &ok[..align]).unwrap();
 
     let mut rng = rand::thread_rng();
     let mut resets = vec![0i32; count];