[ipxe-devel] [PATCH] [serial] Don't enable serial console without serial support
Shao Miller
sha0.miller at gmail.com
Wed Oct 3 19:11:03 UTC 2012
With proper formatting for the 'if', this time... - Shao
From 6c5b1c214f8d94fdf9e9b56d0b7cd9de2702c214 Mon Sep 17 00:00:00 2001
From: Shao Miller <sha0.miller at gmail.com>
Date: Wed, 3 Oct 2012 14:56:13 -0400
Subject: [PATCH] [serial] Don't enable serial console without serial support
serial_console_init() would enable serial console support without
knowing if the serial driver succeeded or not. As a result, the
serial console would interfere with a normal keyboard on a system
lacking serial support.
Steps to reproduce the problem after #defining CONSOLE_SERIAL:
qemu -serial none -kernel bin/ipxe.lkrn -append shell
(Only the enter key would work from the keyboard)
Reported-by: Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
Signed-off-by: Shao Miller <sha0.miller at gmail.com>
---
src/core/serial.c | 7 ++++++-
src/core/serial_console.c | 9 ++++++---
src/include/ipxe/serial.h | 1 +
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/core/serial.c b/src/core/serial.c
index a5551b1..8f5a159 100644
--- a/src/core/serial.c
+++ b/src/core/serial.c
@@ -93,6 +93,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define uart_writeb(val,addr) outb((val),(addr))
#endif
+/* Boolean for the state of serial driver initialization */
+int serial_initialized = 0;
+
/*
* void serial_putc(int ch);
* Write character `ch' to port UART_BASE.
@@ -207,7 +210,6 @@ static void serial_init ( void ) {
/* Set clear to send, so flow control works... */
uart_writeb((1<<1), UART_BASE + UART_MCR);
-
/* Flush the input buffer. */
do {
/* rx buffer reg
@@ -217,6 +219,9 @@ static void serial_init ( void ) {
/* line status reg */
status = uart_readb(UART_BASE + UART_LSR);
} while(status & UART_LSR_DR);
+
+ /* Note that serial support has been initialized */
+ serial_initialized = 1;
out:
return;
}
diff --git a/src/core/serial_console.c b/src/core/serial_console.c
index bbddd6b..a901915 100644
--- a/src/core/serial_console.c
+++ b/src/core/serial_console.c
@@ -18,9 +18,12 @@
struct console_driver serial_console __console_driver;
static void serial_console_init ( void ) {
- /* Serial driver initialization should already be done,
- * time to enable the serial console. */
- serial_console.disabled = 0;
+ /*
+ * Check if serial driver initialization is done.
+ * If so, it's time to enable the serial console.
+ */
+ if (serial_initialized)
+ serial_console.disabled = 0;
}
struct console_driver serial_console __console_driver = {
diff --git a/src/include/ipxe/serial.h b/src/include/ipxe/serial.h
index c16e56a..b47b1d1 100644
--- a/src/include/ipxe/serial.h
+++ b/src/include/ipxe/serial.h
@@ -12,5 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
extern void serial_putc ( int ch );
extern int serial_getc ( void );
extern int serial_ischar ( void );
+extern int serial_initialized;
#endif /* _IPXE_SERIAL_H */
--
1.7.11.4
-------------- next part --------------
>From 6c5b1c214f8d94fdf9e9b56d0b7cd9de2702c214 Mon Sep 17 00:00:00 2001
From: Shao Miller <sha0.miller at gmail.com>
Date: Wed, 3 Oct 2012 14:56:13 -0400
Subject: [PATCH] [serial] Don't enable serial console without serial support
serial_console_init() would enable serial console support without
knowing if the serial driver succeeded or not. As a result, the
serial console would interfere with a normal keyboard on a system
lacking serial support.
Steps to reproduce the problem after #defining CONSOLE_SERIAL:
qemu -serial none -kernel bin/ipxe.lkrn -append shell
(Only the enter key would work from the keyboard)
Reported-by: Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
Signed-off-by: Shao Miller <sha0.miller at gmail.com>
---
src/core/serial.c | 7 ++++++-
src/core/serial_console.c | 9 ++++++---
src/include/ipxe/serial.h | 1 +
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/core/serial.c b/src/core/serial.c
index a5551b1..8f5a159 100644
--- a/src/core/serial.c
+++ b/src/core/serial.c
@@ -93,6 +93,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define uart_writeb(val,addr) outb((val),(addr))
#endif
+/* Boolean for the state of serial driver initialization */
+int serial_initialized = 0;
+
/*
* void serial_putc(int ch);
* Write character `ch' to port UART_BASE.
@@ -207,7 +210,6 @@ static void serial_init ( void ) {
/* Set clear to send, so flow control works... */
uart_writeb((1<<1), UART_BASE + UART_MCR);
-
/* Flush the input buffer. */
do {
/* rx buffer reg
@@ -217,6 +219,9 @@ static void serial_init ( void ) {
/* line status reg */
status = uart_readb(UART_BASE + UART_LSR);
} while(status & UART_LSR_DR);
+
+ /* Note that serial support has been initialized */
+ serial_initialized = 1;
out:
return;
}
diff --git a/src/core/serial_console.c b/src/core/serial_console.c
index bbddd6b..a901915 100644
--- a/src/core/serial_console.c
+++ b/src/core/serial_console.c
@@ -18,9 +18,12 @@
struct console_driver serial_console __console_driver;
static void serial_console_init ( void ) {
- /* Serial driver initialization should already be done,
- * time to enable the serial console. */
- serial_console.disabled = 0;
+ /*
+ * Check if serial driver initialization is done.
+ * If so, it's time to enable the serial console.
+ */
+ if (serial_initialized)
+ serial_console.disabled = 0;
}
struct console_driver serial_console __console_driver = {
diff --git a/src/include/ipxe/serial.h b/src/include/ipxe/serial.h
index c16e56a..b47b1d1 100644
--- a/src/include/ipxe/serial.h
+++ b/src/include/ipxe/serial.h
@@ -12,5 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
extern void serial_putc ( int ch );
extern int serial_getc ( void );
extern int serial_ischar ( void );
+extern int serial_initialized;
#endif /* _IPXE_SERIAL_H */
--
1.7.11.4
More information about the ipxe-devel
mailing list