Skip to content

Commit c50eb97

Browse files
Show progress when skipping and verifying (#904)
* Show progress when skipping and verifying The progress callbacks get initialized and updated even if we skip a segment. For verification, we add an extra step to the progress which is updated once verification is complete. * Make callbacks compulsory, add empty impl convience struct * changelog * fixups * Add skip bool to finish to determine whether the segment was finished via skip or real work was done * more changelog * Fix new clippy lints introduced in 1.88 --------- Co-authored-by: Jesse Braham <jesse@beta7.io>
1 parent 73c613a commit c50eb97

File tree

18 files changed

+127
-127
lines changed

18 files changed

+127
-127
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- All methods on the now removed `Target` & `ReadEFuse`, `UsbOtg` and `RtcWdtReset` traits have been implemented directly on (#891)
3434
- Update checks can now be skipped by setting the the `ESPFLASH_SKIP_UPDATE_CHECK` environment variable (#900)
3535
- `flash_write_size` and `max_ram_block_size` functions no longer take a connection parameter and return a Result type (#903)
36+
- `DefaultProgressCallback` which implements `ProgressCallbacks` but all methods are no-ops (#904)
3637

3738
### Changed
3839

@@ -58,13 +59,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5859
- `Flasher::into_serial` has been replaced by `Flasher::into_connection` (#882)
5960
- Automatically migrate `espflash@3` configuration files to the new format (#883)
6061
- Update dependencies to their latest versions (#893)
61-
- `ProgressCallbacks` has moved to `flasher` (#891)
6262
- `Chip::crystal_freq` has been renamed to `Chip::xtal_frequency` (#891)
6363
- `Chip::chip_revision` has been renamed to `Chip::revision` (also applies to `minor` and `major`) (#891)
6464
- Any reference to `esp_idf` or `EspIdf` has been cut to just `idf` (#891)
6565
- Renamed `targets` module to `target` (#891)
6666
- Test data is now excluded from the crates.io release (#897)
67-
- The command module, and `Command` related structs now exist in a top level module, instead of the `connection` module (#901)
67+
- The command module, and `Command` related structs now exist in a top level module, instead of the `connection` module (#901)
68+
- API's that take `Option<&mut dyn ProgressCallbacks>` now take `&mut dyn ProgressCallbacks` instead (#904)
69+
- `ProgressCallbacks::finish()` now has a `skipped: bool` parameter to indicate if a segment was skipped (#904)
6870

6971
### Fixed
7072

@@ -79,6 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7981
- espflash now extracts the MMU page size from the app descriptor (#835)
8082
- `ResetBeforeOperation` & `ResetAfterOperation` are now public, to allow the creation of a `Connection` (#895)
8183
- `Flasher` now respects its internal `verify` and `skip` flags for all methods. (#901)
84+
- Progress is now reported on skipped segments and verification (#904)
8285

8386
### Removed
8487

cargo-espflash/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn main() -> Result<()> {
242242
subcommand: args,
243243
skip_update_check,
244244
} = cli.subcommand;
245-
debug!("{:#?}, {:#?}", args, skip_update_check);
245+
debug!("{args:#?}, {skip_update_check:#?}");
246246

247247
// Only check for updates once the command-line arguments have been processed,
248248
// to avoid printing any update notifications when the help message is
@@ -366,7 +366,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
366366
.or_else(|| Some(FlashSize::default())); // Otherwise, use a reasonable default value
367367

368368
if args.flash_args.ram {
369-
flasher.load_elf_to_ram(&elf_data, Some(&mut EspflashProgress::default()))?;
369+
flasher.load_elf_to_ram(&elf_data, &mut EspflashProgress::default())?;
370370
} else {
371371
let flash_data = make_flash_data(
372372
args.flash_args.image,
@@ -581,7 +581,7 @@ fn build(
581581
}
582582
Message::CompilerMessage(message) => {
583583
if let Some(rendered) = message.message.rendered {
584-
print!("{}", rendered);
584+
print!("{rendered}");
585585
}
586586
}
587587
// Ignore all other messages.

espflash/src/bin/espflash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
279279
.or_else(|| Some(FlashSize::default())); // Otherwise, use a reasonable default value
280280

281281
if args.flash_args.ram {
282-
flasher.load_elf_to_ram(&elf_data, Some(&mut EspflashProgress::default()))?;
282+
flasher.load_elf_to_ram(&elf_data, &mut EspflashProgress::default())?;
283283
} else {
284284
let flash_data = make_flash_data(
285285
args.flash_args.image,

espflash/src/cli/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn serialize_u16_to_hex<S>(decimal: &u16, serializer: S) -> Result<S::Ok, S::Err
6161
where
6262
S: serde::Serializer,
6363
{
64-
let hex_string = format!("{:04x}", decimal);
64+
let hex_string = format!("{decimal:04x}");
6565
serializer.serialize_str(&hex_string)
6666
}
6767

espflash/src/cli/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ use crate::{
4747
FlashSettings,
4848
FlashSize,
4949
Flasher,
50-
ProgressCallbacks,
5150
},
5251
image_format::{
5352
ImageFormat,
5453
ImageFormatKind,
5554
Metadata,
5655
idf::{IdfBootloaderFormat, parse_partition_table},
5756
},
58-
target::{Chip, XtalFrequency},
57+
target::{Chip, ProgressCallbacks, XtalFrequency},
5958
};
6059

6160
pub mod config;
@@ -481,7 +480,7 @@ pub fn checksum_md5(args: &ChecksumMd5Args, config: &Config) -> Result<()> {
481480
let mut flasher = connect(&args.connect_args, config, true, true)?;
482481

483482
let checksum = flasher.checksum_md5(args.address, args.size)?;
484-
println!("0x{:x}", checksum);
483+
println!("0x{checksum:x}");
485484

486485
let chip = flasher.chip();
487486
flasher
@@ -620,7 +619,7 @@ pub fn print_board_info(flasher: &mut Flasher) -> Result<()> {
620619
println!("Features: {}", info.features.join(", "));
621620

622621
if let Some(mac) = info.mac_address {
623-
println!("MAC address: {}", mac);
622+
println!("MAC address: {mac}");
624623
}
625624

626625
Ok(())
@@ -767,7 +766,7 @@ impl ProgressCallbacks for EspflashProgress {
767766
}
768767

769768
/// End the progress bar
770-
fn finish(&mut self) {
769+
fn finish(&mut self, _skipped: bool) {
771770
if let Some(ref pb) = self.pb {
772771
pb.finish();
773772
}
@@ -827,7 +826,7 @@ pub fn erase_region(args: EraseRegionArgs, config: &Config) -> Result<()> {
827826

828827
/// Write an ELF image to a target device's flash
829828
pub fn flash_image<'a>(flasher: &mut Flasher, image_format: ImageFormat<'a>) -> Result<()> {
830-
flasher.load_image_to_flash(Some(&mut EspflashProgress::default()), image_format)?;
829+
flasher.load_image_to_flash(&mut EspflashProgress::default(), image_format)?;
831830
info!("Flashing has completed!");
832831

833832
Ok(())
@@ -1117,11 +1116,7 @@ pub fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
11171116
let chip = flasher.chip();
11181117
let target_xtal_freq = chip.xtal_frequency(flasher.connection())?;
11191118

1120-
flasher.write_bin_to_flash(
1121-
args.address,
1122-
&buffer,
1123-
Some(&mut EspflashProgress::default()),
1124-
)?;
1119+
flasher.write_bin_to_flash(args.address, &buffer, &mut EspflashProgress::default())?;
11251120

11261121
if args.monitor {
11271122
let pid = flasher.connection().usb_pid();

espflash/src/cli/monitor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl RawModeGuard {
6767
impl Drop for RawModeGuard {
6868
fn drop(&mut self) {
6969
if let Err(e) = disable_raw_mode() {
70-
error!("Failed to disable raw_mode: {:#}", e)
70+
error!("Failed to disable raw_mode: {e:#}")
7171
}
7272
}
7373
}
@@ -90,7 +90,7 @@ pub fn monitor(
9090
}
9191

9292
let baud = monitor_args.monitor_baud;
93-
debug!("Opening serial monitor with baudrate: {}", baud);
93+
debug!("Opening serial monitor with baudrate: {baud}");
9494

9595
// Explicitly set the baud rate when starting the serial monitor, to allow using
9696
// different rates for flashing.

espflash/src/cli/monitor/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn resolve_addresses(
3838
let location = symbols.location(addr);
3939

4040
if let Some(name) = name {
41-
let output = if line.trim() == format!("0x{:x}", addr) {
41+
let output = if line.trim() == format!("0x{addr:x}") {
4242
if let Some((file, line_num)) = location {
4343
format!("{name}\r\n at {file}:{line_num}\r\n")
4444
} else {

espflash/src/cli/serial.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn serial_port_info(matches: &ConnectArgs, config: &Config) -> Result<Serial
5858
pid: usb_info.pid,
5959
})
6060
}) {
61-
error!("Failed to save config {:#}", e);
61+
error!("Failed to save config {e:#}");
6262
}
6363
}
6464
}
@@ -190,7 +190,7 @@ fn select_serial_port(
190190
match &port_info.port_type {
191191
SerialPortType::UsbPort(info) => {
192192
if let Some(product) = &info.product {
193-
format!("{} - {}", formatted, product)
193+
format!("{formatted} - {product}")
194194
} else {
195195
formatted.to_string()
196196
}
@@ -242,9 +242,9 @@ fn confirm_port(port_name: &str, product: Option<&String>) -> Result<bool, Error
242242
Confirm::with_theme(&ColorfulTheme::default())
243243
.with_prompt({
244244
if let Some(product) = product {
245-
format!("Use serial port '{}' - {}?", port_name, product)
245+
format!("Use serial port '{port_name}' - {product}?")
246246
} else {
247-
format!("Use serial port '{}'?", port_name)
247+
format!("Use serial port '{port_name}'?")
248248
}
249249
})
250250
.interact_opt()?

espflash/src/command.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ impl CommandType {
152152
CommandType::FlashDeflEnd => FLASH_DEFLATE_END_TIMEOUT,
153153
CommandType::FlashMd5 => {
154154
log::warn!(
155-
"Using default timeout for {}, this may not be sufficient for large flash regions. Consider using `timeout_for_size` instead.",
156-
self
155+
"Using default timeout for {self}, this may not be sufficient for large flash regions. Consider using `timeout_for_size` instead."
157156
);
158157

159158
DEFAULT_TIMEOUT

espflash/src/connection/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Connection {
9999
return Ok(());
100100
}
101101
Err(e) => {
102-
debug!("Failed to reset, error {:#?}, retrying", e);
102+
debug!("Failed to reset, error {e:#?}, retrying");
103103
}
104104
}
105105
}
@@ -159,8 +159,8 @@ impl Connection {
159159
download_mode = data.get(2).is_some();
160160

161161
// Further processing or printing the results
162-
debug!("Boot Mode: {}", boot_mode);
163-
debug!("Download Mode: {}", download_mode);
162+
debug!("Boot Mode: {boot_mode}");
163+
debug!("Download Mode: {download_mode}");
164164
};
165165
}
166166

@@ -447,7 +447,7 @@ impl Connection {
447447

448448
/// Write a command to the serial port.
449449
pub fn write_command(&mut self, command: Command<'_>) -> Result<(), Error> {
450-
debug!("Writing command: {:02x?}", command);
450+
debug!("Writing command: {command:02x?}");
451451
let mut binding = Box::new(&mut self.serial);
452452
let serial = binding.as_mut();
453453

@@ -575,7 +575,7 @@ impl Connection {
575575
} else {
576576
self.read_reg(CHIP_DETECT_MAGIC_REG_ADDR)?
577577
};
578-
debug!("Read chip magic value: 0x{:08x}", magic);
578+
debug!("Read chip magic value: 0x{magic:08x}");
579579
Chip::from_magic(magic)
580580
}
581581
}

0 commit comments

Comments
 (0)