Skip to content

Commit 479acdb

Browse files
atxhuaRbb666
authored andcommitted
Add picolib support to bsp/x86, default to newlib
- add i686-atxhua-picolib-elf-gcc toolchain - add picolib option to bsp/x86 - add necessary picolib require library
1 parent 0b2e35a commit 479acdb

9 files changed

Lines changed: 148 additions & 0 deletions

File tree

.github/workflows/manual_dist.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ on:
3636
- "gcc"
3737
- "sourcery-riscv32-esp32"
3838
- "i686-x86-newlib"
39+
- "i686-x86-picolib"
3940
bsp_config:
4041
description: 'Type a config you want mannual test in .config, like: CONFIG_RT_USING_DEBUG=y,CONFIG_RT_DEBUGING_COLOR=y,CONFIG_RT_DEBUGING_CONTEXT=y'
4142
required: false
@@ -135,6 +136,13 @@ jobs:
135136
echo "RTT_EXEC_PATH=/opt/i686-atxhua-newlib-elf-gcc/bin" >> $GITHUB_ENV
136137
echo "RTT_CC_PREFIX=i686-atxhua-newlib-elf-" >> $GITHUB_ENV
137138
139+
- name: Install i686 X86 Picolib ToolChains
140+
if: ${{ github.event.inputs.bsp_tool_chain == 'i686-x86-picolib' && success() }}
141+
run: |
142+
source tools/ci/toolchain.sh i686-atxhua-picolib-elf-gcc
143+
echo "RTT_EXEC_PATH=/opt/i686-atxhua-picolib-elf-gcc/bin" >> $GITHUB_ENV
144+
echo "RTT_CC_PREFIX=i686-atxhua-picolib-elf-" >> $GITHUB_ENV
145+
138146
- name: Bsp Scons Compile
139147
if: ${{ success() }}
140148
shell: bash

bsp/x86/.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64
306306
# CONFIG_RT_USING_LCD is not set
307307
# CONFIG_RT_USING_HWCRYPTO is not set
308308
# CONFIG_RT_USING_WIFI is not set
309+
# CONFIG_RT_USING_RPMSG is not set
309310
# CONFIG_RT_USING_BLK is not set
310311
# CONFIG_RT_USING_REGULATOR is not set
311312
# CONFIG_RT_USING_POWER_SUPPLY is not set
@@ -944,6 +945,12 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
944945
# CONFIG_PKG_USING_FT32F4_STD_DRIVER is not set
945946
# CONFIG_PKG_USING_FT32F4_CMSIS_DRIVER is not set
946947
# end of FT32 HAL & SDK Drivers
948+
949+
#
950+
# NOVOSNS Drivers
951+
#
952+
# CONFIG_PKG_USING_NOVOSNS_SERIES_DRIVER is not set
953+
# end of NOVOSNS Drivers
947954
# end of HAL & SDK Drivers
948955

949956
#
@@ -1466,3 +1473,10 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
14661473
# end of RT-Thread online packages
14671474

14681475
CONFIG_IA32=y
1476+
1477+
#
1478+
# X86 Features
1479+
#
1480+
CONFIG_X86_BSP_USING_LIBC=y
1481+
# CONFIG_X86_BSP_USING_PICOLIBC_PORT is not set
1482+
# end of X86 Features

bsp/x86/Kconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,23 @@ config IA32
1515
select RT_USING_COMPONENTS_INIT
1616
select RT_USING_USER_MAIN
1717
default y
18+
19+
menu "X86 Features"
20+
21+
choice
22+
prompt "C Library type"
23+
default X86_BSP_USING_LIBC
24+
25+
config X86_BSP_USING_LIBC
26+
bool "Newlib"
27+
help
28+
Use the standard Newlib implementation.
29+
30+
config X86_BSP_USING_PICOLIBC_PORT
31+
bool "Picolibc (tinystdio)"
32+
select RT_USING_COMPONENTS_INIT
33+
help
34+
Use Picolibc with tinystdio for a smaller footprint.
35+
endchoice
36+
37+
endmenu

bsp/x86/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
# RT-Thread for x86
22

3+
## Intro
4+
This x86 BSP support both newlib & picolib, with toolchain available
5+
- **Newlib:** `i686-atxhua-newlib-elf-`
6+
- **Picolibc:** `i686-atxhua-picolib-elf-`
7+
8+
## Install Toolchain
9+
To install toolchain run the following command:
10+
- **Newlib:** sudo ../../tools/ci/toolchain.sh i686-atxhua-newlib-elf-gcc
11+
- **Picolibc:** sudo ../../tools/ci/toolchain.sh i686-atxhua-picolib-elf-gcc
12+
13+
## Configuration
14+
Use `menuconfig` to select your preferred C library:
15+
1. Run `scons --menuconfig`
16+
2. Navigate to `X86 Features` -> `C Library type`
17+
3. Select either `Newlib`(default) or `Picolibc`
18+
19+
## Building
20+
After select the correct library in `menuconfig`, set the toolchain path and prefix:
21+
### Newlib
22+
```bash
23+
export RTT_EXEC_PATH=/opt/i686-atxhua-newlib-elf-gcc/bin
24+
export RTT_CC_PREFIX=i686-atxhua-newlib-elf-
25+
scons
26+
```
27+
28+
### Picolib
29+
```bash
30+
export RTT_EXEC_PATH=/opt/i686-atxhua-picolib-elf-gcc/bin
31+
export RTT_CC_PREFIX=i686-atxhua-picolib-elf-
32+
scons
33+
```
34+
35+
## Result ELF
36+
### Newlib
37+
```
38+
Memory region Used Size Region Size %age Used
39+
i686-atxhua-newlib-elf-objcopy -O binary rtthread.elf rtthread.bin
40+
i686-atxhua-newlib-elf-size rtthread.elf
41+
text data bss dec hex filename
42+
212900 3274 10844 227018 376ca rtthread.elf
43+
scons: done building targets.
44+
45+
```
46+
47+
### Picolib
48+
```
49+
Memory region Used Size Region Size %age Used
50+
i686-atxhua-picolib-elf-objcopy -O binary rtthread.elf rtthread.bin
51+
i686-atxhua-picolib-elf-size rtthread.elf
52+
text data bss dec hex filename
53+
174122 2568 10528 187218 2db52 rtthread.elf
54+
scons: done building targets.
55+
```
56+
357
这是一份基础的RT-Thread针对x86的版本、移植,主要是能够在qemu中执行。以下说明主要针对Linux的环境,如果是Windows环境,请使用Env工具,同时请自行处理生成iso的方法。
458

559
## 编译
@@ -8,6 +62,7 @@
862

963
* [i386-unknown-elf_for_x86_64-pc-linux-gnu_latest.tar.bz2](http://117.143.63.254:9012/www/rt-smart/i386-unknown-elf_for_x86_64-pc-linux-gnu_latest.tar.bz2)
1064
* [ GCC 15.2.0 w/ Newlib 4.6.0.20260123: https://github.com/atxhua/i686-atxhua-newlib-elf/releases/download/15.2.0/i686-atxhua-newlib-elf-linux.tar.gz ](https://github.com/atxhua/i686-atxhua-newlib-elf/releases/download/15.2.0/i686-atxhua-newlib-elf-linux.tar.gz)
65+
* [ GCC 15.2.0 w/ Picolib 1.8.11: https://github.com/atxhua/i686-atxhua-picolib-elf/releases/download/15.2.0/i686-atxhua-picolib-elf-linux.tar.gz ](https://github.com/atxhua/i686-atxhua-picolib-elf/releases/download/15.2.0/i686-atxhua-picolib-elf-linux.tar.gz)
1166

1267

1368
下载后解压,然后配置RTT_EXEC_PATH & RTT_CC_PREFIX 变量

bsp/x86/picolib/SConscript

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Import('RTT_ROOT')
2+
Import('rtconfig')
3+
from building import *
4+
5+
cwd = GetCurrentDir()
6+
7+
src = Glob('*.c')
8+
9+
CPPPATH = [cwd]
10+
CPPFLAGS = '-specs=picolibc.specs'
11+
12+
group = DefineGroup('Picolib', src, depend = ['X86_BSP_USING_PICOLIBC_PORT'], CPPPATH = CPPPATH, CPPFLAGS = CPPFLAGS)
13+
14+
Return('group')

bsp/x86/picolib/picolib_stdio.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <rtthread.h>
2+
#include <stdio.h>
3+
4+
static int picolibc_putc(char c, FILE *file)
5+
{
6+
(void)file;
7+
8+
if (c == '\n')
9+
{
10+
rt_hw_console_output("\r");
11+
}
12+
13+
rt_hw_console_output((const char *)&c);
14+
return c;
15+
}
16+
17+
static FILE __stdio_out = FDEV_SETUP_STREAM(picolibc_putc, NULL, NULL, _FDEV_SETUP_WRITE);
18+
19+
FILE *const stdout = &__stdio_out;
20+
FILE *const stderr = &__stdio_out;

bsp/x86/rtconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@
351351
/* FT32 HAL & SDK Drivers */
352352

353353
/* end of FT32 HAL & SDK Drivers */
354+
355+
/* NOVOSNS Drivers */
356+
357+
/* end of NOVOSNS Drivers */
354358
/* end of HAL & SDK Drivers */
355359

356360
/* sensors drivers */
@@ -432,4 +436,9 @@
432436
/* end of RT-Thread online packages */
433437
#define IA32
434438

439+
/* X86 Features */
440+
441+
#define X86_BSP_USING_LIBC
442+
/* end of X86 Features */
443+
435444
#endif

bsp/x86/rtconfig.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import os
22

3+
def check_config_key_enable(key):
4+
if not os.path.isfile('.config'): return False
5+
return (key + '=y') in open('.config').read()
6+
37
# toolchains options
48
ARCH='ia32'
59
CPU=''
@@ -30,6 +34,9 @@
3034
OBJCPY = PREFIX + 'objcopy'
3135

3236
DEVICE = ' -mtune=generic'
37+
if check_config_key_enable('CONFIG_X86_BSP_USING_PICOLIBC_PORT'):
38+
DEVICE += ' -specs=picolibc.specs'
39+
3340
CFLAGS = DEVICE + ' -Wall'
3441
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
3542
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T x86_ram.lds -nostartfiles'

tools/ci/toolchain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare -A download_urls=(
1010
["riscv32-esp-elf-gcc"]="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz"
1111
["clang"]="https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz"
1212
["i686-atxhua-newlib-elf-gcc"]="https://github.com/atxhua/i686-atxhua-newlib-elf/releases/download/15.2.0/i686-atxhua-newlib-elf-linux.tar.gz"
13+
["i686-atxhua-picolib-elf-gcc"]="https://github.com/atxhua/i686-atxhua-picolib-elf/releases/download/15.2.0/i686-atxhua-picolib-elf-linux.tar.gz"
1314
)
1415

1516
show_help() {

0 commit comments

Comments
 (0)