diff --git a/Cargo.toml b/Cargo.toml index d0684b2..56893df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ version = "0.1.0" cortex-m = "0.7.0" flash-algorithm = { version = "0.5.0", default-features = false, features = [ "panic-handler", + "verify", ] } # this lets you use `cargo fix`! diff --git a/build.sh b/build.sh index 345ccd4..5e96554 100755 --- a/build.sh +++ b/build.sh @@ -30,4 +30,5 @@ cat <) -> Result<(), ErrorCode> { + let Some(data) = data else { + return Ok(()); + }; + (self.funcs.flash_flush_cache)(); + (self.funcs.flash_enter_cmd_xip)(); + let check = unsafe { core::slice::from_raw_parts(address as *const u8, size as usize) }; + for (offset, (check, data)) in check.iter().zip(data.iter()).enumerate() { + if *check != *data { + (self.funcs.flash_exit_xip)(); + // Return the first address that failed. + return ErrorCode::new(offset as u32 + address) + .map(|e| Err(e)) + .unwrap_or(Ok(())); + } + } + + (self.funcs.flash_exit_xip)(); + + // Return the last address in the flash range. Any other value (including `Ok(())`) + // is an error. + ErrorCode::new(address + size) + .map(|e| Err(e)) + .unwrap_or(Ok(())) + } } impl Drop for RP2Algo {