Browse Source

[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.

Reported-by: Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
Signed-off-by: Shao Miller <sha0.miller@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Shao Miller 11 years ago
parent
commit
a712dae709
3 changed files with 13 additions and 4 deletions
  1. 6
    1
      src/core/serial.c
  2. 6
    3
      src/core/serial_console.c
  3. 1
    0
      src/include/ipxe/serial.h

+ 6
- 1
src/core/serial.c View File

@@ -93,6 +93,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
93 93
 #define uart_writeb(val,addr) outb((val),(addr))
94 94
 #endif
95 95
 
96
+/* Boolean for the state of serial driver initialization */
97
+int serial_initialized = 0;
98
+
96 99
 /*
97 100
  * void serial_putc(int ch);
98 101
  *	Write character `ch' to port UART_BASE.
@@ -207,7 +210,6 @@ static void serial_init ( void ) {
207 210
 	/* Set clear to send, so flow control works... */
208 211
 	uart_writeb((1<<1), UART_BASE + UART_MCR);
209 212
 
210
-
211 213
 	/* Flush the input buffer. */
212 214
 	do {
213 215
 		/* rx buffer reg
@@ -217,6 +219,9 @@ static void serial_init ( void ) {
217 219
 		/* line status reg */
218 220
 		status = uart_readb(UART_BASE + UART_LSR);
219 221
 	} while(status & UART_LSR_DR);
222
+
223
+	/* Note that serial support has been initialized */
224
+	serial_initialized = 1;
220 225
  out:
221 226
 	return;
222 227
 }

+ 6
- 3
src/core/serial_console.c View File

@@ -18,9 +18,12 @@
18 18
 struct console_driver serial_console __console_driver;
19 19
 
20 20
 static void serial_console_init ( void ) {
21
-	/* Serial driver initialization should already be done,
22
-	 * time to enable the serial console. */
23
-	serial_console.disabled = 0;
21
+	/*
22
+	 * Check if serial driver initialization is done.
23
+	 * If so, it's time to enable the serial console.
24
+	 */
25
+	if ( serial_initialized )
26
+		serial_console.disabled = 0;
24 27
 }
25 28
 
26 29
 struct console_driver serial_console __console_driver = {

+ 1
- 0
src/include/ipxe/serial.h View File

@@ -12,5 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 extern void serial_putc ( int ch );
13 13
 extern int serial_getc ( void );
14 14
 extern int serial_ischar ( void );
15
+extern int serial_initialized;
15 16
 
16 17
 #endif /* _IPXE_SERIAL_H */

Loading…
Cancel
Save