Skip to content

Commit 11620c9

Browse files
Janrupfjessebraham
authored andcommitted
Allow to skip padding when building flash image
1 parent 41eb720 commit 11620c9

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

cargo-espflash/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ pub struct SaveImageOpts {
124124
/// Custom partition table for merging
125125
#[clap(long, short = 'T')]
126126
pub partition_table: Option<PathBuf>,
127+
/// Don't pad the image to the flash size
128+
#[clap(long, short = 'P')]
129+
pub skip_padding: bool,
127130
}
128131

129132
fn main() -> Result<()> {
@@ -423,6 +426,7 @@ fn save_image(
423426
opts.merge,
424427
bootloader,
425428
partition_table,
429+
opts.skip_padding,
426430
)?;
427431

428432
Ok(())

espflash/src/cli/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub fn save_elf_as_image(
172172
merge: bool,
173173
bootloader_path: Option<PathBuf>,
174174
partition_table_path: Option<PathBuf>,
175+
skip_padding: bool,
175176
) -> Result<()> {
176177
let image = ElfFirmwareImage::try_from(elf_data)?;
177178

@@ -237,13 +238,15 @@ pub fn save_elf_as_image(
237238
file.write_all(&segment.data).into_diagnostic()?;
238239
}
239240

240-
// Take flash_size as input parameter, if None, use default value of 4Mb
241-
let padding_bytes = vec![
242-
0xffu8;
243-
flash_size.unwrap_or(FlashSize::Flash4Mb).size() as usize
244-
- file.metadata().into_diagnostic()?.len() as usize
245-
];
246-
file.write_all(&padding_bytes).into_diagnostic()?;
241+
if !skip_padding {
242+
// Take flash_size as input parameter, if None, use default value of 4Mb
243+
let padding_bytes = vec![
244+
0xffu8;
245+
flash_size.unwrap_or(FlashSize::Flash4Mb).size() as usize
246+
- file.metadata().into_diagnostic()?.len() as usize
247+
];
248+
file.write_all(&padding_bytes).into_diagnostic()?;
249+
}
247250
} else {
248251
let flash_image = chip.get_flash_image(
249252
&image,

espflash/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub struct SaveImageOpts {
7979
/// Custom partition table for merging
8080
#[clap(long, short = 'T')]
8181
pub partition_table: Option<PathBuf>,
82+
/// Don't pad the image to the flash size
83+
#[clap(long, short = 'P')]
84+
pub skip_padding: bool,
8285
}
8386

8487
fn main() -> Result<()> {
@@ -197,6 +200,7 @@ fn save_image(opts: SaveImageOpts) -> Result<()> {
197200
opts.merge,
198201
opts.bootloader,
199202
opts.partition_table,
203+
opts.skip_padding,
200204
)?;
201205

202206
Ok(())

0 commit comments

Comments
 (0)