From 2e9ea7bf8510dcb8f915fc080564c520249711aa Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Mon, 26 Feb 2018 09:48:46 +0100 Subject: [PATCH] stm32mon: add option to replace the spinner Using only a Carriage Return as done to have a nice spinner is not terribly compatible with logging the output of the tool to a file or piping it to anything. Add another option to have a simple progress-bar instead. Signed-off-by: Vincent Palatin BRANCH=none BUG=none TEST=on Meowth, run flash_fp_mcu from the factory UI. Change-Id: I0c37689d2ed1e45dff54b7f1eb2be515ea37e004 Reviewed-on: https://chromium-review.googlesource.com/936766 Commit-Ready: Vincent Palatin Tested-by: Vincent Palatin Reviewed-by: Aseda Aboagye Reviewed-by: Nicolas Norvez --- util/stm32mon.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/util/stm32mon.c b/util/stm32mon.c index 8e7c8b31da..345eb7cb29 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -528,13 +528,23 @@ int command_get_commands(int fd, struct stm32_def *chip) return -1; } +static int use_progressbar; static int windex; static const char wheel[] = {'|', '/', '-', '\\' }; static void draw_spinner(uint32_t remaining, uint32_t size) { int percent = (size - remaining)*100/size; - printf("\r%c%3d%%", wheel[windex++], percent); - windex %= sizeof(wheel); + if (use_progressbar) { + int dots = percent / 4; + + while (dots > windex) { + putchar('#'); + windex++; + } + } else { + printf("\r%c%3d%%", wheel[windex++], percent); + windex %= sizeof(wheel); + } } int command_read_mem(int fd, uint32_t address, uint32_t size, uint8_t *buffer) @@ -897,6 +907,7 @@ static const struct option longopts[] = { {"spi", 1, 0, 's'}, {"length", 1, 0, 'n'}, {"offset", 1, 0, 'o'}, + {"progressbar", 0, 0, 'p'}, {NULL, 0, 0, 0} }; @@ -905,7 +916,7 @@ void display_usage(char *program) fprintf(stderr, "Usage: %s [-a [-l address ]] | [-s]" " [-d ] [-b ]] [-u] [-e] [-U]" - " [-r ] [-w ] [-o offset] [-l length] [-g]\n", + " [-r ] [-w ] [-o offset] [-l length] [-g] [-p]\n", program); fprintf(stderr, "Can access the controller via serial port or i2c\n"); fprintf(stderr, "Serial port mode:\n"); @@ -927,6 +938,8 @@ void display_usage(char *program) fprintf(stderr, "--o[ffset] : offset to read/write/start from/to\n"); fprintf(stderr, "--n[length] : amount to read/write\n"); fprintf(stderr, "--g[o] : jump to execute flash entrypoint\n"); + fprintf(stderr, "--p[rogressbar] : use a progress bar instead of " + "the spinner\n"); exit(2); } @@ -991,6 +1004,9 @@ int parse_parameters(int argc, char **argv) case 'o': offset = strtol(optarg, NULL, 0); break; + case 'p': + use_progressbar = 1; + break; case 'r': input_filename = optarg; break;