[libc][musl] support arm-linux-musleabi toolchain
目前基本功能已经可以在QEMU上跑起来,但是pthread和内核signal选中会报冲突。先合并一版本,后续解决这些问题。
This commit is contained in:
parent
fc83546cf5
commit
bdd663a33f
@ -26,25 +26,16 @@ with open(automac_h_fn, 'w') as f:
|
|||||||
f.write(header + get_mac_address() + end)
|
f.write(header + get_mac_address() + end)
|
||||||
|
|
||||||
# toolchains options
|
# toolchains options
|
||||||
ARCH='arm'
|
ARCH ='arm'
|
||||||
CPU='cortex-a'
|
CPU ='cortex-a'
|
||||||
CROSS_TOOL='gcc'
|
CROSS_TOOL = 'gcc'
|
||||||
|
|
||||||
if os.getenv('RTT_CC'):
|
|
||||||
CROSS_TOOL = os.getenv('RTT_CC')
|
|
||||||
|
|
||||||
# only support GNU GCC compiler.
|
|
||||||
PLATFORM = 'gcc'
|
PLATFORM = 'gcc'
|
||||||
EXEC_PATH = r'/usr/bin'
|
EXEC_PATH = os.getenv('RTT_EXEC_PATH') or r'/usr/bin'
|
||||||
|
|
||||||
if os.getenv('RTT_EXEC_PATH'):
|
|
||||||
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
|
|
||||||
|
|
||||||
BUILD = 'debug'
|
BUILD = 'debug'
|
||||||
|
|
||||||
if PLATFORM == 'gcc':
|
if PLATFORM == 'gcc':
|
||||||
# toolchains
|
# toolchains
|
||||||
PREFIX = 'arm-none-eabi-'
|
PREFIX = os.getenv('RTT_CC_PREFIX') or 'arm-none-eabi-'
|
||||||
CC = PREFIX + 'gcc'
|
CC = PREFIX + 'gcc'
|
||||||
CXX = PREFIX + 'g++'
|
CXX = PREFIX + 'g++'
|
||||||
AS = PREFIX + 'gcc'
|
AS = PREFIX + 'gcc'
|
||||||
@ -55,27 +46,25 @@ if PLATFORM == 'gcc':
|
|||||||
OBJDUMP = PREFIX + 'objdump'
|
OBJDUMP = PREFIX + 'objdump'
|
||||||
OBJCPY = PREFIX + 'objcopy'
|
OBJCPY = PREFIX + 'objcopy'
|
||||||
STRIP = PREFIX + 'strip'
|
STRIP = PREFIX + 'strip'
|
||||||
|
CFPFLAGS = ' -msoft-float'
|
||||||
|
AFPFLAGS = ' -mfloat-abi=softfp -mfpu=neon'
|
||||||
|
DEVICE = ' -march=armv7-a -mtune=cortex-a7 -ftree-vectorize -ffast-math -funwind-tables -fno-strict-aliasing'
|
||||||
|
|
||||||
DEVICE = ' -march=armv7-a -marm -msoft-float'
|
CXXFLAGS= DEVICE + CFPFLAGS + ' -Wall'
|
||||||
CFLAGS = DEVICE + ' -Wall -Werror'
|
CFLAGS = DEVICE + CFPFLAGS + ' -Wall -std=gnu99'
|
||||||
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__ -I.'
|
AFLAGS = DEVICE + ' -c' + AFPFLAGS + ' -x assembler-with-cpp'
|
||||||
LINK_SCRIPT = 'link.lds'
|
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors -T link.lds' + ' -lsupc++ -lgcc -static'
|
||||||
LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors'+\
|
|
||||||
' -T %s' % LINK_SCRIPT
|
|
||||||
|
|
||||||
CPATH = ''
|
CPATH = ''
|
||||||
LPATH = ''
|
LPATH = ''
|
||||||
|
|
||||||
# generate debug info in all cases
|
|
||||||
AFLAGS += ' -gdwarf-2'
|
|
||||||
CFLAGS += ' -g -gdwarf-2'
|
|
||||||
|
|
||||||
if BUILD == 'debug':
|
if BUILD == 'debug':
|
||||||
CFLAGS += ' -O0'
|
CFLAGS += ' -O0 -gdwarf-2'
|
||||||
|
CXXFLAGS += ' -O0 -gdwarf-2'
|
||||||
|
AFLAGS += ' -gdwarf-2'
|
||||||
else:
|
else:
|
||||||
CFLAGS += ' -O2'
|
CFLAGS += ' -Os'
|
||||||
|
CXXFLAGS += ' -Os'
|
||||||
CXXFLAGS = CFLAGS + ' -Woverloaded-virtual -fno-exceptions -fno-rtti'
|
CXXFLAGS += ' -Woverloaded-virtual -fno-exceptions -fno-rtti'
|
||||||
|
|
||||||
M_CFLAGS = CFLAGS + ' -mlong-calls -fPIC '
|
M_CFLAGS = CFLAGS + ' -mlong-calls -fPIC '
|
||||||
M_CXXFLAGS = CXXFLAGS + ' -mlong-calls -fPIC'
|
M_CXXFLAGS = CXXFLAGS + ' -mlong-calls -fPIC'
|
||||||
@ -83,5 +72,6 @@ if PLATFORM == 'gcc':
|
|||||||
' -shared -fPIC -nostartfiles -nostdlib -static-libgcc'
|
' -shared -fPIC -nostartfiles -nostdlib -static-libgcc'
|
||||||
M_POST_ACTION = STRIP + ' -R .hash $TARGET\n' + SIZE + ' $TARGET \n'
|
M_POST_ACTION = STRIP + ' -R .hash $TARGET\n' + SIZE + ' $TARGET \n'
|
||||||
|
|
||||||
|
DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n'
|
||||||
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' +\
|
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' +\
|
||||||
SIZE + ' $TARGET \n'
|
SIZE + ' $TARGET \n'
|
||||||
|
@ -762,7 +762,7 @@ RTM_EXPORT(telldir);
|
|||||||
* @param d the directory stream.
|
* @param d the directory stream.
|
||||||
* @param offset the offset in 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;
|
struct dfs_fd *fd;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#ifndef __SYS_SELECT_H__
|
#ifndef __SYS_SELECT_H__
|
||||||
#define __SYS_SELECT_H__
|
#define __SYS_SELECT_H__
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtconfig.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
@ -14,12 +14,11 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
|
||||||
/* sigev_notify values
|
/* sigev_notify values
|
||||||
NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
|
NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
|
||||||
|
|
||||||
@ -54,7 +53,6 @@ struct siginfo
|
|||||||
{
|
{
|
||||||
uint16_t si_signo;
|
uint16_t si_signo;
|
||||||
uint16_t si_code;
|
uint16_t si_code;
|
||||||
|
|
||||||
union sigval si_value;
|
union sigval si_value;
|
||||||
};
|
};
|
||||||
typedef struct siginfo siginfo_t;
|
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 SIGUSR2 31 /* user defined signal 2 */
|
||||||
#define NSIG 32 /* signal 0 implied */
|
#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>
|
/* Some applications take advantage of the fact that <sys/signal.h>
|
||||||
* and <signal.h> are equivalent in glibc. Allow for that here. */
|
* and <signal.h> are equivalent in glibc. Allow for that here. */
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#endif
|
#endif /* defined(RT_USING_NEWLIBC) */
|
||||||
|
#endif /* __ARMCC_VERSION */
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif /* __SYS_SIGNAL_H__ */
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ typedef __time64_t time_t;
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#undef CLOCKS_PER_SEC
|
#undef CLOCKS_PER_SEC
|
||||||
#define CLOCKS_PER_SEC RT_TICK_PER_SECOND
|
#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);
|
time_t timegm(struct tm * const t);
|
||||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||||
int settimeofday(const struct timeval *tv, const 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 *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* asctime_r(const struct tm *t, char *buf);
|
||||||
char *ctime_r(const time_t * tim_p, char * result);
|
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);
|
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);
|
struct tm* localtime(const time_t* t);
|
||||||
time_t mktime(struct tm* const 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);
|
char* ctime(const time_t* tim_p);
|
||||||
time_t time(time_t* t);
|
time_t time(time_t* t);
|
||||||
#endif
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_DELAY
|
#ifdef RT_USING_POSIX_DELAY
|
||||||
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
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
|
#ifndef CLOCK_REALTIME
|
||||||
#define CLOCK_REALTIME 1
|
#define CLOCK_REALTIME 1
|
||||||
#endif
|
#endif /* CLOCK_REALTIME */
|
||||||
|
|
||||||
#define CLOCK_CPUTIME_ID 2
|
#define CLOCK_CPUTIME_ID 2
|
||||||
|
|
||||||
#ifndef CLOCK_PROCESS_CPUTIME_ID
|
#ifndef CLOCK_PROCESS_CPUTIME_ID
|
||||||
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
|
#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
|
||||||
#endif
|
#endif /* CLOCK_PROCESS_CPUTIME_ID */
|
||||||
|
|
||||||
#ifndef CLOCK_THREAD_CPUTIME_ID
|
#ifndef CLOCK_THREAD_CPUTIME_ID
|
||||||
#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
|
#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
|
||||||
#endif
|
#endif /* CLOCK_THREAD_CPUTIME_ID */
|
||||||
|
|
||||||
#ifndef CLOCK_MONOTONIC
|
#ifndef CLOCK_MONOTONIC
|
||||||
#define CLOCK_MONOTONIC 4
|
#define CLOCK_MONOTONIC 4
|
||||||
#endif
|
#endif /* CLOCK_MONOTONIC */
|
||||||
#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */
|
#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_CLOCK
|
#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_delete(timer_t timerid);
|
||||||
int timer_getoverrun(timer_t timerid);
|
int timer_getoverrun(timer_t timerid);
|
||||||
int timer_gettime(timer_t timerid, struct itimerspec *its);
|
int timer_gettime(timer_t timerid, struct itimerspec *its);
|
||||||
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);
|
||||||
struct itimerspec *ovalue);
|
|
||||||
#endif /* RT_USING_POSIX_TIMER */
|
#endif /* RT_USING_POSIX_TIMER */
|
||||||
|
|
||||||
/* timezone */
|
/* timezone */
|
||||||
@ -153,6 +152,6 @@ int8_t tz_is_dst(void);
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif /* _SYS_TIME_H_ */
|
#endif /* _SYS_TIME_H_ */
|
||||||
|
30
components/libc/compilers/musl/SConscript
Normal file
30
components/libc/compilers/musl/SConscript
Normal file
@ -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')
|
20
components/libc/compilers/musl/syscalls.c
Normal file
20
components/libc/compilers/musl/syscalls.c
Normal file
@ -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();
|
||||||
|
}
|
@ -3,26 +3,25 @@ from building import *
|
|||||||
from gcc import *
|
from gcc import *
|
||||||
Import('rtconfig')
|
Import('rtconfig')
|
||||||
|
|
||||||
src = []
|
|
||||||
cwd = GetCurrentDir()
|
|
||||||
group = []
|
group = []
|
||||||
LIBS = []
|
|
||||||
CPPPATH = [cwd]
|
|
||||||
|
|
||||||
if rtconfig.PLATFORM in ['gcc']:
|
libc_name, libc_version = GetGCCLibcNameVersion(rtconfig)
|
||||||
LIBS += ['c', 'm'] # link libc and libm
|
|
||||||
src += Glob('*.c')
|
|
||||||
|
|
||||||
#report newlib version
|
if libc_name == 'newlib':
|
||||||
print('Newlib version:' + GetNewLibVersion(rtconfig))
|
print('Newlib version: ' + libc_version)
|
||||||
|
|
||||||
# identify this is Newlib, and only enable POSIX.1-1990
|
cwd = GetCurrentDir()
|
||||||
CPPDEFINES = ['RT_USING_NEWLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1']
|
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'])
|
AddDepend(['RT_USING_NEWLIBC', 'RT_USING_LIBC'])
|
||||||
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
|
||||||
|
|
||||||
list = os.listdir(cwd)
|
group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
||||||
for d in list:
|
|
||||||
|
list = os.listdir(cwd)
|
||||||
|
for d in list:
|
||||||
path = os.path.join(cwd, d)
|
path = os.path.join(cwd, d)
|
||||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||||
group = group + SConscript(os.path.join(d, 'SConscript'))
|
group = group + SConscript(os.path.join(d, 'SConscript'))
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
|
|
||||||
|
#define STDIO_DEVICE_NAME_MAX 32
|
||||||
|
|
||||||
int libc_system_init(void)
|
int libc_system_init(void)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#ifdef RT_USING_POSIX_STDIO
|
||||||
@ -34,7 +36,7 @@ int libc_system_init(void)
|
|||||||
INIT_COMPONENT_EXPORT(libc_system_init);
|
INIT_COMPONENT_EXPORT(libc_system_init);
|
||||||
|
|
||||||
#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIBC)
|
#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIBC)
|
||||||
#define STDIO_DEVICE_NAME_MAX 32
|
|
||||||
static FILE* std_console = NULL;
|
static FILE* std_console = NULL;
|
||||||
int libc_stdio_set_console(const char* device_name, int mode)
|
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 name[STDIO_DEVICE_NAME_MAX];
|
||||||
char *file_mode;
|
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';
|
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||||
|
|
||||||
if (mode == O_RDWR)
|
if (mode == O_RDWR)
|
||||||
@ -107,15 +109,71 @@ int libc_stdio_get_console(void)
|
|||||||
return -1;
|
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)
|
#elif defined(RT_USING_POSIX_STDIO)
|
||||||
#define STDIO_DEVICE_NAME_MAX 32
|
|
||||||
static int std_fd = -1;
|
static int std_fd = -1;
|
||||||
int libc_stdio_set_console(const char* device_name, int mode)
|
int libc_stdio_set_console(const char* device_name, int mode)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char name[STDIO_DEVICE_NAME_MAX];
|
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';
|
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||||
|
|
||||||
fd = open(name, mode, 0);
|
fd = open(name, mode, 0);
|
||||||
|
@ -550,8 +550,9 @@ typedef struct rt_timer *rt_timer_t;
|
|||||||
#ifdef RT_USING_SIGNALS
|
#ifdef RT_USING_SIGNALS
|
||||||
#include <sys/signal.h>
|
#include <sys/signal.h>
|
||||||
typedef unsigned long rt_sigset_t;
|
typedef unsigned long rt_sigset_t;
|
||||||
typedef void (*rt_sighandler_t)(int signo);
|
|
||||||
typedef siginfo_t rt_siginfo_t;
|
typedef siginfo_t rt_siginfo_t;
|
||||||
|
typedef void (*rt_sighandler_t)(int signo);
|
||||||
|
|
||||||
|
|
||||||
#define RT_SIG_MAX 32
|
#define RT_SIG_MAX 32
|
||||||
#endif /* RT_USING_SIGNALS */
|
#endif /* RT_USING_SIGNALS */
|
||||||
|
97
tools/gcc.py
97
tools/gcc.py
@ -69,7 +69,6 @@ def CheckHeader(rtconfig, filename):
|
|||||||
def GetNewLibVersion(rtconfig):
|
def GetNewLibVersion(rtconfig):
|
||||||
version = 'unknown'
|
version = 'unknown'
|
||||||
root = GetGCCRoot(rtconfig)
|
root = GetGCCRoot(rtconfig)
|
||||||
|
|
||||||
if CheckHeader(rtconfig, '_newlib_version.h'): # get version from _newlib_version.h file
|
if CheckHeader(rtconfig, '_newlib_version.h'): # get version from _newlib_version.h file
|
||||||
f = open(os.path.join(root, 'include', '_newlib_version.h'), 'r')
|
f = open(os.path.join(root, 'include', '_newlib_version.h'), 'r')
|
||||||
if f:
|
if f:
|
||||||
@ -86,6 +85,33 @@ def GetNewLibVersion(rtconfig):
|
|||||||
f.close()
|
f.close()
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
# FIXME: it's not very good
|
||||||
|
def CheckMUSLLibc(rtconfig):
|
||||||
|
if 'musl' in rtconfig.PREFIX:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
# FIXME: there is no musl version or musl macros can be found officially
|
||||||
|
def GetMuslVersion(rtconfig):
|
||||||
|
version = 'unknown'
|
||||||
|
# root = GetGCCRoot(rtconfig)
|
||||||
|
# print(root)
|
||||||
|
return version
|
||||||
|
|
||||||
|
# return libc name and version
|
||||||
|
def GetGCCLibcNameVersion(rtconfig):
|
||||||
|
if rtconfig.PLATFORM != 'gcc':
|
||||||
|
return ('unknown', 'unknown')
|
||||||
|
|
||||||
|
newlib_version = GetNewLibVersion(rtconfig)
|
||||||
|
if newlib_version != 'unknown':
|
||||||
|
return ('newlib', newlib_version) # libc: newlib, version: newlib_version
|
||||||
|
elif CheckMUSLLibc(rtconfig) == True:
|
||||||
|
GetMuslVersion(rtconfig)
|
||||||
|
return ('musl', 'unknown') #libc: musl, version: unknown
|
||||||
|
else:
|
||||||
|
return ('unknown', 'unknown') # libc: unknown, version: unknown
|
||||||
|
|
||||||
def GCCResult(rtconfig, str):
|
def GCCResult(rtconfig, str):
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -173,43 +199,44 @@ def GCCResult(rtconfig, str):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def GenerateGCCConfig(rtconfig):
|
def GenerateGCCConfig(rtconfig):
|
||||||
str = ''
|
# str = ''
|
||||||
cc_header = ''
|
# cc_header = ''
|
||||||
cc_header += '#ifndef CCONFIG_H__\n'
|
# cc_header += '#ifndef CCONFIG_H__\n'
|
||||||
cc_header += '#define CCONFIG_H__\n'
|
# cc_header += '#define CCONFIG_H__\n'
|
||||||
cc_header += '/* Automatically generated file; DO NOT EDIT. */\n'
|
# cc_header += '/* Automatically generated file; DO NOT EDIT. */\n'
|
||||||
cc_header += '/* compiler configure file for RT-Thread in GCC*/\n\n'
|
# cc_header += '/* compiler configure file for RT-Thread in GCC*/\n\n'
|
||||||
|
|
||||||
if CheckHeader(rtconfig, 'newlib.h'):
|
# if CheckHeader(rtconfig, 'newlib.h'):
|
||||||
str += '#include <newlib.h>\n'
|
# str += '#include <newlib.h>\n'
|
||||||
cc_header += '#define HAVE_NEWLIB_H 1\n'
|
# cc_header += '#define HAVE_NEWLIB_H 1\n'
|
||||||
cc_header += '#define LIBC_VERSION "newlib %s"\n\n' % GetNewLibVersion(rtconfig)
|
# cc_header += '#define LIBC_VERSION "newlib %s"\n\n' % GetNewLibVersion(rtconfig)
|
||||||
|
|
||||||
if CheckHeader(rtconfig, 'sys/signal.h'):
|
# if CheckHeader(rtconfig, 'sys/signal.h'):
|
||||||
str += '#include <sys/signal.h>\n'
|
# str += '#include <sys/signal.h>\n'
|
||||||
cc_header += '#define HAVE_SYS_SIGNAL_H 1\n'
|
# cc_header += '#define HAVE_SYS_SIGNAL_H 1\n'
|
||||||
if CheckHeader(rtconfig, 'sys/select.h'):
|
# if CheckHeader(rtconfig, 'sys/select.h'):
|
||||||
str += '#include <sys/select.h>\n'
|
# str += '#include <sys/select.h>\n'
|
||||||
cc_header += '#define HAVE_SYS_SELECT_H 1\n'
|
# cc_header += '#define HAVE_SYS_SELECT_H 1\n'
|
||||||
if CheckHeader(rtconfig, 'pthread.h'):
|
# if CheckHeader(rtconfig, 'pthread.h'):
|
||||||
str += "#include <pthread.h>\n"
|
# str += "#include <pthread.h>\n"
|
||||||
cc_header += '#define HAVE_PTHREAD_H 1\n'
|
# cc_header += '#define HAVE_PTHREAD_H 1\n'
|
||||||
|
|
||||||
# if CheckHeader(rtconfig, 'sys/dirent.h'):
|
# # if CheckHeader(rtconfig, 'sys/dirent.h'):
|
||||||
# str += '#include <sys/dirent.h>\n'
|
# # str += '#include <sys/dirent.h>\n'
|
||||||
|
|
||||||
# add some common features
|
# # add some common features
|
||||||
str += 'const char* version = __VERSION__;\n'
|
# str += 'const char* version = __VERSION__;\n'
|
||||||
str += 'const int iso_c_visible = __ISO_C_VISIBLE;\n'
|
# str += 'const int iso_c_visible = __ISO_C_VISIBLE;\n'
|
||||||
str += '\n#ifdef HAVE_INITFINI_ARRAY\n'
|
# str += '\n#ifdef HAVE_INITFINI_ARRAY\n'
|
||||||
str += 'const int init_fini_array = HAVE_INITFINI_ARRAY;\n'
|
# str += 'const int init_fini_array = HAVE_INITFINI_ARRAY;\n'
|
||||||
str += '#endif\n'
|
# str += '#endif\n'
|
||||||
|
|
||||||
cc_header += '\n'
|
# cc_header += '\n'
|
||||||
cc_header += GCCResult(rtconfig, str)
|
# cc_header += GCCResult(rtconfig, str)
|
||||||
cc_header += '\n#endif\n'
|
# cc_header += '\n#endif\n'
|
||||||
|
|
||||||
cc_file = open('cconfig.h', 'w')
|
# cc_file = open('cconfig.h', 'w')
|
||||||
if cc_file:
|
# if cc_file:
|
||||||
cc_file.write(cc_header)
|
# cc_file.write(cc_header)
|
||||||
cc_file.close()
|
# cc_file.close()
|
||||||
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user