Commit fa137fc8 authored by Fabio Utzig's avatar Fabio Utzig Committed by David Brown
Browse files

Add option to disable verifying contents before writes

At the moment writes always checking that they are being
performed on an erased section of memory. This patch enables
a test to disable that, to enable looking for other error
causes.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent f5c895e3
Loading
Loading
Loading
Loading
+9 −1
Changes for sim/simflash/src/lib.rs: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ pub trait Flash {
    fn add_bad_region(&mut self, offset: usize, len: usize, rate: f32) -> Result<()>;
    fn reset_bad_regions(&mut self);

    fn set_verify_writes(&mut self, enable: bool);

    fn sector_iter(&self) -> SectorIter;
    fn device_size(&self) -> usize;
}
@@ -69,6 +71,7 @@ pub struct SimFlash {
    bad_region: Vec<(usize, usize, f32)>,
    // Alignment required for writes.
    align: usize,
    verify_writes: bool,
}

impl SimFlash {
@@ -85,6 +88,7 @@ impl SimFlash {
            sectors: sectors,
            bad_region: Vec::new(),
            align: align,
            verify_writes: true,
        }
    }

@@ -176,7 +180,7 @@ impl Flash for SimFlash {
        }

        for (i, x) in &mut self.write_safe[offset .. offset + payload.len()].iter_mut().enumerate() {
            if !(*x) {
            if self.verify_writes && !(*x) {
                panic!("Write to unerased location at 0x{:x}", offset + i);
            }
            *x = false;
@@ -215,6 +219,10 @@ impl Flash for SimFlash {
        self.bad_region.clear();
    }

    fn set_verify_writes(&mut self, enable: bool) {
        self.verify_writes = enable;
    }

    /// An iterator over each sector in the device.
    fn sector_iter(&self) -> SectorIter {
        SectorIter {