Skip to content

Commit

Permalink
This closes #4.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ccollins476ad committed Jan 11, 2017
2 parents 0960365 + dc1964c commit 4c3ce3f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
27 changes: 26 additions & 1 deletion sim/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@

extern crate gcc;

use std::fs;
use std::io;
use std::path::Path;

fn main() {
let mut conf = gcc::Config::new();

conf.file("../boot/bootutil/src/loader.c");
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(())
}
15 changes: 9 additions & 6 deletions sim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -194,12 +196,13 @@ fn try_upgrade(flash: &Flash, areadesc: &AreaDesc, stop: Option<i32>) -> (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
}

Expand Down

0 comments on commit 4c3ce3f

Please sign in to comment.