diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2018-08-08 12:05:12 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-08 23:52:09 -0700 |
commit | 954231f4af7bd5c1130c865cd16bc1111330bec7 (patch) | |
tree | c8365e3f9bea564ebd7e9904e907c9f9e4f9257e /util/stm32mon.c | |
parent | 989c446da629c6e557a9749ecb427f1b619f7d5b (diff) | |
download | chrome-ec-954231f4af7bd5c1130c865cd16bc1111330bec7.tar.gz |
stm32mon: do not print zeros received when draining the input.
When stm32mon starts up, before trying to program the EC it first
drains the EC console device and displays the contents on the console.
In case of programming over Cr50 the EC console device buffer could be
filled up with many hundreds of zeros which were received by the Cr50
UART when the EC was held in reset, as the Cr50 UART does not process
the 'break' condition properly and considers all received zeros valid
data.
This patch adds code to discard zeros received from the EC console
before flash programming starts, so that the zeros do not flood the
terminal where stm32mon is invoked.
BRANCH=none
BUG=none
TEST=no more zeros printed when stm32mon is invoked, the number of
discarded zeros is reported.
Change-Id: I86c6fe45d1ef55ce7be5aa7511231edb24cfb2be
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1168158
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'util/stm32mon.c')
-rw-r--r-- | util/stm32mon.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/util/stm32mon.c b/util/stm32mon.c index 9c5567fbc4..3c4e313df2 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -269,21 +269,44 @@ static void discard_input(int fd) { uint8_t buffer[64]; int res, i; + int count_of_zeros; /* Skip in i2c and spi modes */ if (mode != MODE_SERIAL) return; /* eat trailing garbage */ + count_of_zeros = 0; do { res = read(fd, buffer, sizeof(buffer)); if (res > 0) { - printf("Recv[%d]:", res); + + /* Discard zeros in the beginning of the buffer. */ for (i = 0; i < res; i++) + if (buffer[i]) + break; + + count_of_zeros += i; + if (i == res) { + /* Only zeros, nothing to print out. */ + continue; + } + + /* Discard zeros in the end of the buffer. */ + while (!buffer[res - 1]) { + count_of_zeros++; + res--; + } + + printf("Recv[%d]:", res - i); + for (; i < res; i++) printf("%02x ", buffer[i]); printf("\n"); } } while (res > 0); + + if (count_of_zeros) + printf("%d zeros ignored\n", count_of_zeros); } int wait_for_ack(int fd) |