Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Picolibc in addition to newlib #5762

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ jobs:
run: |
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
wget -q https://github.com/picolibc/picolibc/releases/download/1.7.6/picolibc-1.7.6-10-2020-q4-major.zip
sudo unzip picolibc-1.7.6-10-2020-q4-major.zip -d /opt/gcc-arm-none-eabi-10-2020-q4-major
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
echo "RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_ENV

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/action_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
run: |
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
wget -q https://github.com/picolibc/picolibc/releases/download/1.7.6/picolibc-1.7.6-10-2020-q4-major.zip
sudo unzip picolibc-1.7.6-10-2020-q4-major.zip -d /opt/gcc-arm-none-eabi-10-2020-q4-major
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
echo "RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_ENV

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/action_utest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
run: |
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
wget -q https://github.com/picolibc/picolibc/releases/download/1.7.6/picolibc-1.7.6-10-2020-q4-major.zip
sudo unzip picolibc-1.7.6-10-2020-q4-major.zip -d /opt/gcc-arm-none-eabi-10-2020-q4-major
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
echo "RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_ENV

Expand Down Expand Up @@ -89,4 +91,4 @@ jobs:
python3 qemu_runner.py --system $TEST_QEMU_ARCH --machine $TEST_QEMU_MACHINE --elf ../$TEST_BSP_ROOT/rtthread.elf
fi
cat rtt_console.log
popd
popd
5 changes: 4 additions & 1 deletion bsp/qemu-vexpress-a9/.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=1024
#
# kservice optimization
#
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
CONFIG_RT_KSERVICE_USING_STDLIB=y
CONFIG_RT_KSERVICE_USING_STDLIB_MEMCPY=y
CONFIG_RT_KSERVICE_USING_STDLIB_MEMSET=y
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
# CONFIG_RT_USING_TINY_FFS is not set
CONFIG_RT_KSERVICE_USING_PRINTF=y
# CONFIG_RT_PRINTF_LONGLONG is not set
CONFIG_RT_DEBUG=y
CONFIG_RT_DEBUG_COLOR=y
Expand Down
17 changes: 17 additions & 0 deletions bsp/qemu-vexpress-a9/link.lds
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ SECTIONS
PROVIDE(__dtors_end__ = .);
}

. = ALIGN(8);
.tdata : {
*(.tdata)
*(.tdata.*)
*(.gnu.linkonce.td.*)
}

.tbss (NOLOAD) : {
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
}

__tdata_source = ADDR(.tdata);
__tdata_size = SIZEOF(.tdata);
__tbss_size = SIZEOF(.tbss);
__tls_size = SIZEOF(.tdata) + SIZEOF(.tbss);

. = ALIGN(8);
__data_start = .;
.data :
Expand Down
4 changes: 4 additions & 0 deletions bsp/qemu-vexpress-a9/rtconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

/* kservice optimization */

#define RT_KSERVICE_USING_STDLIB
#define RT_KSERVICE_USING_STDLIB_MEMCPY
#define RT_KSERVICE_USING_STDLIB_MEMSET
#define RT_KSERVICE_USING_PRINTF
#define RT_DEBUG
#define RT_DEBUG_COLOR

Expand Down
1 change: 1 addition & 0 deletions bsp/qemu-vexpress-a9/rtconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_mac_address():

# only support GNU GCC compiler.
PLATFORM = 'gcc'
LIBC = 'picolibc'
EXEC_PATH = r'/usr/bin'

if os.getenv('RTT_EXEC_PATH'):
Expand Down
6 changes: 5 additions & 1 deletion bsp/qemu-vexpress-gemini/.config
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ CONFIG_IDLE_THREAD_STACK_SIZE=512
#
# kservice optimization
#
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
CONFIG_RT_KSERVICE_USING_STDLIB=y
CONFIG_RT_KSERVICE_USING_STDLIB_MEMCPY=y
CONFIG_RT_KSERVICE_USING_STDLIB_MEMSET=y
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
# CONFIG_RT_USING_TINY_FFS is not set
CONFIG_RT_KSERVICE_USING_PRINTF=y
# CONFIG_RT_PRINTF_LONGLONG is not set
# CONFIG_RT_PRINTF_FLOAT is not set
CONFIG_RT_DEBUG=y
CONFIG_RT_DEBUG_COLOR=y
# CONFIG_RT_DEBUG_INIT_CONFIG is not set
Expand Down
4 changes: 4 additions & 0 deletions bsp/qemu-vexpress-gemini/rtconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

/* kservice optimization */

#define RT_KSERVICE_USING_STDLIB
#define RT_KSERVICE_USING_STDLIB_MEMCPY
#define RT_KSERVICE_USING_STDLIB_MEMSET
#define RT_KSERVICE_USING_PRINTF
#define RT_DEBUG
#define RT_DEBUG_COLOR

Expand Down
1 change: 1 addition & 0 deletions bsp/qemu-vexpress-gemini/rtconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ARCH='arm'
CPU='vexpress-a9'
CROSS_TOOL='gcc'
LIBC='picolibc'

if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')
Expand Down
17 changes: 17 additions & 0 deletions bsp/qemu-vexpress-gemini/vexpress.lds
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ SECTIONS
} =0
__text_end = .;

. = ALIGN(8);
.tdata : {
*(.tdata)
*(.tdata.*)
*(.gnu.linkonce.td.*)
}

.tbss (NOLOAD) : {
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
}

__tdata_source = ADDR(.tdata);
__tdata_size = SIZEOF(.tdata);
__tbss_size = SIZEOF(.tbss);
__tls_size = SIZEOF(.tdata) + SIZEOF(.tbss);

__rodata_start = .;
.rodata : { *(.rodata) *(.rodata.*) }
__rodata_end = .;
Expand Down
18 changes: 9 additions & 9 deletions components/drivers/serial/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

/* it's possible the 'getc/putc' is defined by stdio.h in gcc/newlib. */
#ifdef getc
#undef getc
#endif

#ifdef putc
#undef putc
#endif

#ifdef RT_USING_POSIX_STDIO
#include <dfs_file.h>
#include <fcntl.h>
Expand All @@ -47,15 +56,6 @@
#include <termios.h>
#endif

/* it's possible the 'getc/putc' is defined by stdio.h in gcc/newlib. */
#ifdef getc
#undef getc
#endif

#ifdef putc
#undef putc
#endif

static rt_err_t serial_fops_rx_ind(rt_device_t dev, rt_size_t size)
{
rt_wqueue_wakeup(&(dev->wait_queue), (void*)POLLIN);
Expand Down
2 changes: 1 addition & 1 deletion components/libc/compilers/newlib/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group = []
LIBS = ['m'] # link libm
CPPPATH = [cwd]

if rtconfig.PLATFORM == 'gcc':
if rtconfig.PLATFORM == 'gcc' and GetGCCLibc(rtconfig) == None:
LIBS += ['c'] # link libc
src += Glob('*.c')

Expand Down
4 changes: 4 additions & 0 deletions components/libc/compilers/picolibc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Picolibc (GCC) porting for RT-Thread

https://keithp.com/picolibc

37 changes: 37 additions & 0 deletions components/libc/compilers/picolibc/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from building import *
from gcc import *
Import('rtconfig')

src = []
cwd = GetCurrentDir()
group = []
CPPPATH = [cwd]
LIBS = []
CCFLAGS = '--specs=picolibc.specs'
LINKFLAGS = ' --specs=picolibc.specs'

if rtconfig.PLATFORM == 'gcc' and GetGCCLibc(rtconfig) == 'picolibc':
LIBS += ['c'] # link libc
src += Glob('*.c')

#report picolibc version
print('Picolibc version:' + GetPicolibcVersion(rtconfig))

# identify this is Picolibc
CPPDEFINES = ['RT_USING_PICOLIBC', 'LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS']

if GetDepend('RT_PRINTF_FLOAT') == False:
CPPDEFINES += ['-DPICOLIBC_INTEGER_PRINTF_SCANF']
LINKFLAGS += ' -DPICOLIBC_INTEGER_PRINTF_SCANF'

group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS, CCFLAGS = CCFLAGS, LINKFLAGS = LINKFLAGS)


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')
24 changes: 24 additions & 0 deletions components/libc/compilers/picolibc/fcntl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-09-02 Meco Man First version
*/

#ifndef __FCNTL_H__
#define __FCNTL_H__

#include <sys/_default_fcntl.h>

#ifndef O_DIRECTORY
#define O_DIRECTORY 0x200000
#endif

#ifndef O_BINARY
#define O_BINARY 0x10000
#endif

#endif
17 changes: 17 additions & 0 deletions components/libc/compilers/picolibc/machine/time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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_

#include <rtconfig.h>
#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND

#endif /* _MACHTIME_H_ */
Loading