summaryrefslogtreecommitdiff
path: root/components/libc/compilers
diff options
context:
space:
mode:
authorMan, Jianting (Meco) <[email protected]>2022-01-10 14:25:46 -0500
committerGitHub <[email protected]>2022-01-10 14:25:46 -0500
commitc6852aa306d07932bc1a62118029ac332acc3fc9 (patch)
tree035cae3629b0a8a63686ffd5212162a334bfeeff /components/libc/compilers
parent1f2e93f1a39590af9a71ecc31b12045696ca6055 (diff)
parent982ad7bcbcbdc31305883803fadf63bad72dbc73 (diff)
Merge branch 'master' into removeinit
Diffstat (limited to 'components/libc/compilers')
-rw-r--r--components/libc/compilers/armlibc/README.md6
-rw-r--r--components/libc/compilers/armlibc/SConscript2
-rw-r--r--components/libc/compilers/armlibc/libc_syms.c1
-rw-r--r--components/libc/compilers/armlibc/syscall_mem.c (renamed from components/libc/compilers/armlibc/mem_std.c)2
-rw-r--r--components/libc/compilers/armlibc/syscalls.c44
-rw-r--r--components/libc/compilers/common/SConscript7
-rw-r--r--components/libc/compilers/common/compiler_private.h17
-rw-r--r--components/libc/compilers/common/dirent.h1
-rw-r--r--components/libc/compilers/common/nogcc/SConscript5
-rw-r--r--components/libc/compilers/common/nogcc/fcntl.h1
-rw-r--r--components/libc/compilers/common/nogcc/sys/errno.h9
-rw-r--r--components/libc/compilers/common/nogcc/sys/select.h6
-rw-r--r--components/libc/compilers/common/nogcc/sys/types.h1
-rw-r--r--components/libc/compilers/common/nogcc/sys/unistd.h1
-rw-r--r--components/libc/compilers/common/nogcc/unistd.h1
-rw-r--r--components/libc/compilers/common/sys/ioctl.h1
-rw-r--r--components/libc/compilers/common/sys/statfs.h1
-rw-r--r--components/libc/compilers/common/sys/time.h27
-rw-r--r--components/libc/compilers/common/sys/vfs.h1
-rw-r--r--components/libc/compilers/common/time.c67
-rw-r--r--components/libc/compilers/dlib/README.md6
-rw-r--r--components/libc/compilers/dlib/SConscript2
-rw-r--r--components/libc/compilers/dlib/syscall_close.c6
-rw-r--r--components/libc/compilers/dlib/syscall_lseek.c6
-rw-r--r--components/libc/compilers/dlib/syscall_mem.c3
-rw-r--r--components/libc/compilers/dlib/syscall_open.c84
-rw-r--r--components/libc/compilers/dlib/syscall_read.c16
-rw-r--r--components/libc/compilers/dlib/syscall_remove.c6
-rw-r--r--components/libc/compilers/dlib/syscall_write.c8
-rw-r--r--components/libc/compilers/dlib/syscalls.c1
-rw-r--r--components/libc/compilers/gcc/newlib/README.md6
-rw-r--r--components/libc/compilers/gcc/newlib/SConscript21
-rw-r--r--components/libc/compilers/gcc/newlib/fcntl.h1
-rw-r--r--components/libc/compilers/gcc/newlib/legacy/SConscript (renamed from components/libc/compilers/gcc/partial/SConscript)0
-rw-r--r--components/libc/compilers/gcc/newlib/legacy/_select/SConscript20
-rw-r--r--components/libc/compilers/gcc/newlib/legacy/_select/readme.md2
-rw-r--r--components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h (renamed from components/libc/compilers/gcc/partial/mips/sys/select.h)12
-rw-r--r--components/libc/compilers/gcc/newlib/libc_syms.c1
-rw-r--r--components/libc/compilers/gcc/newlib/machine/time.h10
-rw-r--r--components/libc/compilers/gcc/newlib/syscalls.c34
-rw-r--r--components/libc/compilers/gcc/partial/mips/SConscript20
-rw-r--r--components/libc/compilers/gcc/partial/mips/readme.md4
-rw-r--r--components/libc/compilers/gcc/partial/readme.md2
43 files changed, 268 insertions, 204 deletions
diff --git a/components/libc/compilers/armlibc/README.md b/components/libc/compilers/armlibc/README.md
index 4d2a73b6be..fc0d750234 100644
--- a/components/libc/compilers/armlibc/README.md
+++ b/components/libc/compilers/armlibc/README.md
@@ -1,9 +1,3 @@
# ARMLIB (Keil-MDK) porting for RT-Thread
-Please define RT_USING_LIBC and compile RT-Thread with Keil-MDK compiler.
-
-
-
-## More Information
-
https://www.keil.com/support/man/docs/armlib/ \ No newline at end of file
diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript
index bf1a299304..bd3ac8dffc 100644
--- a/components/libc/compilers/armlibc/SConscript
+++ b/components/libc/compilers/armlibc/SConscript
@@ -7,6 +7,6 @@ group = []
CPPDEFINES = ['RT_USING_ARM_LIBC']
if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang':
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/armlibc/libc_syms.c b/components/libc/compilers/armlibc/libc_syms.c
index 829d57b559..2b370a25a6 100644
--- a/components/libc/compilers/armlibc/libc_syms.c
+++ b/components/libc/compilers/armlibc/libc_syms.c
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/syscall_mem.c
index f8a81c7873..b5403dfaf3 100644
--- a/components/libc/compilers/armlibc/mem_std.c
+++ b/components/libc/compilers/armlibc/syscall_mem.c
@@ -13,7 +13,7 @@
#include <stddef.h>
#ifndef RT_USING_HEAP
-#define DBG_TAG "armlibc.mem"
+#define DBG_TAG "armlibc.syscall.mem"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c
index 0e965d62af..82c0f38b4f 100644
--- a/components/libc/compilers/armlibc/syscalls.c
+++ b/components/libc/compilers/armlibc/syscalls.c
@@ -21,19 +21,20 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
-#ifdef RT_USING_POSIX_DEVIO
+#include <compiler_private.h>
+#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
-#endif /* RT_USING_POSIX_DEVIO */
+#endif /* RT_USING_POSIX_STDIO */
#define DBG_TAG "armlibc.syscalls"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
-#ifdef __CLANG_ARM
+#ifdef __clang__
__asm(".global __use_no_semihosting\n\t");
#else
#pragma import(__use_no_semihosting_swi)
-#endif /* __CLANG_ARM */
+#endif
/* Standard IO device handles. */
#define STDIN 0
@@ -69,6 +70,7 @@ FILEHANDLE _sys_open(const char *name, int openmode)
return (STDERR);
#ifndef DFS_USING_POSIX
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#else
/* Correct openmode from fopen to open */
@@ -113,6 +115,7 @@ int _sys_close(FILEHANDLE fh)
return close(fh);
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0;
#endif /* DFS_USING_POSIX */
}
@@ -149,17 +152,18 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
if (fh == STDIN)
{
-#ifdef RT_USING_POSIX_DEVIO
+#ifdef RT_USING_POSIX_STDIO
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard output before initializing libc");
+ LOG_W("Do not invoke standard output before initializing Compiler");
return 0; /* error, but keep going */
}
size = read(STDIN_FILENO, buf, len);
return len - size; /* success */
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
return 0; /* error */
-#endif /* RT_USING_POSIX_DEVIO */
+#endif /* RT_USING_POSIX_STDIO */
}
else if (fh == STDOUT || fh == STDERR)
{
@@ -178,6 +182,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
}
}
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
@@ -199,7 +204,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
if (fh == STDOUT || fh == STDERR)
{
-#ifdef RT_USING_CONSOLE
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_device_t console;
console = rt_console_get_device();
if (console)
@@ -209,7 +214,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
return 0; /* success */
#else
return 0; /* error */
-#endif /* RT_USING_CONSOLE */
+#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
}
else if (fh == STDIN)
{
@@ -228,6 +233,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
return 0; /* error */
}
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
@@ -246,6 +252,7 @@ int _sys_seek(FILEHANDLE fh, long pos)
/* position is relative to the start of file fh */
return lseek(fh, pos, 0);
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
@@ -269,10 +276,7 @@ char *_sys_command_string(char *cmd, int len)
void _ttywrch(int ch)
{
#ifdef RT_USING_CONSOLE
- char c;
-
- c = (char)ch;
- rt_kprintf(&c);
+ rt_kprintf("%c", (char)ch);
#endif /* RT_USING_CONSOLE */
}
@@ -301,6 +305,7 @@ long _sys_flen(FILEHANDLE fh)
fstat(fh, &stat);
return stat.st_size;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0;
#endif /* DFS_USING_POSIX */
}
@@ -318,6 +323,7 @@ int remove(const char *filename)
#ifdef DFS_USING_POSIX
return unlink(filename);
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
@@ -328,10 +334,7 @@ int remove(const char *filename)
int fputc(int c, FILE *f)
{
#ifdef RT_USING_CONSOLE
- char ch[2] = {0};
-
- ch[0] = c;
- rt_kprintf(&ch[0]);
+ rt_kprintf("%c", (char)c);
return 1;
#else
return 0; /* error */
@@ -340,18 +343,19 @@ int fputc(int c, FILE *f)
int fgetc(FILE *f)
{
-#ifdef RT_USING_POSIX_DEVIO
+#ifdef RT_USING_POSIX_STDIO
char ch;
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard output before initializing libc");
+ LOG_W("Do not invoke standard output before initializing Compiler");
return 0;
}
if(read(STDIN_FILENO, &ch, 1) == 1)
return ch;
-#endif /* RT_USING_POSIX_DEVIO */
+#endif /* RT_USING_POSIX_STDIO */
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
return 0; /* error */
}
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index 504bf84e56..8db8f2c94a 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -10,12 +10,9 @@ CPPDEFINES = []
if rtconfig.CROSS_TOOL == 'keil':
CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
-if GetDepend('RT_USING_LIBC'):
- src += Glob('*.c')
-elif GetDepend('RT_LIBC_USING_TIME'):
- src += ['time.c']
+src += Glob('*.c')
-group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
list = os.listdir(cwd)
for item in list:
diff --git a/components/libc/compilers/common/compiler_private.h b/components/libc/compilers/common/compiler_private.h
new file mode 100644
index 0000000000..7f6b42e837
--- /dev/null
+++ b/components/libc/compilers/common/compiler_private.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-12-26 Meco Man First Version
+ */
+
+#ifndef __COMPILER_PRIVATE_H__
+#define __COMPILER_PRIVATE_H__
+
+#define _WARNING_WITHOUT_FS "Please enable RT_USING_POSIX_FS"
+#define _WARNING_WITHOUT_STDIO "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_STDIO"
+
+#endif /* __COMPILER_PRIVATE_H__ */
diff --git a/components/libc/compilers/common/dirent.h b/components/libc/compilers/common/dirent.h
index a6353fd6f8..a9c7ef856d 100644
--- a/components/libc/compilers/common/dirent.h
+++ b/components/libc/compilers/common/dirent.h
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
*/
+
#ifndef __DIRENT_H__
#define __DIRENT_H__
diff --git a/components/libc/compilers/common/nogcc/SConscript b/components/libc/compilers/common/nogcc/SConscript
index c766c8f82d..dbc26ac177 100644
--- a/components/libc/compilers/common/nogcc/SConscript
+++ b/components/libc/compilers/common/nogcc/SConscript
@@ -7,9 +7,8 @@ cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
-if GetDepend('RT_USING_LIBC'):
- src += Glob('*.c')
+src += Glob('*.c')
if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
- group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
+ group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
diff --git a/components/libc/compilers/common/nogcc/fcntl.h b/components/libc/compilers/common/nogcc/fcntl.h
index 51ee1024a8..83c3ec0b6b 100644
--- a/components/libc/compilers/common/nogcc/fcntl.h
+++ b/components/libc/compilers/common/nogcc/fcntl.h
@@ -7,6 +7,7 @@
* Date Author Notes
* 2021-09-02 Meco Man First version
*/
+
#ifndef __FCNTL_H__
#define __FCNTL_H__
diff --git a/components/libc/compilers/common/nogcc/sys/errno.h b/components/libc/compilers/common/nogcc/sys/errno.h
index 0452fe93a1..d53ce4b386 100644
--- a/components/libc/compilers/common/nogcc/sys/errno.h
+++ b/components/libc/compilers/common/nogcc/sys/errno.h
@@ -7,6 +7,7 @@
* Date Author Notes
* 2021-05-22 Meco Man The first version.
*/
+
#ifndef __SYS_ERRNO_H__
#define __SYS_ERRNO_H__
@@ -575,6 +576,10 @@ defined in armcc/errno.h
#ifndef EHWPOISON
#define EHWPOISON (ERROR_BASE_NO + 133)
#endif
-#endif
-#endif
+#elif defined(_WIN32)
+#include <errno.h>
+
+#endif /* defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) */
+
+#endif /* __SYS_ERRNO_H__ */
diff --git a/components/libc/compilers/common/nogcc/sys/select.h b/components/libc/compilers/common/nogcc/sys/select.h
index 02fb77dd89..44f9b4ed91 100644
--- a/components/libc/compilers/common/nogcc/sys/select.h
+++ b/components/libc/compilers/common/nogcc/sys/select.h
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2021-07-21 Meco Man The first version
+ * 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version
*/
#ifndef __SYS_SELECT_H__
@@ -33,13 +34,12 @@
typedef long fd_mask;
#ifndef _WIN32
-#ifndef _SYS_TYPES_FD_SET /* MIPS */
-
+#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
#define NBBY 8 /* number of bits in a byte */
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
-#endif
+#endif /* howmany */
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
diff --git a/components/libc/compilers/common/nogcc/sys/types.h b/components/libc/compilers/common/nogcc/sys/types.h
index 5672f54a4d..32b2493c95 100644
--- a/components/libc/compilers/common/nogcc/sys/types.h
+++ b/components/libc/compilers/common/nogcc/sys/types.h
@@ -8,6 +8,7 @@
* 2020-09-05 Meco Man fix bugs
* 2020-12-16 Meco Man add useconds_t
*/
+
#ifndef __SYS_TYPES_H__
#define __SYS_TYPES_H__
diff --git a/components/libc/compilers/common/nogcc/sys/unistd.h b/components/libc/compilers/common/nogcc/sys/unistd.h
index 6195c4c2aa..650c87dc18 100644
--- a/components/libc/compilers/common/nogcc/sys/unistd.h
+++ b/components/libc/compilers/common/nogcc/sys/unistd.h
@@ -8,6 +8,7 @@
* 2020-12-16 Meco Man add usleep
* 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h
*/
+
#ifndef __SYS_UNISTD_H__
#define __SYS_UNISTD_H__
diff --git a/components/libc/compilers/common/nogcc/unistd.h b/components/libc/compilers/common/nogcc/unistd.h
index 9b96d45adb..4dd71c842e 100644
--- a/components/libc/compilers/common/nogcc/unistd.h
+++ b/components/libc/compilers/common/nogcc/unistd.h
@@ -6,4 +6,5 @@
* Change Logs:
* Date Author Notes
*/
+
#include "sys/unistd.h"
diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h
index a1642199b1..d93c79115a 100644
--- a/components/libc/compilers/common/sys/ioctl.h
+++ b/components/libc/compilers/common/sys/ioctl.h
@@ -7,6 +7,7 @@
* Date Author Notes
* 2020-09-01 Meco Man First Version
*/
+
#ifndef __SYS_IOCTL_H__
#define __SYS_IOCTL_H__
diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h
index 0c6dc44df3..a86a789475 100644
--- a/components/libc/compilers/common/sys/statfs.h
+++ b/components/libc/compilers/common/sys/statfs.h
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
*/
+
#ifndef __SYS_STATFS_H__
#define __SYS_STATFS_H__
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h
index a285139649..758333796d 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -8,6 +8,7 @@
* 2020-09-07 Meco Man combine gcc armcc iccarm
* 2021-02-12 Meco Man move all definitions located in <clock_time.h> to this file
*/
+
#ifndef __SYS_TIME_H__
#define __SYS_TIME_H__
@@ -15,6 +16,9 @@
#include <sys/types.h>
#include <stdint.h>
#include <time.h>
+#ifdef _WIN32
+#include <winsock.h> /* for struct timeval */
+#endif
#ifdef __cplusplus
extern "C" {
@@ -39,20 +43,14 @@ struct timezone
int tz_dsttime; /* type of dst correction */
};
-/*
- * Structure returned by gettimeofday(2) system call,
- * and used in other calls.
- */
-#ifndef _TIMEVAL_DEFINED
+#if !defined(_TIMEVAL_DEFINED) && !defined(_WIN32)
#define _TIMEVAL_DEFINED
-#if !defined(_WIN32)
struct timeval
{
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* and microseconds */
};
#endif
-#endif /* _TIMEVAL_DEFINED */
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \
!(defined(__ICCARM__) && (__VER__ >= 8010001)) && \
@@ -70,8 +68,22 @@ int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv, const struct timezone *tz);
#if defined(__ARMCC_VERSION) || defined (__ICCARM__)
struct tm *gmtime_r(const time_t *timep, struct tm *r);
+#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);
+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
+#ifdef RT_USING_POSIX_DELAY
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
+#endif /* RT_USING_POSIX_DELAY */
+
#ifdef RT_USING_POSIX_CLOCK
/* POSIX clock and timer */
#define MILLISECOND_PER_SECOND 1000UL
@@ -103,7 +115,6 @@ int clock_getres (clockid_t clockid, struct timespec *res);
int clock_gettime (clockid_t clockid, struct timespec *tp);
int clock_settime (clockid_t clockid, const struct timespec *tp);
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp);
-int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
int rt_timespec_to_tick(const struct timespec *time);
#endif /* RT_USING_POSIX_CLOCK */
diff --git a/components/libc/compilers/common/sys/vfs.h b/components/libc/compilers/common/sys/vfs.h
index 00739ab1c6..a9330df002 100644
--- a/components/libc/compilers/common/sys/vfs.h
+++ b/components/libc/compilers/common/sys/vfs.h
@@ -7,6 +7,7 @@
* Date Author Notes
* 2021-09-11 Meco Man First version
*/
+
#ifndef __SYS_VFS_H__
#define __SYS_VFS_H__
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 4d204a0c00..46bb0c1355 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -25,7 +25,7 @@
#include <sys/errno.h>
#include <rtthread.h>
#include <rthw.h>
-#ifdef RT_USING_DEVICE
+#ifdef RT_USING_RTC
#include <rtdevice.h>
#endif
@@ -33,6 +33,8 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
+#define _WARNING_NO_RTC "Cannot find a RTC device!"
+
/* seconds per day */
#define SPD 24*60*60
@@ -54,8 +56,8 @@ static const short __spm[13] =
(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31),
};
-ALIGN(4) static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
-ALIGN(4) static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
+ALIGN(4) static const char *days = "Sun Mon Tue Wed Thu Fri Sat ";
+ALIGN(4) static const char *months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
static int __isleap(int year)
{
@@ -108,7 +110,7 @@ static rt_err_t get_timeval(struct timeval *tv)
else
{
/* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
- rt_kprintf("Cannot find a RTC device to provide time!\r\n");
+ rt_kprintf(_WARNING_NO_RTC);
return -RT_ENOSYS;
}
@@ -116,7 +118,7 @@ static rt_err_t get_timeval(struct timeval *tv)
#else
/* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
- rt_kprintf("Cannot find a RTC device to provide time!\r\n");
+ rt_kprintf(_WARNING_NO_RTC);
return -RT_ENOSYS;
#endif /* RT_USING_RTC */
}
@@ -153,14 +155,14 @@ static int set_timeval(struct timeval *tv)
}
else
{
- LOG_W("Cannot find a RTC device to provide time!");
+ LOG_W(_WARNING_NO_RTC);
return -RT_ENOSYS;
}
return rst;
#else
- LOG_W("Cannot find a RTC device to provide time!");
+ LOG_W(_WARNING_NO_RTC);
return -RT_ENOSYS;
#endif /* RT_USING_RTC */
}
@@ -215,7 +217,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r)
{
time_t local_tz;
- local_tz = *t + tz_get() * 3600;
+ local_tz = *t + (time_t)tz_get() * 3600;
return gmtime_r(&local_tz, r);
}
RTM_EXPORT(localtime_r);
@@ -232,7 +234,7 @@ time_t mktime(struct tm * const t)
time_t timestamp;
timestamp = timegm(t);
- timestamp = timestamp - 3600 * tz_get();
+ timestamp = timestamp - 3600 * (time_t)tz_get();
return timestamp;
}
RTM_EXPORT(mktime);
@@ -365,7 +367,7 @@ time_t timegm(struct tm * const t)
{
register time_t day;
register time_t i;
- register time_t years = t->tm_year - 70;
+ register time_t years = (time_t)t->tm_year - 70;
if (t->tm_sec > 60)
{
@@ -486,8 +488,18 @@ RTM_EXPORT(settimeofday);
RTM_EXPORT(difftime);
RTM_EXPORT(strftime);
-#ifdef RT_USING_POSIX_CLOCK
+#ifdef RT_USING_POSIX_DELAY
#include <delay.h>
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
+{
+ sleep(rqtp->tv_sec);
+ ndelay(rqtp->tv_nsec);
+ return 0;
+}
+RTM_EXPORT(nanosleep);
+#endif /* RT_USING_POSIX_DELAY */
+
+#ifdef RT_USING_POSIX_CLOCK
#ifdef RT_USING_RTC
static volatile struct timeval _timevalue;
static int _rt_clock_time_system_init()
@@ -525,7 +537,7 @@ INIT_COMPONENT_EXPORT(_rt_clock_time_system_init);
int clock_getres(clockid_t clockid, struct timespec *res)
{
#ifndef RT_USING_RTC
- LOG_W("Cannot find a RTC device to save time!");
+ LOG_W(_WARNING_NO_RTC);
return -1;
#else
int ret = 0;
@@ -564,7 +576,7 @@ RTM_EXPORT(clock_getres);
int clock_gettime(clockid_t clockid, struct timespec *tp)
{
#ifndef RT_USING_RTC
- LOG_W("Cannot find a RTC device to save time!");
+ LOG_W(_WARNING_NO_RTC);
return -1;
#else
int ret = 0;
@@ -628,7 +640,7 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s
int clock_settime(clockid_t clockid, const struct timespec *tp)
{
#ifndef RT_USING_RTC
- LOG_W("Cannot find a RTC device to save time!");
+ LOG_W(_WARNING_NO_RTC);
return -1;
#else
register rt_base_t level;
@@ -668,33 +680,6 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
}
RTM_EXPORT(clock_settime);
-int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
-{
- uint32_t time_ms = rqtp->tv_sec * 1000;
- uint32_t time_us = rqtp->tv_nsec / 1000;
-
- time_ms += time_us / 1000 ;
- time_us = time_us % 1000;
-
- if (rt_thread_self() != RT_NULL)
- {
- rt_thread_mdelay(time_ms);
- }
- else /* scheduler has not run yet */
- {
- while(time_ms > 0)
- {
- udelay(1000u);
- time_ms -= 1;
- }
- }
-
- udelay(time_us);
-
- return 0;
-}
-RTM_EXPORT(nanosleep);
-
int rt_timespec_to_tick(const struct timespec *time)
{
int tick;
diff --git a/components/libc/compilers/dlib/README.md b/components/libc/compilers/dlib/README.md
index acd08f9074..e4d70e8135 100644
--- a/components/libc/compilers/dlib/README.md
+++ b/components/libc/compilers/dlib/README.md
@@ -1,9 +1,3 @@
# DLIB (IAR) porting for RT-Thread
-Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
-
-
-
-## More Information
-
http://www.iarsys.co.jp/download/LMS2/arm/7502/ewarm7502doc/arm/doc/EWARM_DevelopmentGuide.ENU.pdf P.130 \ No newline at end of file
diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript
index f685873e16..e11ea65b97 100644
--- a/components/libc/compilers/dlib/SConscript
+++ b/components/libc/compilers/dlib/SConscript
@@ -15,6 +15,6 @@ if rtconfig.PLATFORM == 'iar':
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c
index 30ee6f2388..736023023d 100644
--- a/components/libc/compilers/dlib/syscall_close.c
+++ b/components/libc/compilers/dlib/syscall_close.c
@@ -7,9 +7,14 @@
* Date Author Notes
* 2015-01-28 Bernard first version
*/
+
#include <rtthread.h>
#include <LowLevelIOInterface.h>
#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.close"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
/*
* The "__close" function should close the file corresponding to
@@ -27,6 +32,7 @@ int __close(int handle)
#ifdef DFS_USING_POSIX
return close(handle);
#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c
index 622f613c51..b2c47e71c9 100644
--- a/components/libc/compilers/dlib/syscall_lseek.c
+++ b/components/libc/compilers/dlib/syscall_lseek.c
@@ -7,9 +7,14 @@
* Date Author Notes
* 2015-01-28 Bernard first version
*/
+
#include <rtthread.h>
#include <LowLevelIOInterface.h>
#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.lseek"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
/*
* The "__lseek" function makes the next file operation (__read or
@@ -36,6 +41,7 @@ long __lseek(int handle, long offset, int whence)
#ifdef DFS_USING_POSIX
return lseek(handle, offset, whence);
#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c
index 74b960f0b9..2de0974e4e 100644
--- a/components/libc/compilers/dlib/syscall_mem.c
+++ b/components/libc/compilers/dlib/syscall_mem.c
@@ -8,11 +8,12 @@
* 2015-01-28 Bernard first version
* 2021-11-13 Meco Man implement no-heap warning
*/
+
#include <rtthread.h>
#include <stddef.h>
#ifndef RT_USING_HEAP
-#define DBG_TAG "dlib.syscall_mem"
+#define DBG_TAG "dlib.syscall.mem"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c
index 66cddc83c1..4d557db4b0 100644
--- a/components/libc/compilers/dlib/syscall_open.c
+++ b/components/libc/compilers/dlib/syscall_open.c
@@ -11,6 +11,10 @@
#include <rtthread.h>
#include <LowLevelIOInterface.h>
#include <fcntl.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.open"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
/*
* The "__open" function opens the file named "filename" as specified
@@ -22,56 +26,58 @@
int __open(const char *filename, int mode)
{
#ifdef DFS_USING_POSIX
- int handle;
- int open_mode = O_RDONLY;
+ int handle;
+ int open_mode = O_RDONLY;
- if (mode & _LLIO_CREAT)
- {
- open_mode |= O_CREAT;
-
- /* Check what we should do with it if it exists. */
- if (mode & _LLIO_APPEND)
+ if (mode & _LLIO_CREAT)
{
- /* Append to the existing file. */
- open_mode |= O_APPEND;
+ open_mode |= O_CREAT;
+
+ /* Check what we should do with it if it exists. */
+ if (mode & _LLIO_APPEND)
+ {
+ /* Append to the existing file. */
+ open_mode |= O_APPEND;
+ }
+
+ if (mode & _LLIO_TRUNC)
+ {
+ /* Truncate the existsing file. */
+ open_mode |= O_TRUNC;
+ }
}
- if (mode & _LLIO_TRUNC)
+ if (mode & _LLIO_TEXT)
{
- /* Truncate the existsing file. */
- open_mode |= O_TRUNC;
+ /* we didn't support text mode */
}
- }
- if (mode & _LLIO_TEXT)
- {
- /* we didn't support text mode */
- }
-
- switch (mode & _LLIO_RDWRMASK)
- {
- case _LLIO_RDONLY:
- break;
-
- case _LLIO_WRONLY:
- open_mode |= O_WRONLY;
- break;
+ switch (mode & _LLIO_RDWRMASK)
+ {
+ case _LLIO_RDONLY:
+ break;
- case _LLIO_RDWR:
- /* The file should be opened for both reads and writes. */
- open_mode |= O_RDWR;
- break;
+ case _LLIO_WRONLY:
+ open_mode |= O_WRONLY;
+ break;
- default:
- return _LLIO_ERROR;
- }
+ case _LLIO_RDWR:
+ /* The file should be opened for both reads and writes. */
+ open_mode |= O_RDWR;
+ break;
- handle = open(filename, open_mode, 0);
- if (handle < 0)
- return _LLIO_ERROR;
+ default:
+ return _LLIO_ERROR;
+ }
- return handle;
+ handle = open(filename, open_mode, 0);
+ if (handle < 0)
+ {
+ return _LLIO_ERROR;
+ }
+ return handle;
#else
- return _LLIO_ERROR;
+ LOG_W(_WARNING_WITHOUT_FS);
+ return _LLIO_ERROR;
#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index 62bc05d243..a276a3e401 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -11,11 +11,11 @@
#include <rtthread.h>
#include <LowLevelIOInterface.h>
#include <unistd.h>
-#ifdef RT_USING_POSIX_DEVIO
+#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
-#endif /* RT_USING_POSIX_DEVIO */
-
-#define DBG_TAG "dlib.syscall_read"
+#endif /* RT_USING_POSIX_STDIO */
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.read"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
@@ -39,16 +39,17 @@ size_t __read(int handle, unsigned char *buf, size_t len)
if (handle == _LLIO_STDIN)
{
-#ifdef RT_USING_POSIX_DEVIO
+#ifdef RT_USING_POSIX_STDIO
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard input before initializing libc");
+ LOG_W("Do not invoke standard input before initializing Compiler");
return 0; /* error, but keep going */
}
return read(STDIN_FILENO, buf, len); /* return the length of the data read */
#else
+ LOG_W(_WARNING_WITHOUT_STDIO);
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX_DEVIO */
+#endif /* RT_USING_POSIX_STDIO */
}
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
@@ -58,6 +59,7 @@ size_t __read(int handle, unsigned char *buf, size_t len)
size = read(handle, buf, len);
return size; /* return the length of the data read */
#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c
index 870f91b8c1..04230544da 100644
--- a/components/libc/compilers/dlib/syscall_remove.c
+++ b/components/libc/compilers/dlib/syscall_remove.c
@@ -7,9 +7,14 @@
* Date Author Notes
* 2015-01-28 Bernard first version
*/
+
#include <rtthread.h>
#include <LowLevelIOInterface.h>
#include <unistd.h>
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.remove"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
/*
* The "remove" function should remove the file named "filename". It
@@ -23,6 +28,7 @@ int remove(const char *filename)
#ifdef DFS_USING_POSIX
return unlink(filename);
#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index 2bc5863d8a..4eead9aa38 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -11,7 +11,8 @@
#include <rtthread.h>
#include <LowLevelIOInterface.h>
#include <unistd.h>
-#define DBG_TAG "dlib.syscall_write"
+#include <compiler_private.h>
+#define DBG_TAG "dlib.syscall.write"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
@@ -39,7 +40,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifdef RT_USING_CONSOLE
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_device_t console_device;
console_device = rt_console_get_device();
@@ -51,7 +52,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
return len; /* return the length of the data written */
#else
return _LLIO_ERROR;
-#endif /* RT_USING_CONSOLE */
+#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
}
else if (handle == _LLIO_STDIN)
{
@@ -63,6 +64,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
size = write(handle, buf, len);
return size; /* return the length of the data written */
#else
+ LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c
index 1ee6a3bc12..391cbcac8a 100644
--- a/components/libc/compilers/dlib/syscalls.c
+++ b/components/libc/compilers/dlib/syscalls.c
@@ -7,6 +7,7 @@
* Date Author Notes
* 2021-02-13 Meco Man implement exit() and abort()
*/
+
#include <rtthread.h>
/* for exit() and abort() */
diff --git a/components/libc/compilers/gcc/newlib/README.md b/components/libc/compilers/gcc/newlib/README.md
index 62172e6a55..4614375b45 100644
--- a/components/libc/compilers/gcc/newlib/README.md
+++ b/components/libc/compilers/gcc/newlib/README.md
@@ -1,10 +1,4 @@
# NEWLIB (GCC) porting for RT-Thread
-Please define RT_USING_LIBC and compile RT-Thread with GCC compiler.
-
-
-
-## More Information
-
https://sourceware.org/newlib/libc.html#Reentrancy
diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript
index 58672a0255..8076a73727 100644
--- a/components/libc/compilers/gcc/newlib/SConscript
+++ b/components/libc/compilers/gcc/newlib/SConscript
@@ -1,4 +1,6 @@
+import os
from building import *
+from gcc import *
Import('rtconfig')
src = []
@@ -8,15 +10,22 @@ LIBS = ['m'] # link libm
CPPPATH = [cwd]
if rtconfig.PLATFORM == 'gcc':
- if GetDepend('RT_USING_LIBC'):
- LIBS += ['c'] # link libc
- src += Glob('*.c')
- else:
- src += ['syscalls.c']
+ LIBS += ['c'] # link libc
+ src += Glob('*.c')
+
+ #report newlib version
+ print('Newlib version:' + GetNewLibVersion(rtconfig))
# identify this is Newlib, and only enable POSIX.1-1990
CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1']
- group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+ 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/compilers/gcc/newlib/fcntl.h b/components/libc/compilers/gcc/newlib/fcntl.h
index 239eaaef0d..847ae3d35b 100644
--- a/components/libc/compilers/gcc/newlib/fcntl.h
+++ b/components/libc/compilers/gcc/newlib/fcntl.h
@@ -7,6 +7,7 @@
* Date Author Notes
* 2021-09-02 Meco Man First version
*/
+
#ifndef __FCNTL_H__
#define __FCNTL_H__
diff --git a/components/libc/compilers/gcc/partial/SConscript b/components/libc/compilers/gcc/newlib/legacy/SConscript
index 4c815c49b8..4c815c49b8 100644
--- a/components/libc/compilers/gcc/partial/SConscript
+++ b/components/libc/compilers/gcc/newlib/legacy/SConscript
diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript b/components/libc/compilers/gcc/newlib/legacy/_select/SConscript
new file mode 100644
index 0000000000..b7bd86a36c
--- /dev/null
+++ b/components/libc/compilers/gcc/newlib/legacy/_select/SConscript
@@ -0,0 +1,20 @@
+from shutil import copy
+from building import *
+from gcc import *
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+# sys/select.h does not exist in newlib 2.1.0 or lower version
+if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == False):
+ try:
+ copy("../../../../common/nogcc/sys/select.h", "./sys/select.h") # copy from 'nogcc/sys/select.h'
+ except:
+ pass
+
+ group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md b/components/libc/compilers/gcc/newlib/legacy/_select/readme.md
new file mode 100644
index 0000000000..4ad9f21923
--- /dev/null
+++ b/components/libc/compilers/gcc/newlib/legacy/_select/readme.md
@@ -0,0 +1,2 @@
+Newlib 2.2.0 or lower version does not provide `sys/select.h`, and `fd_set` is defined in `sys/types.h`. It will be generated by scons automatically, and **DO NOT** change it.
+
diff --git a/components/libc/compilers/gcc/partial/mips/sys/select.h b/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h
index 575ad3a1b5..02fb77dd89 100644
--- a/components/libc/compilers/gcc/partial/mips/sys/select.h
+++ b/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h
@@ -15,6 +15,10 @@
#include <sys/types.h>
#include <sys/time.h>
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
#ifndef FD_SETSIZE
#define FD_SETSIZE 32
#endif
@@ -26,16 +30,17 @@
#define FD_SETSIZE DFS_FD_MAX
#endif /* SAL_USING_POSIX */
-#define NBBY 8 /* number of bits in a byte */
-
typedef long fd_mask;
+#ifndef _WIN32
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+
+#define NBBY 8 /* number of bits in a byte */
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
#endif
-#ifndef _SYS_TYPES_FD_SET /* MIPS */
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;
@@ -48,5 +53,6 @@ typedef struct _types_fd_set {
#endif /* _SYS_TYPES_FD_SET */
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+#endif /* _WIN32 */
#endif /* __SYS_SELECT_H__ */
diff --git a/components/libc/compilers/gcc/newlib/libc_syms.c b/components/libc/compilers/gcc/newlib/libc_syms.c
index aaf6980d6b..e6ca23b393 100644
--- a/components/libc/compilers/gcc/newlib/libc_syms.c
+++ b/components/libc/compilers/gcc/newlib/libc_syms.c
@@ -7,6 +7,7 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
+
#include <rtthread.h>
#include <rtm.h>
diff --git a/components/libc/compilers/gcc/newlib/machine/time.h b/components/libc/compilers/gcc/newlib/machine/time.h
index 9ef838f892..805b061aea 100644
--- a/components/libc/compilers/gcc/newlib/machine/time.h
+++ b/components/libc/compilers/gcc/newlib/machine/time.h
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-02-16 Meco Man The first version
+ */
+
#ifndef _MACHTIME_H_
#define _MACHTIME_H_
diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c
index 8fe8c5be4b..dcf26ccfb7 100644
--- a/components/libc/compilers/gcc/newlib/syscalls.c
+++ b/components/libc/compilers/gcc/newlib/syscalls.c
@@ -20,13 +20,13 @@
#include <unistd.h>
#include <sys/errno.h>
#include <sys/stat.h>
-#ifdef RT_USING_POSIX_DEVIO
+#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
-#endif /* RT_USING_POSIX_DEVIO */
+#endif /* RT_USING_POSIX_STDIO */
#ifdef RT_USING_MODULE
#include <dlmodule.h>
#endif /* RT_USING_MODULE */
-
+#include <compiler_private.h>
#define DBG_TAG "newlib.syscalls"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
@@ -92,8 +92,6 @@ void __libc_init_array(void)
/* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */
}
-#ifdef RT_USING_LIBC
-
/* Reentrant versions of system calls. */
#ifndef _REENT_ONLY
int *__errno ()
@@ -112,6 +110,7 @@ int _close_r(struct _reent *ptr, int fd)
#ifdef DFS_USING_POSIX
return close(fd);
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -185,10 +184,10 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
#ifdef DFS_USING_POSIX
_off_t rc;
-
rc = lseek(fd, pos, whence);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -198,10 +197,10 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode)
{
#ifdef DFS_USING_POSIX
int rc;
-
rc = mkdir(name, mode);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -214,6 +213,7 @@ int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
rc = open(file, flags, mode);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -225,16 +225,17 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
_ssize_t rc;
if (fd == STDIN_FILENO)
{
-#ifdef RT_USING_POSIX_DEVIO
+#ifdef RT_USING_POSIX_STDIO
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard input before initializing libc");
+ LOG_W("Do not invoke standard input before initializing Compiler");
return 0;
}
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
ptr->_errno = ENOTSUP;
return -1;
-#endif /* RT_USING_POSIX_DEVIO */
+#endif /* RT_USING_POSIX_STDIO */
}
else if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
@@ -245,6 +246,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
rc = read(fd, buf, nbytes);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -254,10 +256,10 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new)
{
#ifdef DFS_USING_POSIX
int rc;
-
rc = rename(old, new);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -267,10 +269,10 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
#ifdef DFS_USING_POSIX
int rc;
-
rc = stat(file, pstat);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -281,6 +283,7 @@ int _unlink_r(struct _reent *ptr, const char *file)
#ifdef DFS_USING_POSIX
return unlink(file);
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -294,7 +297,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
-#ifdef RT_USING_CONSOLE
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_device_t console;
console = rt_console_get_device();
@@ -303,7 +306,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
#else
ptr->_errno = ENOTSUP;
return -1;
-#endif /* RT_USING_CONSOLE */
+#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
}
else if (fd == STDIN_FILENO)
{
@@ -315,6 +318,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
rc = write(fd, buf, nbytes);
return rc;
#else
+ LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
ptr->_errno = ENOTSUP;
return -1;
#endif /* DFS_USING_POSIX */
@@ -333,5 +337,3 @@ These functions are implemented and replaced by the 'common/time.c' file
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
*/
-
-#endif /* RT_USING_LIBC */
diff --git a/components/libc/compilers/gcc/partial/mips/SConscript b/components/libc/compilers/gcc/partial/mips/SConscript
deleted file mode 100644
index 7651233d46..0000000000
--- a/components/libc/compilers/gcc/partial/mips/SConscript
+++ /dev/null
@@ -1,20 +0,0 @@
-from shutil import copy
-from building import *
-
-Import('rtconfig')
-
-src = []
-cwd = GetCurrentDir()
-CPPPATH = [cwd]
-group = []
-
-if rtconfig.PLATFORM == 'gcc' and ('mips' in rtconfig.PREFIX): # identify mips gcc tool chain
- try:
- # There is no 'sys/select.h' in tthe mips gcc toolchain; it will be copied from 'nogcc/sys/select.h'
- copy("../../../common/nogcc/sys/select.h", "./sys/select.h")
- except:
- pass
-
- group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/compilers/gcc/partial/mips/readme.md b/components/libc/compilers/gcc/partial/mips/readme.md
deleted file mode 100644
index a3eeb06c5d..0000000000
--- a/components/libc/compilers/gcc/partial/mips/readme.md
+++ /dev/null
@@ -1,4 +0,0 @@
-These files don't exist in the mips gcc toolchain. They will be generated by scons automatically , and **DO NOT** change them:
-
-- sys/select.h
-
diff --git a/components/libc/compilers/gcc/partial/readme.md b/components/libc/compilers/gcc/partial/readme.md
deleted file mode 100644
index 959fc29f35..0000000000
--- a/components/libc/compilers/gcc/partial/readme.md
+++ /dev/null
@@ -1,2 +0,0 @@
-This folder is for some particular targets.
-