diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2013-02-06 09:32:59 -0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-02-06 10:35:52 -0800 |
commit | fe2e8852b9a3f352aec2e303a91cf8a7f9aaeff0 (patch) | |
tree | a3013dd45610f998a06ad4be1900891d4ad58edd | |
parent | e9c3b705d5efd8e691e6ddbd198b543a11db7997 (diff) | |
download | chrome-ec-fe2e8852b9a3f352aec2e303a91cf8a7f9aaeff0.tar.gz |
stm32mon: add back flashing progression
As we no longer have the low-tech dots to show the progression of the
on-going flashing, display a completion percentage to give the user a
hint of the ETA.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=none
TEST=./util/flash_ec --board=spring
and see accurate progression percentage reported.
Change-Id: I75ccbe3433acd6c94d03a08bf462ea4516e4ce02
Reviewed-on: https://gerrit.chromium.org/gerrit/42733
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r-- | util/stm32mon.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/util/stm32mon.c b/util/stm32mon.c index e8dd908f23..41ed389fc8 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -371,9 +371,10 @@ int command_get_commands(int fd) static int windex; static const char wheel[] = {'|', '/', '-', '\\' }; -static void draw_spinner(void) +static void draw_spinner(uint32_t remaining, uint32_t size) { - printf("%c%c", 8, wheel[windex++]); + int percent = (size - remaining)*100/size; + printf("\r%c%3d%%", wheel[windex++], percent); windex %= sizeof(wheel); } @@ -392,7 +393,7 @@ int command_read_mem(int fd, uint32_t address, uint32_t size, uint8_t *buffer) cnt = (remaining > PAGE_SIZE) ? PAGE_SIZE - 1 : remaining - 1; addr_be = htonl(address); - draw_spinner(); + draw_spinner(remaining, size); fflush(stdout); res = send_command(fd, CMD_READMEM, loads, 2, buffer, cnt + 1); if (res < 0) @@ -425,7 +426,7 @@ int command_write_mem(int fd, uint32_t address, uint32_t size, uint8_t *buffer) loads[1].size = cnt + 1; memcpy(outbuf + 1, buffer, cnt); - draw_spinner(); + draw_spinner(remaining, size); fflush(stdout); res = send_command(fd, CMD_WRITEMEM, loads, 2, NULL, 0); if (res < 0) @@ -590,13 +591,13 @@ int read_flash(int fd, struct stm32_def *chip, const char *filename, if (!size) size = chip->flash_size; offset += chip->flash_start; - printf("Reading %d bytes at 0x%08x ", size, offset); + printf("Reading %d bytes at 0x%08x\n", size, offset); res = command_read_mem(fd, offset, size, buffer); if (res > 0) { if (fwrite(buffer, res, 1, hnd) != 1) fprintf(stderr, "Cannot write %s\n", filename); } - printf(" %d bytes read.\n", res); + printf("\r %d bytes read.\n", res); fclose(hnd); free(buffer); @@ -631,14 +632,14 @@ int write_flash(int fd, struct stm32_def *chip, const char *filename, fclose(hnd); offset += chip->flash_start; - printf("Writing %d bytes at 0x%08x ", res, offset); + printf("Writing %d bytes at 0x%08x\n", res, offset); written = command_write_mem(fd, offset, res, buffer); if (written != res) { fprintf(stderr, "Error writing to flash\n"); free(buffer); return -EIO; } - printf("Done.\n"); + printf("\rDone.\n"); free(buffer); return 0; |