From 1ce194007b684086dcf6af000fce946e36ffc445 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 8 Jan 2021 19:18:44 +0100 Subject: [PATCH] software: allow BIOS compilation with UART disabled. --- litex/soc/software/bios/boot.c | 4 ++++ litex/soc/software/bios/cmds/cmd_boot.c | 2 ++ litex/soc/software/bios/isr.c | 2 ++ litex/soc/software/bios/main.c | 22 +++++++++++--------- litex/soc/software/libbase/console.c | 27 +++++++++++++++++++++++++ litex/soc/software/libbase/uart.c | 4 ++++ 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 64e0ffae5..ed2174f44 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -100,6 +100,8 @@ void romboot(void) /* Serial Boot */ /*-----------------------------------------------------------------------*/ +#ifdef CSR_UART_BASE + static int check_ack(void) { int recognized; @@ -265,6 +267,8 @@ int serialboot(void) return 1; } +#endif + /*-----------------------------------------------------------------------*/ /* Ethernet Boot */ /*-----------------------------------------------------------------------*/ diff --git a/litex/soc/software/bios/cmds/cmd_boot.c b/litex/soc/software/bios/cmds/cmd_boot.c index e46e8e97b..24743bf15 100644 --- a/litex/soc/software/bios/cmds/cmd_boot.c +++ b/litex/soc/software/bios/cmds/cmd_boot.c @@ -50,7 +50,9 @@ define_command(romboot, romboot, "Boot from ROM", BOOT_CMDS); * Boot software from serial interface * */ +#ifdef CSR_UART_BASE define_command(serialboot, serialboot, "Boot from Serial (SFL)", BOOT_CMDS); +#endif /** * Command "netboot" diff --git a/litex/soc/software/bios/isr.c b/litex/soc/software/bios/isr.c index e7bf91afc..a7fe63aee 100644 --- a/litex/soc/software/bios/isr.c +++ b/litex/soc/software/bios/isr.c @@ -151,10 +151,12 @@ void isr(void) irqs = irq_pending() & irq_getmask(); +#ifdef CSR_UART_BASE #ifndef UART_POLLING if(irqs & (1 << UART_INTERRUPT)) uart_isr(); #endif +#endif } #endif diff --git a/litex/soc/software/bios/main.c b/litex/soc/software/bios/main.c index 0ffb03bdf..86a797fef 100644 --- a/litex/soc/software/bios/main.c +++ b/litex/soc/software/bios/main.c @@ -49,27 +49,29 @@ static void boot_sequence(void) { - if(serialboot()) { +#ifdef CSR_UART_BASE + if (serialboot() == 0) + return; +#endif #ifdef FLASH_BOOT_ADDRESS - flashboot(); + flashboot(); #endif #ifdef ROM_BOOT_ADDRESS - romboot(); + romboot(); #endif #if defined(CSR_SPISDCARD_BASE) || defined(CSR_SDCORE_BASE) - sdcardboot(); + sdcardboot(); #endif #if defined(CSR_SATA_SECTOR2MEM_BASE) - sataboot(); + sataboot(); #endif #ifdef CSR_ETHMAC_BASE #ifdef CSR_ETHPHY_MODE_DETECTION_MODE_ADDR - eth_mode(); + eth_mode(); #endif - netboot(); + netboot(); #endif - printf("No boot medium found\n"); - } + printf("No boot medium found\n"); } int main(int i, char **c) @@ -85,7 +87,9 @@ int main(int i, char **c) irq_setmask(0); irq_setie(1); #endif +#ifdef CSR_UART_BASE uart_init(); +#endif printf("\n"); printf("\e[1m __ _ __ _ __\e[0m\n"); diff --git a/litex/soc/software/libbase/console.c b/litex/soc/software/libbase/console.c index 7861a1d98..ec434643b 100644 --- a/litex/soc/software/libbase/console.c +++ b/litex/soc/software/libbase/console.c @@ -3,6 +3,8 @@ #include #include +#include + FILE *stdin, *stdout, *stderr; static console_write_hook write_hook; @@ -20,6 +22,7 @@ void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn) read_nonblock_hook = rn; } +#ifdef CSR_UART_BASE int putchar(int c) { uart_write(c); @@ -46,6 +49,30 @@ int readchar_nonblock(void) || ((read_nonblock_hook != NULL) && read_nonblock_hook())); } +#else + +int putchar(int c) +{ + if(write_hook != NULL) + write_hook(c); + return c; +} + +char readchar(void) +{ + while(1) { + if((read_nonblock_hook != NULL) && read_nonblock_hook()) + return read_hook(); + } +} + +int readchar_nonblock(void) +{ + return ((read_nonblock_hook != NULL) && read_nonblock_hook()); +} + +#endif + int puts(const char *s) { while(*s) { diff --git a/litex/soc/software/libbase/uart.c b/litex/soc/software/libbase/uart.c index 81aa128b4..0f4b76c82 100644 --- a/litex/soc/software/libbase/uart.c +++ b/litex/soc/software/libbase/uart.c @@ -2,6 +2,8 @@ #include #include +#ifdef CSR_UART_BASE + /* * Buffer sizes must be a power of 2 so that modulos can be computed * with logical AND. @@ -150,4 +152,6 @@ void uart_sync(void) while (uart_txfull_read()); } +#endif + #endif \ No newline at end of file