Skip to content

Commit a43be2e

Browse files
authored
Indicate in CLI when a partition was skipped or being verified, fix incorrect chunk size being shown. (#908)
* Indicate in CLI when a partition was skipped or being verified * Fix target address alignment, and just append to last msg. * Modify changelog with logs of changes
1 parent 2e3f3c3 commit a43be2e

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- `flash_write_size` and `max_ram_block_size` functions no longer take a connection parameter and return a Result type (#903)
3636
- `DefaultProgressCallback` which implements `ProgressCallbacks` but all methods are no-ops (#904)
3737
- Update checks can now be skipped by setting the `ESPFLASH_SKIP_UPDATE_CHECK` environment variable (#900)
38+
- `ProgressCallbacks` now has a `verifying` method to notify when post-flash checksum checking has begun (#908)
3839

3940
### Changed
4041

@@ -68,6 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6869
- The command module, and `Command` related structs now exist in a top level module, instead of the `connection` module (#901)
6970
- API's that take `Option<&mut dyn ProgressCallbacks>` now take `&mut dyn ProgressCallbacks` instead (#904)
7071
- `ProgressCallbacks::finish()` now has a `skipped: bool` parameter to indicate if a segment was skipped (#904)
72+
- CLI usage now shows when a segment has been skipped due to already-matching checksum and when a segment is being verified (#908)
7173

7274
### Fixed
7375

espflash/src/cli/mod.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,14 @@ pub(crate) fn display_image_size(app_size: u32, part_size: Option<u32>) {
745745
#[derive(Debug, Default)]
746746
pub struct EspflashProgress {
747747
pb: Option<ProgressBar>,
748+
verifying: bool,
748749
}
749750

750751
impl ProgressCallbacks for EspflashProgress {
751752
/// Initialize the progress bar
752753
fn init(&mut self, addr: u32, len: usize) {
753754
let pb = ProgressBar::new(len as u64)
754-
.with_message(format!("{addr:#X}"))
755+
.with_message(format!("{addr:<#8X}"))
755756
.with_style(
756757
ProgressStyle::default_bar()
757758
.template("[{elapsed_precise}] [{bar:40}] {pos:>7}/{len:7} {msg}")
@@ -760,20 +761,43 @@ impl ProgressCallbacks for EspflashProgress {
760761
);
761762

762763
self.pb = Some(pb);
764+
self.verifying = false;
763765
}
764766

765767
/// Update the progress bar
766768
fn update(&mut self, current: usize) {
767-
if let Some(ref pb) = self.pb {
769+
if let Some(pb) = &self.pb {
768770
pb.set_position(current as u64);
769771
}
770772
}
771773

774+
/// Tell user we're verifying the flashed data
775+
fn verifying(&mut self) {
776+
if let Some(pb) = &self.pb {
777+
self.verifying = true;
778+
let last_msg = pb.message();
779+
780+
pb.set_message(format!("{last_msg} Verifying..."));
781+
}
782+
}
783+
772784
/// End the progress bar
773-
fn finish(&mut self, _skipped: bool) {
774-
if let Some(ref pb) = self.pb {
775-
pb.finish();
785+
fn finish(&mut self, skipped: bool) {
786+
if let Some(pb) = &self.pb {
787+
use crossterm::style::Stylize;
788+
let last_msg = pb.message();
789+
790+
if skipped {
791+
let skipped = "Skipped! (checksum matches)".cyan();
792+
pb.finish_with_message(format!("{last_msg} {skipped}"));
793+
} else if self.verifying {
794+
let ok = "OK!".green();
795+
pb.finish_with_message(format!("{last_msg} {ok}"));
796+
} else {
797+
pb.finish();
798+
}
776799
}
800+
self.verifying = false;
777801
}
778802
}
779803

espflash/src/target/flash_target/esp32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl FlashTarget for Esp32Target {
125125
let chunks = compressed.chunks(flash_write_size);
126126
let num_chunks = chunks.len();
127127

128-
progress.init(addr, num_chunks + self.verify as usize);
128+
progress.init(addr, num_chunks);
129129

130130
if self.skip {
131131
let flash_checksum_md5: u128 = connection.with_timeout(
@@ -190,6 +190,7 @@ impl FlashTarget for Esp32Target {
190190
}
191191

192192
if self.verify {
193+
progress.verifying();
193194
let flash_checksum_md5: u128 = connection.with_timeout(
194195
CommandType::FlashMd5.timeout_for_size(segment.data.len() as u32),
195196
|connection| {
@@ -206,7 +207,6 @@ impl FlashTarget for Esp32Target {
206207
return Err(Error::VerifyFailed);
207208
}
208209
debug!("Segment at address '0x{addr:x}' verified successfully");
209-
progress.update(num_chunks + 1)
210210
}
211211

212212
progress.finish(false);

espflash/src/target/flash_target/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub trait ProgressCallbacks {
2727
fn init(&mut self, addr: u32, total: usize);
2828
/// Update some progress report.
2929
fn update(&mut self, current: usize);
30+
/// Indicate post-flash checksum verification has begun.
31+
fn verifying(&mut self);
3032
/// Finish some progress report.
3133
fn finish(&mut self, skipped: bool);
3234
}
@@ -38,5 +40,6 @@ pub struct DefaultProgressCallback;
3840
impl ProgressCallbacks for DefaultProgressCallback {
3941
fn init(&mut self, _addr: u32, _total: usize) {}
4042
fn update(&mut self, _current: usize) {}
43+
fn verifying(&mut self) {}
4144
fn finish(&mut self, _skipped: bool) {}
4245
}

0 commit comments

Comments
 (0)