* [U-Boot] [PATCH] sandbox: put stdin into raw mode
@ 2011-10-26 10:21 Mike Frysinger
2011-10-26 16:17 ` Simon Glass
2011-11-03 21:30 ` Wolfgang Denk
0 siblings, 2 replies; 3+ messages in thread
From: Mike Frysinger @ 2011-10-26 10:21 UTC (permalink / raw)
To: u-boot
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>
---
arch/sandbox/cpu/os.c | 34 ++++++++++++++++++++++++++++++++++
drivers/serial/sandbox.c | 1 +
include/os.h | 5 +++++
3 files changed, 40 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);
+}
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 814a0f9..1927c16 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 3ea6d2d..d5df22f 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);
--
1.7.6.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] sandbox: put stdin into raw mode
2011-10-26 10:21 [U-Boot] [PATCH] sandbox: put stdin into raw mode Mike Frysinger
@ 2011-10-26 16:17 ` Simon Glass
2011-11-03 21:30 ` Wolfgang Denk
1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2011-10-26 16:17 UTC (permalink / raw)
To: u-boot
On Wed, Oct 26, 2011 at 3:21 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> 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>
Thanks Mike
> ---
> ?arch/sandbox/cpu/os.c ? ?| ? 34 ++++++++++++++++++++++++++++++++++
> ?drivers/serial/sandbox.c | ? ?1 +
> ?include/os.h ? ? ? ? ? ? | ? ?5 +++++
> ?3 files changed, 40 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);
> +}
> diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
> index 814a0f9..1927c16 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 3ea6d2d..d5df22f 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);
> --
> 1.7.6.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] sandbox: put stdin into raw mode
2011-10-26 10:21 [U-Boot] [PATCH] sandbox: put stdin into raw mode Mike Frysinger
2011-10-26 16:17 ` Simon Glass
@ 2011-11-03 21:30 ` Wolfgang Denk
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Denk @ 2011-11-03 21:30 UTC (permalink / raw)
To: u-boot
Dear Mike Frysinger,
In message <1319624489-32009-1-git-send-email-vapier@gentoo.org> you wrote:
> 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>
> ---
> arch/sandbox/cpu/os.c | 34 ++++++++++++++++++++++++++++++++++
> drivers/serial/sandbox.c | 1 +
> include/os.h | 5 +++++
> 3 files changed, 40 insertions(+), 0 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
How much net work could a network work, if a network could net work?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-03 21:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-26 10:21 [U-Boot] [PATCH] sandbox: put stdin into raw mode Mike Frysinger
2011-10-26 16:17 ` Simon Glass
2011-11-03 21:30 ` Wolfgang Denk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.