diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-10-26 00:21:29 +0000 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2011-11-03 22:35:21 +0100 |
commit | ab06a758b9407a3f4b89d23ac08dc45aa7749f11 (patch) | |
tree | 8ce0ad0d59b2ed86b010be7d7e6a30311a6ad5d3 /arch | |
parent | ec8f0b9024adc1075bb514edefbf186e63f84268 (diff) | |
download | u-boot-imx-ab06a758b9407a3f4b89d23ac08dc45aa7749f11.zip u-boot-imx-ab06a758b9407a3f4b89d23ac08dc45aa7749f11.tar.gz u-boot-imx-ab06a758b9407a3f4b89d23ac08dc45aa7749f11.tar.bz2 |
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 <vapier@gentoo.org>
Tested-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sandbox/cpu/os.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 6c175d4..f80faac 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -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); +} |