Skip to content

Commit

Permalink
Fix programming when some preamble bytes must be restored but were al…
Browse files Browse the repository at this point in the history
…ready erased
  • Loading branch information
adamgreig committed Jan 20, 2021
1 parent 7a14871 commit 937b5ed
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,21 +958,12 @@ impl<'a, A: FlashAccess> Flash<'a, A> {
}

/// Read all the bytes before `address` in memory which will be erased by `plan`.
///
/// If all those bytes are 0xFF, returns an empty Vec instead, as they won't be changed
/// by the erase operation.
fn read_erase_preamble(&mut self, address: u32, plan: &ErasePlan) -> Result<Vec<u8>> {
let base = plan.0[0].2;
let len = address - base;
if len > 0 {
log::debug!("Reading erase preamble: base={} len={}", base, len);
let data = self.read(base, len as usize)?;
// If all the preamble is already 0xFF, there's no point reprogramming it.
if data.iter().all(|x| *x == 0xFF) {
Ok(Vec::new())
} else {
Ok(data)
}
self.read(base, len as usize)
} else {
Ok(Vec::new())
}
Expand Down

0 comments on commit 937b5ed

Please sign in to comment.