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

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

18
 struct console_driver serial_console __console_driver;
18
 struct console_driver serial_console __console_driver;
19
 
19
 
20
 static void serial_console_init ( void ) {
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
 struct console_driver serial_console __console_driver = {
29
 struct console_driver serial_console __console_driver = {

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

12
 extern void serial_putc ( int ch );
12
 extern void serial_putc ( int ch );
13
 extern int serial_getc ( void );
13
 extern int serial_getc ( void );
14
 extern int serial_ischar ( void );
14
 extern int serial_ischar ( void );
15
+extern int serial_initialized;
15
 
16
 
16
 #endif /* _IPXE_SERIAL_H */
17
 #endif /* _IPXE_SERIAL_H */

Loading…
Cancel
Save