Skip to content

Commit 0ca8829

Browse files
authored
read-image: Clearer progress reporting (#23)
* read-image: Clearer progress reporting Due to periodic reboot to avoid watchdog, `read_flash_data()` only sees a partial range at a time, it's ignorant of overall progress. Previously, to the user, progress appeared to loop: Read 16384 bytes out of 1048576 (1%) from flash ... Read 1048576 bytes out of 1048576 (100%) from flash followed by boot, sync, and exactly same progression several times (unless one looks too closely into FlashRead messages)... Now percentages are only reported at top level, and lower-level progress uses addresses, which do advance monotonically: Sent device reboot message, [190, 0, 0, 1, 241, 79] Sent message type DeviceCommand [BE, 0, 0, 1, F1, 4F] === Preparing to read flash from 0x3C100000 (25%) to 0x3C200000 (50%) === Starting loader and checking communications ... Now doing flash read Read flash from 0x3C100000 to 0x3C104000 ... Read flash from 0x3C1FC000 to 0x3C200000 * Log reboot message in hex, like other messages
1 parent 11c107a commit 0ca8829

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

bestool/src/beslink/read_flash.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ pub fn read_flash_data(
1414
let mut result = vec![];
1515
let mut tries = 0;
1616
while result.len() < length {
17-
match read_flash_chunk(serial_port, address + result.len()) {
17+
let pos = address + result.len();
18+
match read_flash_chunk(serial_port, pos) {
1819
Ok(chunk) => {
1920
result.extend_from_slice(&chunk);
2021
std::thread::sleep(Duration::from_millis(10)); // Try to yield to let watch dog reset
21-
info!(
22-
"Read {} bytes out of {} ({}%) from flash",
23-
result.len(),
24-
length,
25-
result.len() * 100 / length
26-
);
22+
info!("Read flash from 0x{:X} to 0x{:X}", pos, pos + chunk.len());
2723
}
2824
Err(e) => {
2925
warn!("Error {}", e);

bestool/src/beslink/reboot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn send_device_reboot(
2121
device_reboot_message.set_checksum();
2222

2323
info!(
24-
"Sent device reboot message, {:?}",
24+
"Sent device reboot message, {:X?}",
2525
device_reboot_message.to_vec()
2626
);
2727
send_message(serial_port, device_reboot_message)?;

bestool/src/cmds/read_image.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn do_read_flash_data(
4040
length: usize,
4141
) -> Result<(), BESLinkError> {
4242
let mut flash_content: Vec<u8> = vec![];
43-
const MAX_READ_BEFORE_RESET: usize = 1024 * 1024; //1MB chunks
43+
const MAX_READ_BEFORE_RESET: usize = 1024 * 1024; //1MiB chunks
4444
while flash_content.len() < length {
4545
let chunk_length = {
4646
if (length - flash_content.len()) < MAX_READ_BEFORE_RESET {
@@ -49,11 +49,15 @@ fn do_read_flash_data(
4949
MAX_READ_BEFORE_RESET
5050
}
5151
};
52-
let chunk = do_reset_sync_read(
53-
serial_port,
54-
0x3C00_0000 + start + flash_content.len(),
55-
chunk_length,
56-
)?;
52+
let pos = 0x3C00_0000 + start + flash_content.len();
53+
info!(
54+
"===== Preparing to read flash from 0x{:X} ({}%) to 0x{:X} ({}%) =====",
55+
pos,
56+
flash_content.len() * 100 / length,
57+
pos + chunk_length,
58+
(flash_content.len() + chunk_length) * 100 / length,
59+
);
60+
let chunk = do_reset_sync_read(serial_port, pos, chunk_length)?;
5761
flash_content.extend(chunk);
5862
}
5963

0 commit comments

Comments
 (0)