Merge pull request #38 from utzig/magic-sz-const
Use constant for magic size
diff --git a/.gitignore b/.gitignore
index 8aaaf2c..4e8f81a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,11 @@
.*.swp
target.sh
*.pyc
+tags
+rusty-tags.*
+
+# mynewt
+repos/
+project.state
+bin/
+targets/
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 49bbc5a..2f61896 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -312,13 +312,14 @@
{
uint32_t off;
int rc;
- uint8_t buf[8];
+ uint8_t buf[BOOT_MAX_ALIGN];
uint8_t align;
off = boot_copy_done_off(fap);
align = hal_flash_align(fap->fa_device_id);
- memset(buf, 0xFF, 8);
+ assert(align <= BOOT_MAX_ALIGN);
+ memset(buf, 0xFF, BOOT_MAX_ALIGN);
buf[0] = 1;
rc = flash_area_write(fap, off, buf, align);
@@ -334,14 +335,16 @@
{
uint32_t off;
int rc;
- uint8_t buf[8];
+ uint8_t buf[BOOT_MAX_ALIGN];
uint8_t align;
off = boot_image_ok_off(fap);
align = hal_flash_align(fap->fa_device_id);
- memset(buf, 0xFF, 8);
+ assert(align <= BOOT_MAX_ALIGN);
+ memset(buf, 0xFF, BOOT_MAX_ALIGN);
buf[0] = 1;
+
rc = flash_area_write(fap, off, buf, align);
if (rc != 0) {
return BOOT_EFLASH;
diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h
index 79885ae..3bdd1cc 100644
--- a/boot/bootutil/src/bootutil_priv.h
+++ b/boot/bootutil/src/bootutil_priv.h
@@ -39,6 +39,8 @@
#define BOOT_TMPBUF_SZ 256
+#define BOOT_MAX_ALIGN 8
+
/*
* Maintain state of copy progress.
*/
diff --git a/sim/src/api.rs b/sim/src/api.rs
index 71d4643..ec502a2 100644
--- a/sim/src/api.rs
+++ b/sim/src/api.rs
@@ -29,6 +29,9 @@
fn map_err(err: Result<()>) -> libc::c_int {
match err {
Ok(()) => 0,
- Err(_) => -1,
+ Err(e) => {
+ warn!("{}", e);
+ -1
+ },
}
}
diff --git a/sim/src/flash.rs b/sim/src/flash.rs
index 797a044..adbb69a 100644
--- a/sim/src/flash.rs
+++ b/sim/src/flash.rs
@@ -94,8 +94,10 @@
}
let mut sub = &mut self.data[offset .. offset + payload.len()];
- if sub.iter().any(|x| *x != 0xFF) {
- bail!(ewrite(format!("Write to non-FF location: offset: {:x}", offset)));
+ for (i, x) in sub.iter().enumerate() {
+ if *x != 0xFF {
+ bail!(ewrite(format!("Write to non-FF location at 0x{:x}", offset + i)));
+ }
}
sub.copy_from_slice(payload);