From: Michael Brown Date: Mon, 23 Jun 2025 14:07:07 +0000 (+0100) Subject: [riscv] Inhibit SBI console when a serial console is active X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=d1823eb67740ce46ebc08226484447bfd463fe2c;p=thirdparty%2Fipxe.git [riscv] Inhibit SBI console when a serial console is active When a native serial driver is enabled for the system console device specified via "/chosen/stdout-path", it is very likely that this will correspond to the same physical serial port used for the SBI debug console. Inhibit input and output via the SBI console whenever a serial console is active, to avoid duplicated output characters and unpredictable input behaviour. Signed-off-by: Michael Brown --- diff --git a/src/arch/riscv/interface/sbi/sbi_console.c b/src/arch/riscv/interface/sbi/sbi_console.c index afbe4286e..1c3784ec8 100644 --- a/src/arch/riscv/interface/sbi/sbi_console.c +++ b/src/arch/riscv/interface/sbi/sbi_console.c @@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include #include #include @@ -43,6 +44,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); extern void early_uart_putchar ( int character ); +/** Dummy serial console (if not present in build) */ +struct uart *serial_console __attribute__ (( weak )); + /** Buffered input character (if any) */ static unsigned char sbi_console_input; @@ -54,6 +58,10 @@ static unsigned char sbi_console_input; static void sbi_putchar ( int character ) { struct sbi_return ret; + /* Do nothing if a real serial console has been enabled */ + if ( serial_console ) + return; + /* Write byte to early UART, if enabled */ early_uart_putchar ( character ); @@ -99,6 +107,10 @@ static int sbi_iskey ( void ) { if ( sbi_console_input ) return sbi_console_input; + /* Do nothing if a real serial console has been enabled */ + if ( serial_console ) + return 0; + /* Read and buffer byte from console, if any */ ret = sbi_ecall_3 ( SBI_DBCN, SBI_DBCN_READ, sizeof ( sbi_console_input ),