From fe2e8852b9a3f352aec2e303a91cf8a7f9aaeff0 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 6 Feb 2013 09:32:59 -0800 Subject: [PATCH] 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 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 Tested-by: Vincent Palatin Reviewed-by: Vadim Bendebury --- util/stm32mon.c | 17 +++++++++-------- 1 file 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;