From 2974b796d1c2a65fe4927d1307f949ddb78184a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannic=20Schr=C3=B6der?= Date: Tue, 20 Sep 2016 14:14:14 +0200 Subject: [PATCH 1/3] Initialize serialdump termios properly termios i_flags were not initialized and could be set to arbitrary values this resulted in unpredicted behaviour of the output like additional newlines --- tools/sky/serialdump.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/sky/serialdump.c b/tools/sky/serialdump.c index 12fd0abfc..deab56df4 100644 --- a/tools/sky/serialdump.c +++ b/tools/sky/serialdump.c @@ -208,6 +208,8 @@ main(int argc, char **argv) options.c_cflag |= CS8; /* Raw input */ + options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* Raw output */ options.c_oflag &= ~OPOST; From 9e080e8aa5c219b4f621afa4730914e265fa5848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannic=20Schr=C3=B6der?= Date: Tue, 20 Sep 2016 14:16:40 +0200 Subject: [PATCH 2/3] Terminate serialdump when serial device disconnects The running serialdump does not recover from a disconnected device but runs indefinitely with outputting anything. This makes it quit with a proper error message. --- tools/sky/serialdump.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/sky/serialdump.c b/tools/sky/serialdump.c index deab56df4..7cc0d0e1e 100644 --- a/tools/sky/serialdump.c +++ b/tools/sky/serialdump.c @@ -281,6 +281,11 @@ main(int argc, char **argv) perror("could not read"); exit(-1); } + if(n == 0) { + errno = EBADF; + perror("serial device disconnected"); + exit(-1); + } for(i = 0; i < n; i++) { switch(mode) { From d524211c2acc97f1b4d89bfbff646227f641f28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannic=20Schr=C3=B6der?= Date: Tue, 20 Sep 2016 14:18:21 +0200 Subject: [PATCH 3/3] Clean exit of serialdump when hitting Ctrl-C Ctrl-C is the best way to close serialdump after using make login. With a clean exit it will signal to make that the make run was successful. --- tools/sky/serialdump.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/sky/serialdump.c b/tools/sky/serialdump.c index 7cc0d0e1e..1fc93ef49 100644 --- a/tools/sky/serialdump.c +++ b/tools/sky/serialdump.c @@ -8,6 +8,7 @@ #include #include #include +#include #define BAUDRATE B115200 #define BAUDRATE_S "115200" @@ -82,9 +83,17 @@ print_hex_line(char *prefix, unsigned char *outbuf, int index) } } +static void +intHandler(int sig) +{ + exit(0); +} + int main(int argc, char **argv) { + signal(SIGINT, intHandler); + struct termios options; fd_set mask, smask; int fd;