From ab06a758b9407a3f4b89d23ac08dc45aa7749f11 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 26 Oct 2011 00:21:29 +0000 Subject: [PATCH] sandbox: put stdin into raw mode This allows us to act like a serial device: we get tab chars and CTRL+C and respond appropriately. Signed-off-by: Mike Frysinger Tested-by: Simon Glass --- arch/sandbox/cpu/os.c | 34 ++++++++++++++++++++++++++++++++++ drivers/serial/sandbox.c | 1 + include/os.h | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 6c175d462a..f80faac1f5 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -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 and 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); +} diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index 814a0f9e7f..1927c167bb 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -30,6 +30,7 @@ int serial_init(void) { + os_tty_raw(0); return 0; } diff --git a/include/os.h b/include/os.h index 3ea6d2ddee..d5df22f77c 100644 --- a/include/os.h +++ b/include/os.h @@ -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); -- 2.30.2