summaryrefslogtreecommitdiffstats
path: root/src/core/uart.c
diff options
context:
space:
mode:
authorMichael Brown2015-07-31 12:19:19 +0200
committerMichael Brown2015-07-31 12:19:19 +0200
commit2849932c4853ba36edafb5ae16c67e5976d95372 (patch)
tree04b1e744924248d6e45c24655d756c2349d3b61c /src/core/uart.c
parent[comboot] Avoid dragging in serial console support unconditionally (diff)
downloadipxe-2849932c4853ba36edafb5ae16c67e5976d95372.tar.gz
ipxe-2849932c4853ba36edafb5ae16c67e5976d95372.tar.xz
ipxe-2849932c4853ba36edafb5ae16c67e5976d95372.zip
[serial] Check for UART existence in uart_select()
Check for existence of the UART in uart_select(), not just in uart_init(). This allows uart_select() to refuse to set a non-working address in uart->base, which in turns means that the serial console code will not attempt to use a non-existent UART. Reported-by: Torgeir Wulfsberg <Torgeir.Wulfsberg@kongsberg.com> Reported-by: Ján ONDREJ (SAL) <ondrejj@salstar.sk> Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/uart.c')
-rw-r--r--src/core/uart.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/core/uart.c b/src/core/uart.c
index 77721484..b85fe076 100644
--- a/src/core/uart.c
+++ b/src/core/uart.c
@@ -80,20 +80,18 @@ void uart_flush ( struct uart *uart ) {
}
/**
- * Initialise UART
+ * Check for existence of UART
*
* @v uart UART
- * @v baud Baud rate, or zero to leave unchanged
- * @v lcr Line control register value, or zero to leave unchanged
* @ret rc Return status code
*/
-int uart_init ( struct uart *uart, unsigned int baud, uint8_t lcr ) {
- uint8_t dlm;
- uint8_t dll;
+int uart_exists ( struct uart *uart ) {
- /* Check for existence of UART */
+ /* Fail if no UART port is defined */
if ( ! uart->base )
return -ENODEV;
+
+ /* Fail if UART scratch register seems not to be present */
uart_write ( uart, UART_SCR, 0x18 );
if ( uart_read ( uart, UART_SCR ) != 0x18 )
return -ENODEV;
@@ -101,6 +99,26 @@ int uart_init ( struct uart *uart, unsigned int baud, uint8_t lcr ) {
if ( uart_read ( uart, UART_SCR ) != 0xae )
return -ENODEV;
+ return 0;
+}
+
+/**
+ * Initialise UART
+ *
+ * @v uart UART
+ * @v baud Baud rate, or zero to leave unchanged
+ * @v lcr Line control register value, or zero to leave unchanged
+ * @ret rc Return status code
+ */
+int uart_init ( struct uart *uart, unsigned int baud, uint8_t lcr ) {
+ uint8_t dlm;
+ uint8_t dll;
+ int rc;
+
+ /* Check for existence of UART */
+ if ( ( rc = uart_exists ( uart ) ) != 0 )
+ return rc;
+
/* Configure divisor and line control register, if applicable */
if ( ! lcr )
lcr = uart_read ( uart, UART_LCR );