From 0ea75d24f26355dcc3186db9e58604c77fdd38c0 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Mon, 13 Aug 2018 15:13:41 -0700 Subject: stm32mon: don't set UART attributes when programming over Cr50 When EC console is connected over a Cr50 UART to USB bridge, there is no need to try setting up UART properties of the interface device as in this case the settings will not propagate to the target. BRANCH=none BUG=b:62539385 TEST=connect a Scarlet device over SuzyQ to the host and source the following script: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv echo gpioset EC_FLASH_SELECT 1 > /dev/ttyUSB0 echo bitbang 2 57600 even > /dev/ttyUSB0 echo ecrst pulse > /dev/ttyUSB0 sleep 2 /stm32mon -d /dev/ttyUSB2 -u -U -e -c -w /ec.bin echo gpioset EC_FLASH_SELECT 0 > /dev/ttyUSB0 echo bitbang 2 disable > /dev/ttyUSB0 echo ecrst pulse > /dev/ttyUSB0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Change-Id: I5feeaffbc25c029fe6b5d8fa712d5927d00e26ce Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/1175317 Reviewed-by: Mary Ruthven --- util/stm32mon.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/util/stm32mon.c b/util/stm32mon.c index d52bcf81d5..cdf8f74f58 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -133,6 +133,7 @@ enum { FLAG_ERASE = 0x02, FLAG_GO = 0x04, FLAG_READ_UNPROTECT = 0x08, + FLAG_CR50_MODE = 0x10, }; typedef struct { @@ -203,7 +204,7 @@ static ssize_t write_wrapper(int fd, const void *buf, size_t count) return rv; } -int open_serial(const char *port) +int open_serial(const char *port, int cr50_mode) { int fd, res; struct termios cfg, cfg_copy; @@ -222,9 +223,14 @@ int open_serial(const char *port) return -1; } cfmakeraw(&cfg); - cfsetspeed(&cfg, baudrate); - /* serial mode should be 8e1 */ - cfg.c_cflag |= PARENB; + + /* Don't bother setting speed and parity when programming over Cr50. */ + if (!cr50_mode) { + cfsetspeed(&cfg, baudrate); + /* serial mode should be 8e1 */ + cfg.c_cflag |= PARENB; + } + /* 200 ms timeout */ cfg.c_cc[VTIME] = 2; cfg.c_cc[VMIN] = 0; @@ -972,21 +978,22 @@ int write_flash(int fd, struct stm32_def *chip, const char *filename, } static const struct option longopts[] = { + {"adapter", 1, 0, 'a'}, + {"baudrate", 1, 0, 'b'}, + {"cr50", 0, 0, 'c'}, {"device", 1, 0, 'd'}, - {"read", 1, 0, 'r'}, - {"write", 1, 0, 'w'}, {"erase", 0, 0, 'e'}, {"go", 0, 0, 'g'}, {"help", 0, 0, 'h'}, - {"location", 1, 0, 'l'}, - {"unprotect", 0, 0, 'u'}, - {"baudrate", 1, 0, 'b'}, - {"adapter", 1, 0, 'a'}, - {"spi", 1, 0, 's'}, {"length", 1, 0, 'n'}, + {"location", 1, 0, 'l'}, {"logfile", 1, 0, 'L'}, {"offset", 1, 0, 'o'}, {"progressbar", 0, 0, 'p'}, + {"read", 1, 0, 'r'}, + {"spi", 1, 0, 's'}, + {"unprotect", 0, 0, 'u'}, + {"write", 1, 0, 'w'}, {NULL, 0, 0, 0} }; @@ -996,7 +1003,7 @@ void display_usage(char *program) "Usage: %s [-a [-l address ]] | [-s]" " [-d ] [-b ]] [-u] [-e] [-U]" " [-r ] [-w ] [-o offset] [-n length] [-g] [-p]" - " [-L ]\n", + " [-L ] [-c]\n", program); fprintf(stderr, "Can access the controller via serial port or i2c\n"); fprintf(stderr, "Serial port mode:\n"); @@ -1022,6 +1029,8 @@ void display_usage(char *program) "the spinner\n"); fprintf(stderr, "-L[ogfile] : save all communications exchange " "in a log file\n"); + fprintf(stderr, "-c[r50_mode] : consider device to be a Cr50 interface," + " no need to set UART port attributes\n"); exit(2); } @@ -1054,7 +1063,7 @@ int parse_parameters(int argc, char **argv) int flags = 0; const char *log_file_name = NULL; - while ((opt = getopt_long(argc, argv, "a:l:b:d:eghL:n:o:pr:s:w:uU?", + while ((opt = getopt_long(argc, argv, "a:l:b:cd:eghL:n:o:pr:s:w:uU?", longopts, &idx)) != -1) { switch (opt) { case 'a': @@ -1067,6 +1076,9 @@ int parse_parameters(int argc, char **argv) case 'b': baudrate = parse_baudrate(optarg); break; + case 'c': + flags |= FLAG_CR50_MODE; + break; case 'd': serial_port = optarg; mode = MODE_SERIAL; @@ -1143,7 +1155,7 @@ int main(int argc, char **argv) case MODE_SERIAL: default: /* Open the serial port tty */ - ser = open_serial(serial_port); + ser = open_serial(serial_port, !!(flags & FLAG_CR50_MODE)); } if (ser < 0) return 1; -- cgit v1.2.1