summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorMan, Jianting (Meco) <[email protected]>2022-11-22 21:40:50 -0500
committerGitHub <[email protected]>2022-11-22 21:40:50 -0500
commitbdd663a33fb0af8864344a7bf568a706669d96d4 (patch)
treebae6015a528c29a38a2630670aa382d07322b771 /components
parentfc83546cf5b7a412b9f191488cd50c90d22c93c6 (diff)
[libc][musl] support arm-linux-musleabi toolchain
目前基本功能已经可以在QEMU上跑起来,但是pthread和内核signal选中会报冲突。先合并一版本,后续解决这些问题。
Diffstat (limited to 'components')
-rw-r--r--components/dfs/src/dfs_posix.c2
-rw-r--r--components/libc/compilers/common/include/sys/select.h2
-rw-r--r--components/libc/compilers/common/include/sys/signal.h15
-rw-r--r--components/libc/compilers/common/include/sys/time.h31
-rw-r--r--components/libc/compilers/musl/SConscript30
-rw-r--r--components/libc/compilers/musl/syscalls.c20
-rw-r--r--components/libc/compilers/newlib/SConscript33
-rw-r--r--components/libc/posix/io/stdio/libc.c66
8 files changed, 151 insertions, 48 deletions
diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c
index c406dd5fdb..ed0647121d 100644
--- a/components/dfs/src/dfs_posix.c
+++ b/components/dfs/src/dfs_posix.c
@@ -762,7 +762,7 @@ RTM_EXPORT(telldir);
* @param d the directory stream.
* @param offset the offset in directory stream.
*/
-void seekdir(DIR *d, off_t offset)
+void seekdir(DIR *d, long offset)
{
struct dfs_fd *fd;
diff --git a/components/libc/compilers/common/include/sys/select.h b/components/libc/compilers/common/include/sys/select.h
index 9004658be9..32ce39c287 100644
--- a/components/libc/compilers/common/include/sys/select.h
+++ b/components/libc/compilers/common/include/sys/select.h
@@ -12,7 +12,7 @@
#ifndef __SYS_SELECT_H__
#define __SYS_SELECT_H__
-#include <rtthread.h>
+#include <rtconfig.h>
#include <sys/types.h>
#include <sys/time.h>
diff --git a/components/libc/compilers/common/include/sys/signal.h b/components/libc/compilers/common/include/sys/signal.h
index dbd947acb9..b92276ecb1 100644
--- a/components/libc/compilers/common/include/sys/signal.h
+++ b/components/libc/compilers/common/include/sys/signal.h
@@ -14,12 +14,11 @@
#ifdef __cplusplus
extern "C" {
-#endif
+#endif /* __cplusplus */
#include <stdint.h>
#include <sys/types.h>
-
/* sigev_notify values
NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
@@ -54,7 +53,6 @@ struct siginfo
{
uint16_t si_signo;
uint16_t si_code;
-
union sigval si_value;
};
typedef struct siginfo siginfo_t;
@@ -216,17 +214,16 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
#define SIGUSR2 31 /* user defined signal 2 */
#define NSIG 32 /* signal 0 implied */
-#ifndef _SIGNAL_H_
+#if defined(RT_USING_NEWLIBC)
/* Some applications take advantage of the fact that <sys/signal.h>
* and <signal.h> are equivalent in glibc. Allow for that here. */
#include <signal.h>
-#endif
-
-#endif
+#endif /* defined(RT_USING_NEWLIBC) */
+#endif /* __ARMCC_VERSION */
#ifdef __cplusplus
}
-#endif
+#endif /* __cplusplus */
-#endif
+#endif /* __SYS_SIGNAL_H__ */
diff --git a/components/libc/compilers/common/include/sys/time.h b/components/libc/compilers/common/include/sys/time.h
index 346320bff0..e3bf3ee4ef 100644
--- a/components/libc/compilers/common/include/sys/time.h
+++ b/components/libc/compilers/common/include/sys/time.h
@@ -22,7 +22,7 @@ typedef __time64_t time_t;
#ifdef __cplusplus
extern "C" {
-#endif
+#endif /* __cplusplus */
#undef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC RT_TICK_PER_SECOND
@@ -79,22 +79,21 @@ int stime(const time_t *t);
time_t timegm(struct tm * const t);
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv, const struct timezone *tz);
-#if defined(__ARMCC_VERSION) || defined (__ICCARM__)
+
+#if defined(__ARMCC_VERSION) || defined (__ICCARM__) || defined(_WIN32)
struct tm *gmtime_r(const time_t *timep, struct tm *r);
-struct tm* localtime_r(const time_t* t, struct tm* r);
char* asctime_r(const struct tm *t, char *buf);
char *ctime_r(const time_t * tim_p, char * result);
-#elif defined(_WIN32)
-struct tm* gmtime_r(const time_t* timep, struct tm* r);
-struct tm* gmtime(const time_t* t);
struct tm* localtime_r(const time_t* t, struct tm* r);
+#endif /* defined(__ARMCC_VERSION) || defined (__ICCARM__) || defined(_WIN32) */
+
+#ifdef _WIN32
+struct tm* gmtime(const time_t* t);
struct tm* localtime(const time_t* t);
time_t mktime(struct tm* const t);
-char* asctime_r(const struct tm* t, char* buf);
-char* ctime_r(const time_t* tim_p, char* result);
char* ctime(const time_t* tim_p);
time_t time(time_t* t);
-#endif
+#endif /* _WIN32 */
#ifdef RT_USING_POSIX_DELAY
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
@@ -112,20 +111,21 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 1
-#endif
+#endif /* CLOCK_REALTIME */
#define CLOCK_CPUTIME_ID 2
#ifndef CLOCK_PROCESS_CPUTIME_ID
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
-#endif
+#endif /* CLOCK_PROCESS_CPUTIME_ID */
+
#ifndef CLOCK_THREAD_CPUTIME_ID
#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
-#endif
+#endif /* CLOCK_THREAD_CPUTIME_ID */
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC 4
-#endif
+#endif /* CLOCK_MONOTONIC */
#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */
#ifdef RT_USING_POSIX_CLOCK
@@ -142,8 +142,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
int timer_delete(timer_t timerid);
int timer_getoverrun(timer_t timerid);
int timer_gettime(timer_t timerid, struct itimerspec *its);
-int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
- struct itimerspec *ovalue);
+int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);
#endif /* RT_USING_POSIX_TIMER */
/* timezone */
@@ -153,6 +152,6 @@ int8_t tz_is_dst(void);
#ifdef __cplusplus
}
-#endif
+#endif /* __cplusplus */
#endif /* _SYS_TIME_H_ */
diff --git a/components/libc/compilers/musl/SConscript b/components/libc/compilers/musl/SConscript
new file mode 100644
index 0000000000..9bc5696157
--- /dev/null
+++ b/components/libc/compilers/musl/SConscript
@@ -0,0 +1,30 @@
+import os
+from building import *
+from gcc import *
+Import('rtconfig')
+
+group = []
+
+libc_name, libc_version = GetGCCLibcNameVersion(rtconfig)
+
+if libc_name == 'musl':
+ print('Musl version: ' + libc_version)
+
+ cwd = GetCurrentDir()
+ src = Glob('*.c')
+
+ CPPPATH = [cwd]
+ CPPDEFINES = ['RT_USING_MUSLLIBC', 'RT_USING_LIBC']
+ LIBS = ['c', 'gcc']
+ LINKFLAGS = ' --specs=kernel.specs'
+ AddDepend(['RT_USING_MUSLLIBC', 'RT_USING_LIBC'])
+
+ group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, LINKFLAGS = LINKFLAGS, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+
+ list = os.listdir(cwd)
+ for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
+
+Return('group')
diff --git a/components/libc/compilers/musl/syscalls.c b/components/libc/compilers/musl/syscalls.c
new file mode 100644
index 0000000000..6d412cc0a1
--- /dev/null
+++ b/components/libc/compilers/musl/syscalls.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-11-18 Meco Man first version
+ */
+
+#include <rtthread.h>
+
+int *__errno_location(void)
+{
+ return _rt_errno();
+}
+int *___errno_location(void)
+{
+ return _rt_errno();
+}
diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript
index dd8966d5bd..14d3f737f5 100644
--- a/components/libc/compilers/newlib/SConscript
+++ b/components/libc/compilers/newlib/SConscript
@@ -3,28 +3,27 @@ from building import *
from gcc import *
Import('rtconfig')
-src = []
-cwd = GetCurrentDir()
group = []
-LIBS = []
-CPPPATH = [cwd]
-if rtconfig.PLATFORM in ['gcc']:
- LIBS += ['c', 'm'] # link libc and libm
- src += Glob('*.c')
+libc_name, libc_version = GetGCCLibcNameVersion(rtconfig)
- #report newlib version
- print('Newlib version:' + GetNewLibVersion(rtconfig))
+if libc_name == 'newlib':
+ print('Newlib version: ' + libc_version)
- # identify this is Newlib, and only enable POSIX.1-1990
- CPPDEFINES = ['RT_USING_NEWLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1']
+ cwd = GetCurrentDir()
+ src = Glob('*.c')
+
+ CPPPATH = [cwd]
+ CPPDEFINES = ['RT_USING_NEWLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1'] # identify this is Newlib, and only enable POSIX.1-1990
+ LIBS = ['c', 'm'] # link libc and libm
AddDepend(['RT_USING_NEWLIBC', 'RT_USING_LIBC'])
- group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
-list = os.listdir(cwd)
-for d in list:
- path = os.path.join(cwd, d)
- if os.path.isfile(os.path.join(path, 'SConscript')):
- group = group + SConscript(os.path.join(d, 'SConscript'))
+ group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+
+ list = os.listdir(cwd)
+ for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
Return('group')
diff --git a/components/libc/posix/io/stdio/libc.c b/components/libc/posix/io/stdio/libc.c
index aa33b25d11..3c4e9d6e0b 100644
--- a/components/libc/posix/io/stdio/libc.c
+++ b/components/libc/posix/io/stdio/libc.c
@@ -18,6 +18,8 @@
#include <sys/errno.h>
#include "libc.h"
+#define STDIO_DEVICE_NAME_MAX 32
+
int libc_system_init(void)
{
#ifdef RT_USING_POSIX_STDIO
@@ -34,7 +36,7 @@ int libc_system_init(void)
INIT_COMPONENT_EXPORT(libc_system_init);
#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIBC)
-#define STDIO_DEVICE_NAME_MAX 32
+
static FILE* std_console = NULL;
int libc_stdio_set_console(const char* device_name, int mode)
{
@@ -42,7 +44,7 @@ int libc_stdio_set_console(const char* device_name, int mode)
char name[STDIO_DEVICE_NAME_MAX];
char *file_mode;
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
+ rt_snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
if (mode == O_RDWR)
@@ -107,15 +109,71 @@ int libc_stdio_get_console(void)
return -1;
}
+#elif defined(RT_USING_POSIX_STDIO) && defined(RT_USING_MUSLLIBC)
+
+static FILE* std_console = NULL;
+int sys_dup2(int oldfd, int new);
+
+int libc_stdio_set_console(const char* device_name, int mode)
+{
+ FILE *fp;
+ char name[STDIO_DEVICE_NAME_MAX];
+ char *file_mode;
+
+ rt_snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
+ name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
+
+ if (mode == O_RDWR) file_mode = "r+";
+ else if (mode == O_WRONLY) file_mode = "wb";
+ else file_mode = "rb";
+
+ fp = fopen(name, file_mode);
+ if (fp)
+ {
+ setvbuf(fp, NULL, _IONBF, 0);
+
+ if (std_console)
+ {
+ fclose(std_console);
+ std_console = NULL;
+ }
+ std_console = fp;
+ }
+
+ if (std_console)
+ {
+ int fd = fileno(std_console);
+
+ // /* set fd (0, 1, 2) */
+ // sys_dup2(fd, 0);
+ // sys_dup2(fd, 1);
+ // sys_dup2(fd, 2);
+ return fd;
+ }
+
+ return -1;
+}
+
+int libc_stdio_get_console(void)
+{
+ int ret = -1;
+ if (std_console)
+ {
+ ret = fileno(std_console);
+ }
+
+ return ret;
+}
+
#elif defined(RT_USING_POSIX_STDIO)
-#define STDIO_DEVICE_NAME_MAX 32
+
static int std_fd = -1;
int libc_stdio_set_console(const char* device_name, int mode)
{
int fd;
char name[STDIO_DEVICE_NAME_MAX];
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
+ rt_snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
fd = open(name, mode, 0);