[serial] Allow platform to specify mechanism for identifying console

Allow the platform configuration to provide a mechanism for
identifying the serial console UART.  Provide two globally available
mechanisms: "null" (i.e. no serial console), and "fixed" (i.e. use
whatever is specified by COMCONSOLE in config/serial.h).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-06-23 16:19:07 +01:00
parent 5d9f20bbd6
commit 2ce1b185b2
7 changed files with 82 additions and 5 deletions

View File

@@ -45,6 +45,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define CONSOLE_SERIAL ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
#endif
#ifdef SERIAL_FIXED
#define SERIAL_PREFIX_fixed
#else
#define SERIAL_PREFIX_fixed __fixed_
#endif
/* Serial console UART */
#ifndef COMCONSOLE
#define COMCONSOLE NULL
@@ -55,12 +61,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define COMSPEED 0
#endif
/** Default serial console UART */
static struct uart * const default_serial_console = COMCONSOLE;
/** Active serial console UART */
struct uart *serial_console;
/**
* Get fixed serial console UART
*
* @ret uart Serial console UART, or NULL
*/
static struct uart * serial_comconsole ( void ) {
return COMCONSOLE;
}
/**
* Print a character to serial console
*
@@ -128,10 +141,11 @@ struct console_driver serial_console_driver __console_driver = {
/** Initialise serial console */
static void serial_init ( void ) {
struct uart *uart = default_serial_console;
struct uart *uart;
int rc;
/* Do nothing if we have no default port */
/* Get default serial console, if any */
uart = default_serial_console();
if ( ! uart )
return;
@@ -174,3 +188,6 @@ struct startup_fn serial_startup_fn __startup_fn ( STARTUP_EARLY ) = {
.name = "serial",
.shutdown = serial_shutdown,
};
PROVIDE_SERIAL_INLINE ( null, default_serial_console );
PROVIDE_SERIAL ( fixed, default_serial_console, serial_comconsole );