]> git.sur5r.net Git - u-boot/commitdiff
sandbox: put stdin into raw mode
authorMike Frysinger <vapier@gentoo.org>
Wed, 26 Oct 2011 00:21:29 +0000 (00:21 +0000)
committerWolfgang Denk <wd@denx.de>
Thu, 3 Nov 2011 21:35:21 +0000 (22:35 +0100)
This allows us to act like a serial device: we get tab chars and CTRL+C
and respond appropriately.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Tested-by: Simon Glass <sjg@chromium.org>
arch/sandbox/cpu/os.c
drivers/serial/sandbox.c
include/os.h

index 6c175d462a5c2f42c91e7468fcf363da308b4c55..f80faac1f5ff5d911e9b76f92a803b542aeb04cf 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <fcntl.h>
 #include <stdlib.h>
+#include <termios.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -53,3 +54,36 @@ void os_exit(int exit_code)
 {
        exit(exit_code);
 }
+
+/* Restore tty state when we exit */
+static struct termios orig_term;
+
+static void os_fd_restore(void)
+{
+       tcsetattr(0, TCSANOW, &orig_term);
+}
+
+/* Put tty into raw mode so <tab> and <ctrl+c> work */
+void os_tty_raw(int fd)
+{
+       static int setup = 0;
+       struct termios term;
+
+       if (setup)
+               return;
+       setup = 1;
+
+       /* If not a tty, don't complain */
+       if (tcgetattr(fd, &orig_term))
+               return;
+
+       term = orig_term;
+       term.c_iflag = IGNBRK | IGNPAR;
+       term.c_oflag = OPOST | ONLCR;
+       term.c_cflag = CS8 | CREAD | CLOCAL;
+       term.c_lflag = 0;
+       if (tcsetattr(fd, TCSANOW, &term))
+               return;
+
+       atexit(os_fd_restore);
+}
index 814a0f9e7fcfc17d7796f03037047f0436cdeacb..1927c167bb701f487bb6ea9687aabb1fb288f271 100644 (file)
@@ -30,6 +30,7 @@
 
 int serial_init(void)
 {
+       os_tty_raw(0);
        return 0;
 }
 
index 3ea6d2ddeef2d781385f3e5eddf88f3773742857..d5df22f77c83c35b8197ec223049afb526f50568 100644 (file)
@@ -71,3 +71,8 @@ int os_close(int fd);
  * @param exit_code    exit code for U-Boot
  */
 void os_exit(int exit_code);
+
+/**
+ * Put tty into raw mode to mimic serial console better
+ */
+void os_tty_raw(int fd);