diff --git a/CHANGELOG.md b/CHANGELOG.md index d2be11b..b8b0ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add Windows native driver support, #39 - Use loaded memory address from ELF file or ihex file +### Fixed + +- Merge gaps in firmware sections, #56 + ### Changed - No erase by default when flashing diff --git a/src/commands/mod.rs b/src/commands/mod.rs index a2cefd0..d5e8960 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -91,7 +91,7 @@ impl fmt::Debug for RawCommand { } } -/// Set address and offset of the firmware, 0x01. +/// 0x01 - Set address and offset of the firmware #[derive(Debug)] pub struct SetWriteMemoryRegion { // 0x08000000 or 0x00000000 @@ -126,14 +126,14 @@ impl Command for SetReadMemoryRegion { } } -/// 0x02 subset +/// 0x02 - Flash or Memory operations #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum Program { // wlink_erase EraseFlash = 0x01, // Before write firmware bytes, choice between 0x02 and 0x04 WriteFlash = 0x02, - // after write flash + // Write flash WriteFlashAndVerify = 0x04, /// Write Flash OP WriteFlashOP = 0x05, diff --git a/src/firmware.rs b/src/firmware.rs index 2269ef4..64896dc 100644 --- a/src/firmware.rs +++ b/src/firmware.rs @@ -39,7 +39,7 @@ pub enum Firmware { } impl Firmware { - /// Merge sections w/ <= 256 bytes gap + /// Merge sections, and fill gap with 0xff pub fn merge_sections(self) -> Result { if let Firmware::Sections(mut sections) = self { sections.sort_by_key(|s| s.address); @@ -49,16 +49,14 @@ impl Firmware { let mut last = it .next() .expect("firmware must has at least one section; qed"); + for sect in it { if let Some(gap) = sect.address.checked_sub(last.end_address()) { - if gap > 256 { - merged.push(last); - last = sect.clone(); - continue; - } else { - last.data.resize(last.data.len() + gap as usize, 0); - last.data.extend_from_slice(§.data); + if gap > 0 { + log::debug!("Merge firmware sections with gap: {}", gap); } + last.data.resize(last.data.len() + gap as usize, 0xff); // fill gap with 0xff + last.data.extend_from_slice(§.data); } else { return Err(anyhow::format_err!( "section address overflow: {:#010x} + {:#x}",