Skip to content

Commit 1e7f421

Browse files
authored
add erase progress bar to "humility qspi" (#231)
1 parent 09a152f commit 1e7f421

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "humility"
1717
#
1818
# Be sure to check in and push all of the files that change. Happy versioning!
1919
#
20-
version = "0.8.12"
20+
version = "0.8.13"
2121
authors = ["Bryan Cantrill <[email protected]>"]
2222
edition = "2018"
2323
license = "MPL-2.0"

cmd/qspi/src/lib.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,33 @@ fn erase(
287287
) -> Result<()> {
288288
let f = funcs.get("QspiSectorErase", 1)?;
289289

290-
humility::msg!(
291-
"erasing {} bytes...",
292-
all_sectors.len() as u32 * device.sector_size
290+
let started = Instant::now();
291+
let len = all_sectors.len() as u32 * device.sector_size;
292+
293+
let bar = ProgressBar::new(len.into());
294+
295+
bar.set_style(
296+
ProgressStyle::default_bar()
297+
.template("humility: erasing [{bar:30}] {bytes}/{total_bytes}"),
293298
);
294299

300+
bar.set_position(0);
301+
295302
//
296303
// To unroll our loop, we need to know how many operations we can stuff in
297304
// our text. For this calculation, we'll be a bit pessimal -- we would
298305
// actually expect to be able to serialize our per-sector operations in
299306
// fewer than 16 bytes -- but we want to give ourselves a bit of slop.
307+
// Finally, we clamp our maximum at 512K of erasing at a go to allow us to
308+
// show progress at a reasonable granularity.
300309
//
301310
let op_bytes_per_sector = 16;
302-
let max_calls = context.text_size() / op_bytes_per_sector;
311+
let max_calls = std::cmp::min(
312+
context.text_size() / op_bytes_per_sector,
313+
(512 * 1024) / device.sector_size as usize,
314+
);
303315

304-
for sectors in all_sectors.chunks(max_calls) {
316+
for (n, sectors) in all_sectors.chunks(max_calls).enumerate() {
305317
let mut ops = vec![];
306318

307319
for addr in sectors {
@@ -327,9 +339,19 @@ fn erase(
327339
);
328340
}
329341
}
342+
343+
bar.set_position(
344+
((n * sectors.len()) as u32 * device.sector_size).into(),
345+
);
330346
}
331347

332-
humility::msg!("... done");
348+
bar.finish_and_clear();
349+
350+
humility::msg!(
351+
"erased {} in {}",
352+
HumanBytes(len.into()),
353+
HumanDuration(started.elapsed())
354+
);
333355

334356
Ok(())
335357
}

tests/cmd/chip.trycmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For more information try --help
1313

1414
```
1515
$ humility --chip this-can-be-anything -V
16-
humility 0.8.12
16+
humility 0.8.13
1717

1818
```
1919

@@ -28,7 +28,7 @@ For more information try --help
2828

2929
```
3030
$ humility -c apx432 -V
31-
humility 0.8.12
31+
humility 0.8.13
3232

3333
```
3434

tests/cmd/version.trycmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ Long version flag:
22

33
```
44
$ humility --version
5-
humility 0.8.12
5+
humility 0.8.13
66

77
```
88

99
Short version flag:
1010

1111
```
1212
$ humility -V
13-
humility 0.8.12
13+
humility 0.8.13
1414

1515
```

0 commit comments

Comments
 (0)