From 1a44316c85bbe9de8d6db7080a73781906ea42b7 Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 10 Jan 2017 11:54:42 -0700 Subject: [PATCH 1/3] sim: Add dependency output Output the names of source files used to build the C library so that Cargo knows to rerun the compilation if these have changed. --- sim/build.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sim/build.rs b/sim/build.rs index c69c09a0..d341e24e 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(); @@ -12,4 +16,26 @@ fn main() { conf.include("../zephyr/include"); conf.debug(true); conf.compile("libbootutil.a"); + walk_dir("../boot").unwrap(); + walk_dir("csupport").unwrap(); + walk_dir("../zephyr").unwrap(); +} + +// Output the names of all files within a directory so that Cargo knows when to rebuild. +fn walk_dir>(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(()) } From c638f799a04228c28f0c7baaaaaf850a199ff5da Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 10 Jan 2017 12:34:33 -0700 Subject: [PATCH 2/3] sim: Test multiple reverts Make sure reboots after an image is reverted never results in the images being swapped again. --- sim/src/main.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sim/src/main.rs b/sim/src/main.rs index 1f17f17f..5691ac24 100644 --- a/sim/src/main.rs +++ b/sim/src/main.rs @@ -143,9 +143,11 @@ fn main() { 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 @@ fn try_upgrade(flash: &Flash, areadesc: &AreaDesc, stop: Option) -> (Flash, (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 } From dc1964c0a6744410ae8c1856f1ace94d96904b0e Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 10 Jan 2017 16:45:05 -0700 Subject: [PATCH 3/3] sim: Fix build paths for new directory layout The zephyr sources have moved to a different directory. Adjust the build script to fix the paths referenced. --- sim/build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sim/build.rs b/sim/build.rs index d341e24e..74e271c7 100644 --- a/sim/build.rs +++ b/sim/build.rs @@ -13,12 +13,11 @@ fn main() { 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(); - walk_dir("../zephyr").unwrap(); } // Output the names of all files within a directory so that Cargo knows when to rebuild.