Skip to content

Commit

Permalink
Update main simulator routines for multi-flash
Browse files Browse the repository at this point in the history
This adds an initial device with multiple flash (nrf52840 + SPI flash)
and updates all test routines to use a HashMap of flash devices (added
as type SimFlashMap).

Signed-off-by: Fabio Utzig <utzig@apache.org>
  • Loading branch information
utzig committed Nov 19, 2018
1 parent b9a317b commit 37b3d4d
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 165 deletions.
2 changes: 1 addition & 1 deletion sim/mcuboot-sys/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::Mutex;
use std::ops::Deref;

/// A FlashMap maintain a table of [device_id -> Flash trait]
type FlashMap = HashMap<u8, FlashPtr>;
pub type FlashMap = HashMap<u8, FlashPtr>;

lazy_static! {
static ref FLASH: Mutex<FlashMap> = {
Expand Down
8 changes: 4 additions & 4 deletions sim/mcuboot-sys/src/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ impl AreaDesc {
});
}

// Look for the image with the given ID, and return its base and size. Panics if the area is
// not present.
pub fn find(&self, id: FlashId) -> (usize, usize) {
// Look for the image with the given ID, and return its offset, size and
// device id. Panics if the area is not present.
pub fn find(&self, id: FlashId) -> (usize, usize, u8) {
for area in &self.whole {
// FIXME: should we ensure id is not duplicated over multiple devices?
if area.flash_id == id {
return (area.off as usize, area.size as usize);
return (area.off as usize, area.size as usize, area.device_id);
}
}
panic!("Requesting area that is not present in flash");
Expand Down
14 changes: 9 additions & 5 deletions sim/mcuboot-sys/src/c.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Interface wrappers to C API entering to the bootloader
use area::AreaDesc;
use simflash::Flash;
use simflash::SimFlashMap;
use libc;
use api;
use std::sync::Mutex;
Expand All @@ -13,12 +13,14 @@ lazy_static! {
}

/// Invoke the bootloader on this flash device.
pub fn boot_go(flash: &mut Flash, areadesc: &AreaDesc, counter: Option<&mut i32>,
catch_asserts: bool) -> (i32, u8) {
pub fn boot_go(flashmap: &mut SimFlashMap, areadesc: &AreaDesc,
counter: Option<&mut i32>, catch_asserts: bool) -> (i32, u8) {
let _lock = BOOT_LOCK.lock().unwrap();

unsafe {
api::set_flash(0, flash);
for (&dev_id, flash) in flashmap.iter_mut() {
api::set_flash(dev_id, flash);
}
raw::c_catch_asserts = if catch_asserts { 1 } else { 0 };
raw::c_asserts = 0u8;
raw::flash_counter = match counter {
Expand All @@ -30,7 +32,9 @@ pub fn boot_go(flash: &mut Flash, areadesc: &AreaDesc, counter: Option<&mut i32>
let asserts = unsafe { raw::c_asserts };
unsafe {
counter.map(|c| *c = raw::flash_counter as i32);
api::clear_flash(0);
for (&dev_id, _) in flashmap {
api::clear_flash(dev_id);
}
};
(result, asserts)
}
Expand Down
3 changes: 3 additions & 0 deletions sim/simflash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::io::Write;
use std::iter::Enumerate;
use std::path::Path;
use std::slice;
use std::collections::HashMap;
use pdump::HexDump;

error_chain! {
Expand Down Expand Up @@ -130,6 +131,8 @@ impl SimFlash {

}

pub type SimFlashMap = HashMap<u8, SimFlash>;

impl Flash for SimFlash {
/// The flash drivers tend to erase beyond the bounds of the given range. Instead, we'll be
/// strict, and make sure that the passed arguments are exactly at a sector boundary, otherwise
Expand Down
Loading

0 comments on commit 37b3d4d

Please sign in to comment.