From 0188d404ded6c83ad4ac7e49724292b361eeb6a4 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 24 Nov 2023 11:39:23 +0100 Subject: [PATCH] fixes hifive1 build --- bare-metal-bsp/env/common-gcc.mk | 1 + bare-metal-bsp/libwrap/sys/_exit.c | 6 ++++++ bare-metal-bsp/libwrap/sys/read.c | 33 +++++++++++++++++------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/bare-metal-bsp/env/common-gcc.mk b/bare-metal-bsp/env/common-gcc.mk index 061521c..ffe4d6b 100644 --- a/bare-metal-bsp/env/common-gcc.mk +++ b/bare-metal-bsp/env/common-gcc.mk @@ -45,6 +45,7 @@ else endif CFLAGS += -mabi=$(RISCV_ABI) CFLAGS += -mcmodel=medany +CFLAGS += -DBOARD_$(BOARD) TRIPLET?=riscv64-unknown-elf CXX=$(TOOL_DIR)$(TRIPLET)-c++ diff --git a/bare-metal-bsp/libwrap/sys/_exit.c b/bare-metal-bsp/libwrap/sys/_exit.c index ed3caa0..19d3a58 100644 --- a/bare-metal-bsp/libwrap/sys/_exit.c +++ b/bare-metal-bsp/libwrap/sys/_exit.c @@ -4,8 +4,14 @@ #include "platform.h" #include "weak_under_alias.h" +#if defined(BOARD_hifive1) +static volatile uint32_t tohost; +static volatile uint32_t fromhost; +#else extern volatile uint32_t tohost; extern volatile uint32_t fromhost; +#endif + void write_hex(int fd, uint32_t hex); void __wrap_exit(int code) diff --git a/bare-metal-bsp/libwrap/sys/read.c b/bare-metal-bsp/libwrap/sys/read.c index 7910756..06bafb2 100644 --- a/bare-metal-bsp/libwrap/sys/read.c +++ b/bare-metal-bsp/libwrap/sys/read.c @@ -11,23 +11,28 @@ ssize_t __wrap_read(int fd, void* ptr, size_t len) { - uint8_t * current = (uint8_t *)ptr; - volatile uint32_t * uart_rx = (uint32_t *)(UART0_BASE_ADDR + UART_REG_RXFIFO); - volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_BASE_ADDR + UART_REG_RXCTRL + 2); +#if defined(BOARD_hifive1) + uint8_t * current = (uint8_t *)ptr; + volatile uint32_t * uart_rx = (uint32_t *)(UART0_CTRL_ADDR + UART_REG_RXFIFO); + volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_CTRL_ADDR + UART_REG_RXCTRL + 2); +#else + uint8_t * current = (uint8_t *)ptr; + volatile uint32_t * uart_rx = (uint32_t *)(UART0_BASE_ADDR + UART_REG_RXFIFO); + volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_BASE_ADDR + UART_REG_RXCTRL + 2); +#endif - ssize_t result = 0; + ssize_t result = 0; - if (isatty(fd)) { - for (current = (uint8_t *)ptr; - (current < ((uint8_t *)ptr) + len) && (*uart_rx_cnt > 0); - current ++) { - *current = *uart_rx; - result++; + if (isatty(fd)) { + for (current = (uint8_t *)ptr; + (current < ((uint8_t *)ptr) + len) && (*uart_rx_cnt > 0); + current ++) { + *current = *uart_rx; + result++; + } + return result; } - return result; - } - - return _stub(EBADF); + return _stub(EBADF); } weak_under_alias(read);