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: Fabio Utzig <utzig@apache.org>
diff --git a/sim/simflash/src/lib.rs b/sim/simflash/src/lib.rs
index d4817c1..c38baac 100644
--- a/sim/simflash/src/lib.rs
+++ b/sim/simflash/src/lib.rs
@@ -41,6 +41,8 @@
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 @@
bad_region: Vec<(usize, usize, f32)>,
// Alignment required for writes.
align: usize,
+ verify_writes: bool,
}
impl SimFlash {
@@ -85,6 +88,7 @@
sectors: sectors,
bad_region: Vec::new(),
align: align,
+ verify_writes: true,
}
}
@@ -176,7 +180,7 @@
}
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 @@
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 {