Commit afb2bc90 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Update main simulator routines for multi-flash

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: default avatarFabio Utzig <utzig@apache.org>
parent 1c9aea58
Loading
Loading
Loading
Loading
+1 −1
Changes for sim/mcuboot-sys/src/api.rs: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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> = {
+4 −4
Changes for sim/mcuboot-sys/src/area.rs: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -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");
+9 −5
Changes for sim/mcuboot-sys/src/c.rs: 9 added lines, 5 removed lines.
Original line number Diff line number Diff line
/// 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;
@@ -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 {
@@ -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)
}
+3
Changes for sim/simflash/src/lib.rs: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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! {
@@ -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
+203 −154

File changed.

Preview size limit exceeded, changes collapsed.