1、add 'menuconfig' function for XiZi_AIoT with imx6q-sabrelite board;2、add compilation function for AIoT system with imx6q-sabrelite board;3、add newlib base files;4、add startup files and irq function for imx6q-sabrelite

This commit is contained in:
Wang_Weigen
2022-12-30 17:59:41 +08:00
parent ce60710fe6
commit 6b091797ae
60 changed files with 2726 additions and 182 deletions
+23
View File
@@ -0,0 +1,23 @@
menu "Lib"
menuconfig LIB
bool "Enable libc APIs from toolchain"
default y
if LIB
config LIB_POSIX
bool "Enable POSIX layer for poll/select, stdin etc"
default y
choice
prompt "select libc"
default LIB_NEWLIB
config LIB_NEWLIB
bool "use newlib as libc realization."
config LIB_MUSLLIB
bool "use musllib as libc realization."
endchoice
endif
endmenu
@@ -0,0 +1,14 @@
SRC_DIR :=
MUSL_DIR :=
ifeq ($(CONFIG_LIB_NEWLIB),y)
SRC_DIR += newlib
endif
ifeq ($(CONFIG_LIB_MUSLLIB), y)
# SRC_DIR += musllib
# MUSL_DIR += musllib
endif
include $(KERNEL_ROOT)/compiler.mk
@@ -0,0 +1,6 @@
menu LIB_NEWLIB
bool "Enable Newlib "
default y
endmenu
@@ -0,0 +1,5 @@
SRC_FILES := fs_syscalls.c time_syscalls.c mem_syscalls.c task_syscalls.c
include $(KERNEL_ROOT)/compiler.mk
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/**
* @file fs_syscalls.c
* @brief support newlib file system
* @version 1.0
* @author AIIT XUOS Lab
* @date 2020-09-23
*/
/*************************************************
File name: fs_syscalls.c
Description: support newlib file system
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2020-09-23
Author: AIIT XUOS Lab
Modification: Use file system functions
*************************************************/
#include <reent.h>
#include <stdio.h>
#include <errno.h>
/* wwg debug here */
// #include <xizi.h>
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _link_r(struct _reent *ptr, const char *old, const char *new)
{
ptr->_errno = ENOTSUP;
return -1;
}
void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
return NULL;
}
int _wait_r(struct _reent *ptr, int *status)
{
ptr->_errno = ENOTSUP;
return -1;
}
#ifdef FS_VFS
#include <iot-vfs_posix.h>
int _close_r(struct _reent *ptr, int fd)
{
return close(fd);
}
int _isatty_r(struct _reent *ptr, int fd)
{
if (fd >=0 && fd < 3)
return 1;
ptr->_errno = ENOTSUP;
return -1;
}
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
return lseek(fd, pos, whence);
}
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
return open(file, flags, mode);
}
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
return read(fd, buf, nbytes);
}
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
return stat(file, pstat);
}
int _unlink_r(struct _reent *ptr, const char *file)
{
return unlink(file);
}
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
return write(fd, buf, nbytes);
}
#else /* FS_VFS */
int _close_r(struct _reent *ptr, int fd)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _isatty_r(struct _reent *ptr, int fd)
{
ptr->_errno = ENOTSUP;
return -1;
}
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
ptr->_errno = ENOTSUP;
return -1;
}
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _unlink_r(struct _reent *ptr, const char *file)
{
ptr->_errno = ENOTSUP;
return -1;
}
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
ptr->_errno = ENOTSUP;
return -1;
}
#endif /* FS_VFS */
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file libc.h
* @brief using newlib need include
* @version 1.0
* @author AIIT XUOS Lab
* @date 2020-09-23
*/
#ifndef _LIBC_H__
#define _LIBC_H__
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#endif
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/**
* @file mem_syscalls.c
* @brief support newlib memory
* @version 1.0
* @author AIIT XUOS Lab
* @date 2020-09-23
*/
/*************************************************
File name: mem_syscalls.c
Description: support newlib memory
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2020-09-23
Author: AIIT XUOS Lab
Modification: Use malloc, realloc, calloc and free functions
*************************************************/
/* wwg debug here */
// #include <xizi.h>
#include <errno.h>
void *_malloc_r (struct _reent *ptr, size_t size)
{
/* wwg debug here */
// void* result = (void*)x_malloc(size);
void* result = NULL;
if (result == NULL)
{
ptr->_errno = ENOMEM;
}
return result;
}
void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
{
/* wwg debug here */
// void* result = (void*)x_realloc(old, newlen);
void* result = NULL;
if (result == NULL)
{
ptr->_errno = ENOMEM;
}
return result;
}
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
{
/* wwg debug here */
// void* result = (void*)x_calloc(size, len);
void* result = NULL;
if (result == NULL)
{
ptr->_errno = ENOMEM;
}
return result;
}
void _free_r (struct _reent *ptr, void *address)
{
/* wwg debug here */
// x_free (address);
}
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
/**
* @file stdio.c
* @brief support newlib stdio
* @version 1.0
* @author AIIT XUOS Lab
* @date 2020-09-23
*/
/*************************************************
File name: stdio.c
Description: support newlib stdio
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/stdio.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2020-09-23
Author: AIIT XUOS Lab
Modification: Use set and get console functions
*************************************************/
#include <xizi.h>
#include <device.h>
#include <stdio.h>
#include <stdlib.h>
#define STDIO_DEVICE_NAME_MAX 32
static FILE* std_console = NULL;
/**
* This function will set system console device.
*
* @param device_name the name of device
* @param mode the mode
*
* @return file number on success; or -1 on failure
*/
int LibcStdioSetConsole(const char* device_name, int mode)
{
FILE *fp;
char name[STDIO_DEVICE_NAME_MAX] = {0};
char *file_mode;
snprintf(name, strlen(device_name) + 6, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
switch (mode)
{
case O_RDWR:
file_mode = "r+";
break;
case O_WRONLY:
file_mode = "wb";
break;
default:
file_mode = "rb";
break;
}
/* try to open file */
fp = fopen(name, file_mode);
if (fp)
{
/* set the fp buffer */
setvbuf(fp, NULL, _IONBF, 0);
if (std_console)
/* try to close console device */
fclose(std_console);
std_console = fp;
if (mode == O_RDWR)
{
/* set _stdin as std_console */
_GLOBAL_REENT->_stdin = std_console;
}
else
{
/* set NULL */
_GLOBAL_REENT->_stdin = NULL;
}
if (mode == O_RDONLY)
{
/* set the _stdout as NULL */
_GLOBAL_REENT->_stdout = NULL;
/* set the _stderr as NULL */
_GLOBAL_REENT->_stderr = NULL;
}
else
{
/* set the _stdout as std_console */
_GLOBAL_REENT->_stdout = std_console;
/* set the _stderr as std_console */
_GLOBAL_REENT->_stderr = std_console;
}
/* set the __sdidinit as 1 */
_GLOBAL_REENT->__sdidinit = 1;
}
if (std_console)
/* return the file number */
return fileno(std_console);
/* failure and return -1 */
return -1;
}
/**
* This function will get system console device.
*
* @return file number on success; or -1 on failure
*/
int LibcStdioGetConsole(void) {
if (std_console)
/* return the file number */
return fileno(std_console);
else
/* failure and return -1 */
return -1;
}
/**
* This function will initialize the c library system.
*
* @return 0
*/
int LibcSystemInit(void)
{
#if defined(KERNEL_CONSOLE)
HardwareDevType console;
/* try to get console device */
console = ObtainConsole();
if (console)
{
#if defined(LIB_POSIX)
/* set console device mode */
LibcStdioSetConsole(console->dev_name, O_RDWR);
#else
/* set console device mode */
LibcStdioSetConsole(console->dev_name, O_WRONLY);
#endif
}
#endif
return 0;
}
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/**
* @file task_syscalls.c
* @brief support newlib abort
* @version 1.0
* @author AIIT XUOS Lab
* @date 2020-09-23
*/
/*************************************************
File name: task_syscalls.c
Description: support newlib abort
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2020-09-23
Author: AIIT XUOS Lab
Modification: Use abort function
*************************************************/
/* wwg debug here */
// #include <xizi.h>
void abort(void)
{
// KTaskDescriptorType current = GetKTaskDescriptor();
// if (current)
// {
// KPrintf("Task:%-8.*s will be aborted!\n", NAME_NUM_MAX, current->task_base_info.name);
// /* pend current task */
// SuspendKTask(current->id.id);
// /* schedule */
// DO_KTASK_ASSIGN;
// }
while (1);
}
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include <sys/time.h>
// #include <xizi.h>
// #include <bus_rtc.h>
// time_t time(time_t *t)
// {
// NULL_PARAM_CHECK(t);
// time_t current = 0;
// #ifdef RESOURCES_RTC
// struct RtcSetParam rtc_set_param;
// rtc_set_param.rtc_set_cmd = OPER_RTC_GET_TIME;
// rtc_set_param.time = &current;
// RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
// #endif
// *t = current;
// return current;
// }
time_t time(time_t *t)
{
time_t current = 0;
*t = current;
return current;
}