skip writing unchanged data

This makes less difference than I'd hoped as so little of the data
is unchanged. Perhaps there's some way to persuade the linker to
place libraries first and the app code later in the image
This commit is contained in:
2026-01-20 18:53:21 +00:00
parent 68a564d3eb
commit 3b66428e93
+19 -7
View File
@@ -193,15 +193,27 @@ where
let write_size = chunk.len() as u32;
let write_size = write_size.min(progress.remaining) as usize;
self.flash
.write(progress.flash_offset, &chunk[..write_size])
.map_err(|_| OtaError::FlashRWError)?;
let unchanged =
write_size <= 8192 && {
let mut old_data = [0u8; 8192];
let p = &mut old_data[..write_size];
_ = self.flash.read(progress.flash_offset, p);
p == &chunk[..write_size]
};
debug!(
"[OTA] Wrote {} bytes to ota partition at 0x{:x}",
write_size, progress.flash_offset
);
if unchanged {
debug!("[OTA] skip writing {} unchanged bytes at 0z:{:x}",
write_size, progress.flash_offset);
} else {
self.flash
.write(progress.flash_offset, &chunk[..write_size])
.map_err(|_| OtaError::FlashRWError)?;
debug!(
"[OTA] Wrote {} bytes to ota partition at 0x{:x}",
write_size, progress.flash_offset
);
}
progress.last_crc = crc32::calc_crc32(&chunk[..write_size], progress.last_crc);
progress.flash_offset += write_size as u32;