summaryrefslogtreecommitdiff
path: root/util/uut
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@google.com>2019-02-06 18:19:38 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-08 14:27:03 -0800
commit6ea830328941f24fc01213030c8ab8865ac4a2f1 (patch)
tree9085daca44cd5275294ea5675100e8a0a6d67132 /util/uut
parent11303f23c7c4abc168ff34ae0f3344635157089f (diff)
downloadchrome-ec-6ea830328941f24fc01213030c8ab8865ac4a2f1.tar.gz
uut: drain EC console before programming
Cr50 doesn't handle the uart break conditions properly, so it will fill up the EC uart with zeros when ECTX_CR50RX stays asserted. We assert that signal to start uut programming, so the buffer is almost guaranteed to be filled with garbage when uut programming starts. We were seeing synchronization fail because the baudrate check would read a zero from the buffer instead of the expected output. This change completely drains the EC console before starting uut to get rid of the garbage that interferes with programming. stm32mon does the exact same thing. We should create common code for initializing serial devices. BUG=b:123775217 BRANCH=none TEST=program cheza using ccd uut Change-Id: I2df562a5b4513ada528e887e057e78a8f1f3054c Signed-off-by: Mary Ruthven <mruthven@google.com> Reviewed-on: https://chromium-review.googlesource.com/1457579 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'util/uut')
-rw-r--r--util/uut/l_com_port.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/util/uut/l_com_port.c b/util/uut/l_com_port.c
index a214d77302..70c60869b3 100644
--- a/util/uut/l_com_port.c
+++ b/util/uut/l_com_port.c
@@ -200,6 +200,57 @@ bool com_config_uart(int h_dev_drv, struct comport_fields com_port_fields)
return true;
}
+/**
+ * Drain the console RX buffer before programming. The device should be in
+ * programming mode and shouldn't be printing anything. Anything that's
+ * currently in the buffer could interfere with programming. discard_input
+ * will discard everything currently in the buffer. It prints any non zero
+ * characters and returns when the console is empty and ready for programming.
+ *
+ * This is the same as discard_input in stm32mon.
+ * TODO: create common library for initializing serial consoles.
+ */
+static void discard_input(int fd)
+{
+ uint8_t buffer[64];
+ int res, i;
+ int count_of_zeros;
+
+ /* Keep track of discarded zeros */
+ count_of_zeros = 0;
+ do {
+ res = read(fd, buffer, sizeof(buffer));
+ if (res > 0) {
+
+ /* 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);
+}
+
+
/******************************************************************************
* Function: int com_port_open()
*
@@ -241,6 +292,12 @@ int com_port_open(const char *com_port_dev_name,
return INVALID_HANDLE_VALUE;
}
+ /*
+ * Drain the console, so what ever is already in the EC console wont
+ * interfere with programming.
+ */
+ discard_input(port_handler);
+
return port_handler;
}