Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Windows] Fixed a crash in monitor when espflash is connected via USB Serial/JTAG, and the user is typing into the monitor but the device is not reading serial input. (#943)
- [Linux/MacOS] Fixed espflash hanging when espflash is connected via USB Serial/JTAG, and the user is typing into the monitor but the device is not reading serial input. (#944, #945)
- Fixed ESP32-S2 flash size detection issues (#950)
- Images are now automatically padded to 4 bytes before writing by the library (previously this was done in the CLI) (#951)

### Removed

Expand Down
6 changes: 0 additions & 6 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,15 +1139,9 @@ pub fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
// Load the file to be flashed
let mut f = File::open(&args.file).into_diagnostic()?;

// If the file size is not divisible by 4, we need to pad `FF` bytes to the end
let size = f.metadata().into_diagnostic()?.len();
let mut padded_bytes = 0;
if size % 4 != 0 {
padded_bytes = 4 - (size % 4);
}
let mut buffer = Vec::with_capacity(size.try_into().into_diagnostic()?);
f.read_to_end(&mut buffer).into_diagnostic()?;
buffer.extend(std::iter::repeat_n(0xFF, padded_bytes as usize));

let mut flasher = connect(&args.connect_args, config, false, false)?;
print_board_info(&mut flasher)?;
Expand Down
13 changes: 12 additions & 1 deletion espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,21 @@ impl Flasher {
data: &[u8],
progress: &mut dyn ProgressCallbacks,
) -> Result<(), Error> {
let segment = Segment {
let mut segment = Segment {
addr,
data: Cow::from(data),
};

// If the file size is not divisible by 4, we need to pad `FF` bytes to the end
let size = segment.data.len();
if size % 4 != 0 {
let padded_bytes = 4 - (size % 4);
segment
.data
.to_mut()
.extend(std::iter::repeat_n(0xFF, padded_bytes));
}

self.write_bins_to_flash(&[segment], progress)?;

info!("Binary successfully written to flash!");
Expand Down
Loading