]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[riscv] Write SBI console output to early UART, if enabled
authorMichael Brown <mcb30@ipxe.org>
Thu, 12 Jun 2025 11:57:26 +0000 (12:57 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 12 Jun 2025 11:57:26 +0000 (12:57 +0100)
The early UART is an optional feature used to obtain debug output from
the prefix before iPXE is able to parse the device tree.

Extend this feature to also cover any console output that iPXE
attempts to send to the SBI console, on the basis that the purpose of
the early UART is to provide an output-only device for situations in
which there is no functional SBI console.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/riscv/interface/sbi/sbi_console.c
src/arch/riscv/prefix/libprefix.S

index c993ebc0ab9b37f960cf37e792a1eb580c7a2275..afbe4286e4bef9194353d8beca79c8dccb2424f2 100644 (file)
@@ -41,6 +41,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define CONSOLE_SBI ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
 #endif
 
+extern void early_uart_putchar ( int character );
+
 /** Buffered input character (if any) */
 static unsigned char sbi_console_input;
 
@@ -52,6 +54,9 @@ static unsigned char sbi_console_input;
 static void sbi_putchar ( int character ) {
        struct sbi_return ret;
 
+       /* Write byte to early UART, if enabled */
+       early_uart_putchar ( character );
+
        /* Write byte to console */
        ret = sbi_ecall_1 ( SBI_DBCN, SBI_DBCN_WRITE_BYTE, character );
        if ( ! ret.error )
index 41e63b3f168f7e46cc9f4a2004ecb49bec518b47..cf62338b5e20151a722a0c439e15fd467f09a2b9 100644 (file)
@@ -243,6 +243,32 @@ early_uart_sifive_wait_\@:
        bltz    a1, early_uart_sifive_wait_\@
        .endm
 
+/*****************************************************************************
+ *
+ * Print single character to early UART (from C code)
+ *
+ *****************************************************************************
+ *
+ * This function is called by the SBI console driver to output a
+ * character to the early UART (if enabled).
+ *
+ * The standard C ABI applies to this function.
+ *
+ * Parameters:
+ *
+ *   a0 - Character to print
+ *
+ * Returns: none
+ *
+ */
+
+       .section ".prefix.early_uart_putchar", "ax", @progbits
+       .globl  early_uart_putchar
+early_uart_putchar:
+       print_char_uart
+       ret
+       .size   early_uart_putchar, . - early_uart_putchar
+
 /*****************************************************************************
  *
  * Print message to debug console