diff --git a/CHANGELOG.md b/CHANGELOG.md index 882c302..0dcc56a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - EEPROM dump support, fix #12 - Refactor all subcommands, using clap v4 - Probe support, multiple chips can be selected by an index +- Progressbar for flash and verify commands + ### Changed - Disable debug log by default diff --git a/Cargo.toml b/Cargo.toml index 75c4b32..b555582 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,4 @@ object = { version = "0.29", default-features = false, features = [ "read_core", "std", ] } +indicatif = "0.17" \ No newline at end of file diff --git a/README.md b/README.md index 3f6dc11..6260a53 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ This tool should work on most WCH MCU chips. But I haven't tested it on any othe - [x] CH32F103 - [x] CH582 - CH58xM-EVT +- [x] CH559 + - CH559TL_MINIEVT_V20 by wch.cn - [x] CH32V203 - [CH32V203G6 FlappyBoard](https://github.com/metro94/FlappyBoard) - ... (feel free to open an issue whether it works on your chip or not) diff --git a/src/flashing.rs b/src/flashing.rs index 90450b0..2205c7c 100644 --- a/src/flashing.rs +++ b/src/flashing.rs @@ -1,8 +1,6 @@ //! Chip flashing routine -use std::thread::sleep; -use std::time::Duration; - use anyhow::Result; +use indicatif::ProgressBar; use scroll::{Pread, Pwrite, LE}; use crate::{ @@ -202,12 +200,16 @@ impl Flashing { const CHUNK: usize = 56; let mut address = 0x0; + + let bar = ProgressBar::new(raw.len() as _); for ch in raw.chunks(CHUNK) { self.flash_chunk(address, ch, key)?; address += ch.len() as u32; + bar.inc(ch.len() as _); } // NOTE: require a write action of empty data for success flashing self.flash_chunk(address, &[], key)?; + bar.finish(); log::info!("Code flash {} bytes written", address); @@ -215,8 +217,6 @@ impl Flashing { } pub fn verify(&mut self, raw: &[u8]) -> Result<()> { - sleep(Duration::from_secs(1)); - let key = self.xor_key(); let key_checksum = key.iter().fold(0_u8, |acc, &x| acc.overflowing_add(x).0); // NOTE: use all-zero key seed for now. @@ -227,10 +227,13 @@ impl Flashing { const CHUNK: usize = 56; let mut address = 0x0; + let bar = ProgressBar::new(raw.len() as _); for ch in raw.chunks(CHUNK) { self.verify_chunk(address, ch, key)?; address += ch.len() as u32; + bar.inc(ch.len() as _); } + bar.finish(); Ok(()) } @@ -270,6 +273,8 @@ impl Flashing { if self.chip.eeprom_size == 0 { anyhow::bail!("Chip does not support EEPROM"); } + let bar = ProgressBar::new(self.chip.eeprom_size as _); + let mut ret: Vec = Vec::with_capacity(self.chip.eeprom_size as _); let mut address = 0x0; while address < self.chip.eeprom_size as u32 { @@ -278,7 +283,7 @@ impl Flashing { let cmd = Command::data_read(address, chunk_size); let resp = self.transport.transfer(cmd)?; anyhow::ensure!(resp.is_ok(), "data_read failed"); - address += CHUNK as u32; + anyhow::ensure!( resp.payload()[2..].len() == chunk_size as usize, "data_read length mismatch" @@ -287,7 +292,11 @@ impl Flashing { anyhow::bail!("EEPROM read failed, required chunk size cannot be satisfied"); } ret.extend_from_slice(&resp.payload()[2..]); + address += chunk_size as u32; + + bar.inc(chunk_size as _); if chunk_size < CHUNK as u16 { + bar.finish(); break; } } diff --git a/src/main.rs b/src/main.rs index e4242ee..c978c5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,6 +175,7 @@ fn main() -> Result<()> { log::info!("Erase done"); } + log::info!("Writing to code flash..."); flashing.flash(&binary)?; sleep(Duration::from_millis(500)); @@ -210,6 +211,7 @@ fn main() -> Result<()> { flashing.reidenfity()?; sleep(Duration::from_millis(500)); + log::info!("Reading EEPROM..."); let eeprom = flashing.dump_eeprom()?; log::info!("EEPROM data size: {}", eeprom.len());