[update][util] update vlibc
This commit is contained in:
parent
eef2ce183c
commit
21529d6a79
@ -105,4 +105,5 @@ endif()
|
|||||||
sdk_library_add_sources(bflb_timestamp/bflb_timestamp.c)
|
sdk_library_add_sources(bflb_timestamp/bflb_timestamp.c)
|
||||||
sdk_add_include_directories(bflb_timestamp)
|
sdk_add_include_directories(bflb_timestamp)
|
||||||
|
|
||||||
|
sdk_add_compile_options(-fno-builtin-printf)
|
||||||
sdk_add_link_options(-u_malloc_r -u_vsnprintf)
|
sdk_add_link_options(-u_malloc_r -u_vsnprintf)
|
@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
struct bflb_device_s *console = NULL;
|
struct bflb_device_s *console = NULL;
|
||||||
|
|
||||||
int puts(const char *fmt) __attribute__((alias("bflb_printf")));
|
int printf(const char *fmt, ...)
|
||||||
int printf(const char *fmt, ...) __attribute__((alias("bflb_printf")));
|
|
||||||
|
|
||||||
int bflb_printf(const char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
char print_buf[128];
|
char print_buf[128];
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
@ -8,11 +8,6 @@
|
|||||||
|
|
||||||
struct bflb_device_s *console = NULL;
|
struct bflb_device_s *console = NULL;
|
||||||
|
|
||||||
void bflb_reg_dump(uint32_t addr)
|
|
||||||
{
|
|
||||||
printf("%08lx[31:0]=%08lx\r\n", addr, *(volatile uint32_t *)(uintptr_t)(addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t __console_output(void *ptr, uint16_t size)
|
uint16_t __console_output(void *ptr, uint16_t size)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
@ -21,18 +16,6 @@ uint16_t __console_output(void *ptr, uint16_t size)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bflb_uart_set_console(struct bflb_device_s *dev)
|
|
||||||
{
|
|
||||||
console = dev;
|
|
||||||
bflb_uart_putchar(console, '\r');
|
|
||||||
vlibc_stdout = vlibc_fopen("<" IOCONSOLE_NAME, "w");
|
|
||||||
vlibc_setvbuf(vlibc_stdout, NULL, _IONBF, 0);
|
|
||||||
vlibc_stderr = vlibc_stdout;
|
|
||||||
|
|
||||||
extern void log_init(void);
|
|
||||||
log_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
__WEAK uint32_t __vlibc_io_init(const char *name, uint8_t mode)
|
__WEAK uint32_t __vlibc_io_init(const char *name, uint8_t mode)
|
||||||
{
|
{
|
||||||
(void)mode;
|
(void)mode;
|
||||||
@ -65,4 +48,61 @@ __WEAK size_t __vlibc_io_mem2dev(struct __vlibc_io *io, const void *ptr, size_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
|
||||||
|
void bflb_dump_hex(const void *ptr, uint32_t buflen)
|
||||||
|
{
|
||||||
|
unsigned char *buf = (unsigned char *)ptr;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < buflen; i += 16) {
|
||||||
|
printf("%08X:", i);
|
||||||
|
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
if (i + j < buflen) {
|
||||||
|
if ((j % 8) == 0) {
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%02X ", buf[i + j]);
|
||||||
|
} else
|
||||||
|
printf(" ");
|
||||||
|
printf(" ");
|
||||||
|
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
if (i + j < buflen)
|
||||||
|
printf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void bflb_reg_dump(uint32_t addr)
|
||||||
|
{
|
||||||
|
printf("%08lx[31:0]=%08lx\r\n", addr, *(volatile uint32_t *)(uintptr_t)(addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
int bflb_data_compare(const uint8_t *expected, uint8_t *input, uint32_t len)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (input[i] != expected[i]) {
|
||||||
|
printf("Compare fail at %d,input %02x, but expect %02x\r\n", i, input[i], expected[i]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bflb_uart_set_console(struct bflb_device_s *dev)
|
||||||
|
{
|
||||||
|
console = dev;
|
||||||
|
bflb_uart_putchar(console, '\r');
|
||||||
|
vlibc_stdout = vlibc_fopen("<" IOCONSOLE_NAME, "w");
|
||||||
|
vlibc_setvbuf(vlibc_stdout, NULL, _IONBF, 0);
|
||||||
|
vlibc_stderr = vlibc_stdout;
|
||||||
|
|
||||||
|
extern void log_init(void);
|
||||||
|
log_init();
|
||||||
}
|
}
|
@ -2,28 +2,20 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "mmheap.h"
|
#include "mmheap.h"
|
||||||
|
#include "bflb_uart.h"
|
||||||
|
|
||||||
extern struct heap_info mmheap_root;
|
extern struct heap_info mmheap_root;
|
||||||
|
|
||||||
#ifdef CONF_VFS_ENABLE
|
extern struct bflb_device_s *console;
|
||||||
#include <vfs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Reentrant versions of system calls. */
|
/* Reentrant versions of system calls. */
|
||||||
|
|
||||||
/* global errno in RT-Thread */
|
/* global errno */
|
||||||
static volatile int _sys_errno = 0;
|
static volatile int _sys_errno = 0;
|
||||||
|
|
||||||
#ifndef _REENT_ONLY
|
#ifndef _REENT_ONLY
|
||||||
int *__errno()
|
int *__errno()
|
||||||
{
|
{
|
||||||
// #if (configUSE_POSIX_ERRNO == 1)
|
|
||||||
// {
|
|
||||||
// extern int FreeRTOS_errno;
|
|
||||||
|
|
||||||
// return &FreeRTOS_errno;
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
return (int *)&_sys_errno;
|
return (int *)&_sys_errno;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -84,108 +76,58 @@ int _link_r(struct _reent *ptr, const char *old, const char *new)
|
|||||||
|
|
||||||
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
|
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
_off_t rc;
|
|
||||||
|
|
||||||
rc = aos_lseek(fd, pos, whence);
|
|
||||||
return rc;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _mkdir_r(struct _reent *ptr, const char *name, int mode)
|
int _mkdir_r(struct _reent *ptr, const char *name, int mode)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = aos_mkdir(name);
|
|
||||||
return rc;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
|
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = aos_open(file, flags);
|
|
||||||
return rc;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _close_r(struct _reent *ptr, int fd)
|
int _close_r(struct _reent *ptr, int fd)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
return aos_close(fd);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
|
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
_ssize_t rc;
|
|
||||||
|
|
||||||
rc = aos_read(fd, buf, nbytes);
|
|
||||||
return rc;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _rename_r(struct _reent *ptr, const char *old, const char *new)
|
int _rename_r(struct _reent *ptr, const char *old, const char *new)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = aos_rename(old, new);
|
|
||||||
return rc;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
|
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = aos_stat(file, pstat);
|
|
||||||
return rc;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _unlink_r(struct _reent *ptr, const char *file)
|
int _unlink_r(struct _reent *ptr, const char *file)
|
||||||
{
|
{
|
||||||
#ifndef CONF_VFS_ENABLE
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = -ENOSYS;
|
ptr->_errno = -ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
return aos_unlink(file);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _wait_r(struct _reent *ptr, int *status)
|
int _wait_r(struct _reent *ptr, int *status)
|
||||||
@ -197,7 +139,10 @@ int _wait_r(struct _reent *ptr, int *status)
|
|||||||
|
|
||||||
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
|
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
return -1;
|
if ((STDOUT_FILENO == fd) || (STDERR_FILENO == fd)) {
|
||||||
|
bflb_uart_put(console, (uint8_t *)buf, nbytes);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *_malloc_r(struct _reent *ptr, size_t size)
|
void *_malloc_r(struct _reent *ptr, size_t size)
|
||||||
|
@ -1314,6 +1314,7 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
|
|||||||
* @param arg
|
* @param arg
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
// int vfprintf(FILE *__restrict, const char *__restrict, __VALIST) __attribute__((alias("vlibc_vfprintf")));
|
||||||
int vlibc_vfprintf(VLIBC_FILE *stream, const char *format, va_list arg)
|
int vlibc_vfprintf(VLIBC_FILE *stream, const char *format, va_list arg)
|
||||||
{
|
{
|
||||||
CHECK_FILE(stream, EOF);
|
CHECK_FILE(stream, EOF);
|
||||||
@ -1389,6 +1390,7 @@ int vlibc_vfprintf(VLIBC_FILE *stream, const char *format, va_list arg)
|
|||||||
* @param arg
|
* @param arg
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
// int vprintf(const char *, __VALIST) __attribute__((alias("vlibc_vprintf")));
|
||||||
int vlibc_vprintf(const char *format, va_list arg)
|
int vlibc_vprintf(const char *format, va_list arg)
|
||||||
{
|
{
|
||||||
return vlibc_vfprintf(vlibc_stdout, format, arg);
|
return vlibc_vfprintf(vlibc_stdout, format, arg);
|
||||||
@ -1402,7 +1404,7 @@ int vlibc_vprintf(const char *format, va_list arg)
|
|||||||
* @param arg
|
* @param arg
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
int vsnprintf (char *, size_t, const char *, va_list) __attribute__ ((alias ("vlibc_vsnprintf")));
|
int vsnprintf(char *__restrict, size_t, const char *__restrict, __VALIST) __attribute__((alias("vlibc_vsnprintf")));
|
||||||
int vlibc_vsnprintf(char *str, size_t size, const char *format, va_list arg)
|
int vlibc_vsnprintf(char *str, size_t size, const char *format, va_list arg)
|
||||||
{
|
{
|
||||||
CHECK_FILE(str, EOF);
|
CHECK_FILE(str, EOF);
|
||||||
@ -1423,6 +1425,7 @@ int vlibc_vsnprintf(char *str, size_t size, const char *format, va_list arg)
|
|||||||
* @param arg
|
* @param arg
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
// int vsprintf(char *__restrict, const char *__restrict, __VALIST) __attribute__((alias("vlibc_vsprintf")));
|
||||||
int vlibc_vsprintf(char *str, const char *format, va_list arg)
|
int vlibc_vsprintf(char *str, const char *format, va_list arg)
|
||||||
{
|
{
|
||||||
return vlibc_vsnprintf(str, PRINTF_MAX_POSSIBLE_BUFFER_SIZE, format, arg);
|
return vlibc_vsnprintf(str, PRINTF_MAX_POSSIBLE_BUFFER_SIZE, format, arg);
|
||||||
@ -1435,6 +1438,7 @@ int vlibc_vsprintf(char *str, const char *format, va_list arg)
|
|||||||
* @param ...
|
* @param ...
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
// int fprintf(FILE *__restrict, const char *__restrict, ...) __attribute__((alias("vlibc_fprintf")));
|
||||||
int vlibc_fprintf(VLIBC_FILE *stream, const char *format, ...)
|
int vlibc_fprintf(VLIBC_FILE *stream, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -1450,8 +1454,7 @@ int vlibc_fprintf(VLIBC_FILE *stream, const char *format, ...)
|
|||||||
* @param ...
|
* @param ...
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
// int puts(const char *__restrict fmt) __attribute__((alias("vlibc_printf")));
|
int printf(const char *__restrict, ...) __attribute__((alias("vlibc_printf")));
|
||||||
// int printf(const char *__restrict fmt, ...) __attribute__((alias("vlibc_printf")));
|
|
||||||
int vlibc_printf(const char *format, ...)
|
int vlibc_printf(const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -1468,6 +1471,7 @@ int vlibc_printf(const char *format, ...)
|
|||||||
* @param ...
|
* @param ...
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
// int sprintf(char *__restrict, const char *__restrict, ...) __attribute__((alias("vlibc_sprintf")));
|
||||||
int vlibc_sprintf(char *str, const char *format, ...)
|
int vlibc_sprintf(char *str, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -1485,6 +1489,7 @@ int vlibc_sprintf(char *str, const char *format, ...)
|
|||||||
* @param ...
|
* @param ...
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
// int snprintf(char *__restrict, size_t, const char *__restrict, ...) __attribute__((alias("vlibc_snprintf")));
|
||||||
int vlibc_snprintf(char *str, size_t size, const char *format, ...)
|
int vlibc_snprintf(char *str, size_t size, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
Reference in New Issue
Block a user