Merge branch 'develop' of https://git.minres.com/Firmware/MNRS-BM-BSP into develop

This commit is contained in:
gabriel 2024-01-30 08:42:55 +01:00
commit 532f7e9bb8
7 changed files with 153 additions and 3 deletions

View File

@ -59,9 +59,9 @@ LIBWRAP := libwrap.a
LINK_DEPS += $(LIBWRAP) LINK_DEPS += $(LIBWRAP)
LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=$(s)) LIBWRAP_LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=$(s))
#LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=_$(s)) #LIBWRAP_LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=_$(s))
LDFLAGS += -L. -Wl,--start-group -lwrap -lc -Wl,--end-group LIBWRAP_LDFLAGS += -L. -Wl,--start-group -lwrap -lc -Wl,--end-group
CLEAN_OBJS += $(LIBWRAP_OBJS) CLEAN_OBJS += $(LIBWRAP_OBJS)

1
newlib-nano/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/*.o

16
newlib-nano/lib.mk Normal file
View File

@ -0,0 +1,16 @@
#CFLAGS+=--specs=nano.specs
#LDFLAGS+=--specs=nano.specs
#CFLAGS+=--specs=rv32imac/ilp32/nano.specs
#LDFLAGS+=--specs=rv32imac/ilp32/nano.specs
NANO_LIB_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
NANO_LIB_SYMS := read write syscalls
NANO_LIB_SRCS := $(foreach s,$(NANO_LIB_SYMS),$(NANO_LIB_DIR)/$(s).c)
#NANO_LIB_SRCS := $(foreach f,$(LIB_SRCS),$(LIB_DIR)/$(f))
NANO_LIB_OBJS := $(NANO_LIB_SRCS:.c=.o)
CLEAN_OBJS += $(NANO_LIB_OBJS)
$(NANO_LIB_OBJS): %.o: %.c $(HEADERS)
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

22
newlib-nano/read.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include "stub.h"
#include <platform.h>
ssize_t _read(int fd, void* ptr, size_t len);
ssize_t _read(int fd, void* ptr, size_t len) {
uint8_t * current = (uint8_t *)ptr;
ssize_t result = 0;
if (isatty(fd)) {
for (current = (uint8_t *)ptr;
(current < ((uint8_t *)ptr) + len) && (uart_get_rx_avail(uart) > 0);
current ++) {
*current = uart_read(uart);
result++;
}
return result;
}
return _stub(EBADF);
}

8
newlib-nano/stub.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _LIBWRAP_STUB_H_
#define _LIBWRAP_STUB_H_
static inline int _stub(int err) {
return err?-1:-1;
}
#endif /* _LIBWRAP_STUB_H_ */

79
newlib-nano/syscalls.c Normal file
View File

@ -0,0 +1,79 @@
#include <unistd.h>
#include <sys/stat.h>
extern int _end;
void* _sbrk(int incr);
int _close(int file);
int _fstat(int file, struct stat *st);
int _isatty(int fd);
int _lseek(int file, int ptr, int dir);
void _kill(int pid, int sig);
int _getpid(void);
void write_hex(int fd, unsigned long int hex);
void *_sbrk(int incr) {
static unsigned char *heap = NULL;
unsigned char *prev_heap;
if (heap == NULL) {
heap = (unsigned char *)&_end;
}
prev_heap = heap;
heap += incr;
return prev_heap;
}
int _close(int file) {
(void)file;
return -1;
}
int _fstat(int file, struct stat *st) {
(void)file;
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int fd) {
if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
return 1;
return 0;
}
int _lseek(int file, int ptr, int dir) {
(void)file;
(void)ptr;
(void)dir;
return 0;
}
void _exit(int status) {
const char message[] = "\nProgam has exited with code:";
write(STDERR_FILENO, message, sizeof(message) - 1);
write_hex(STDERR_FILENO, status);
write(STDERR_FILENO, "\n", 1);
for (;;);
}
void _kill(int pid, int sig) {
(void)pid;
(void)sig;
return;
}
int _getpid(void) {
return -1;
}
void write_hex(int fd, unsigned long int hex){
uint8_t ii;
uint8_t jj;
char towrite;
write(fd , "0x", 2);
for (ii = sizeof(unsigned long int) * 2 ; ii > 0; ii--) {
jj = ii - 1;
uint8_t digit = ((hex & (0xF << (jj*4))) >> (jj*4));
towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA));
write(fd, &towrite, 1);
}
}

24
newlib-nano/write.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include "stub.h"
#include <platform.h>
ssize_t _write(int fd, const void* ptr, size_t len);
ssize_t _write(int fd, const void* ptr, size_t len) {
const char * current = (const char *)ptr;
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
while (uart_get_tx_free(uart)==0) ;
uart_write(uart, current[jj]);
if (current[jj] == '\n') {
while (uart_get_tx_free(uart)==0) ;
uart_write(uart, '\r');
}
}
return len;
}
return _stub(EBADF);
}