]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[riscv] Inhibit SBI console when a serial console is active
authorMichael Brown <mcb30@ipxe.org>
Mon, 23 Jun 2025 14:07:07 +0000 (15:07 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 23 Jun 2025 14:07:07 +0000 (15:07 +0100)
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 <mcb30@ipxe.org>
src/arch/riscv/interface/sbi/sbi_console.c

index afbe4286e4bef9194353d8beca79c8dccb2424f2..1c3784ec8dadaf900ed8a8bb9fd6f6cb2e6e902d 100644 (file)
@@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/sbi.h>
 #include <ipxe/io.h>
 #include <ipxe/keys.h>
+#include <ipxe/serial.h>
 #include <ipxe/console.h>
 #include <config/console.h>
 
@@ -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 ),