This closes #4.
Merge remote-tracking branch 'd3zd3z/sim' into mcuboot-master
* d3zd3z/sim:
sim: Fix build paths for new directory layout
sim: Test multiple reverts
sim: Add dependency output
diff --git a/sim/build.rs b/sim/build.rs
index c69c09a..74e271c 100644
--- a/sim/build.rs
+++ b/sim/build.rs
@@ -2,6 +2,10 @@
extern crate gcc;
+use std::fs;
+use std::io;
+use std::path::Path;
+
fn main() {
let mut conf = gcc::Config::new();
@@ -9,7 +13,28 @@
conf.file("../boot/bootutil/src/bootutil_misc.c");
conf.file("csupport/run.c");
conf.include("../boot/bootutil/include");
- conf.include("../zephyr/include");
+ conf.include("../boot/zephyr/include");
conf.debug(true);
conf.compile("libbootutil.a");
+ walk_dir("../boot").unwrap();
+ walk_dir("csupport").unwrap();
+}
+
+// Output the names of all files within a directory so that Cargo knows when to rebuild.
+fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
+ for ent in fs::read_dir(path.as_ref())? {
+ let ent = ent?;
+ let p = ent.path();
+ if p.is_dir() {
+ walk_dir(p)?;
+ } else {
+ // Note that non-utf8 names will fail.
+ let name = p.to_str().unwrap();
+ if name.ends_with(".c") || name.ends_with(".h") {
+ println!("cargo:rerun-if-changed={}", name);
+ }
+ }
+ }
+
+ Ok(())
}
diff --git a/sim/src/main.rs b/sim/src/main.rs
index 1f17f17..5691ac2 100644
--- a/sim/src/main.rs
+++ b/sim/src/main.rs
@@ -143,9 +143,11 @@
bad, total_count,
bad as f32 * 100.0 / total_count as f32);
- info!("Try revert");
- let fl2 = try_revert(&flash, &areadesc);
- assert!(verify_image(&fl2, 0x020000, &primary));
+ for count in 2 .. 5 {
+ info!("Try revert: {}", count);
+ let fl2 = try_revert(&flash, &areadesc, count);
+ assert!(verify_image(&fl2, 0x020000, &primary));
+ }
info!("Try norevert");
let fl2 = try_norevert(&flash, &areadesc);
@@ -194,12 +196,13 @@
(fl, cnt2)
}
-fn try_revert(flash: &Flash, areadesc: &AreaDesc) -> Flash {
+fn try_revert(flash: &Flash, areadesc: &AreaDesc, count: usize) -> Flash {
let mut fl = flash.clone();
c::set_flash_counter(0);
- assert_eq!(c::boot_go(&mut fl, &areadesc), 0);
- assert_eq!(c::boot_go(&mut fl, &areadesc), 0);
+ for _ in 0 .. count {
+ assert_eq!(c::boot_go(&mut fl, &areadesc), 0);
+ }
fl
}