summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2018-02-26 09:48:46 +0100
committerchrome-bot <chrome-bot@chromium.org>2018-03-01 16:13:09 -0800
commit2e9ea7bf8510dcb8f915fc080564c520249711aa (patch)
tree699c7a218e46cc16f40e2682031e06ebf14d6847
parentf917f447d7206faa98ea2c1b1915fb4196913ef0 (diff)
downloadchrome-ec-2e9ea7bf8510dcb8f915fc080564c520249711aa.tar.gz
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 <vpalatin@chromium.org> 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 <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Nicolas Norvez <norvez@chromium.org>
-rw-r--r--util/stm32mon.c22
1 files 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 <i2c_adapter> [-l address ]] | [-s]"
" [-d <tty>] [-b <baudrate>]] [-u] [-e] [-U]"
- " [-r <file>] [-w <file>] [-o offset] [-l length] [-g]\n",
+ " [-r <file>] [-w <file>] [-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;