多年前笔者看过RTEMS的相关文档,当时参考几位前辈Ray/雪松/Rickleaf的大作。进来突发奇想,这么多年,这个OS仍然在维护发展,当前最新已经到6版了,用新的CODE游玩一把,略作记录。
把玩RTEMS, 编译环境是少不了折腾的,不过当前已经有人开发了source-builder的工具,编译工具等可以省心不少,4.10.3-RC2是4系列版本中开始有source builder工具的版本,5.3 当前已经支持,这里选用 4.10.3-RC2 和 5.3 两个版本
安装Linux 使用centos 7.6 为避免不必要麻烦,选择全部安装。
从Index of /pub/rtems/releases/4.10/4.10.3-rc2/现在所有文件
解压缩rtems-source-builder-4.10.3-rc2.tar.xz 到该目录下
/root/rtems-source-builder-4.10.3-rc2/rtems
新建patchs sources两个目录,其中patchs 用于放置 .diff 文件,sources 放置其他下载的文件
source-builder完全可以运行命令后,联网自动下载编译,这里提前下载好相关文件放到两个目录中,避免网络问题下载中断导致各种问题。
切换到如下目录
$ cd rtems-source-builder-4.10.3-rc2/rtems
运行如下配置
$ ../source-builder/sb-set-builder --prefix=$HOME/development/rtems/4.10.3-rc2 4.10/rtems-i386
因为相关文件都已提前现在,所以source builder自动开始编译,笔者机器32Core, 编译一共花费10分钟,其中Build NewLib时间最长,编译时可以随时打开rtems-source-builder-4.10.3-rc2/rtems/目录下rsb开头的.txt 文件查看进度
编译后的交叉工具链位于
/root/development/rtems/4.10.3-rc2/
查看内容如下
ls /root/development/rtems/4.10.3-rc2/
bin i386-rtems4.10 include lib lib64 libexec make share
当前4.10版本的交叉工具链已编译生成,放置目录结构如下:
[root@localhost development]# tree -L 3
.├── rtems
│ └── 5.3
│ ├── bin
│ ├── i386-rtems5
│ ├── lib
│ ├── make
│ └── share
├── rtems-arm
│ └── 5.3
│ ├── arm-rtems5
│ ├── bin
│ ├── include
│ ├── lib
│ ├── libexec
│ └── share
└── rtems-i386
├── 4.10.3-rc2
│ ├── bin
│ ├── i386-rtems4.10
│ ├── include
│ ├── lib
│ ├── lib64
│ ├── libexec
│ ├── make
│ └── share
└── 5.3
├── bin
├── i386-rtems5
├── include
├── lib
├── libexec
└── share
下面让我们开始真正的编译代码
RTEMS既可以使用configure 脚本配置然后再make的方式编译,也可以直接用source-builder命令一次搞定,这里我们为了灵活选择configure脚本方式
切换到rtems-4.10-3-rc2 的代码录下
运行boot strap生成配置,一共耗费3分15秒。
[root@localhost rtems-4.10.3-rc2]# ./bootstrap
./c
./c/src/ada-tests
./c/src
./c/src/lib/libbsp/arm
acinclude.m4 is unchanged
后续其他部分打印省略
注意rtems5.3 bootstrap有两种脚本,另外一个是基于python开发的,运行效果相同
设置交叉编译器的路径
export PATH=/root/development/rtems-i386/4.10.3-rc2/bin:$PATH
输入i386-rtems4.10-gcc –v 确认无问题
[root@localhost build-dir]# i386-rtems4.10-gcc -v
Using built-in specs.
Target: i386-rtems4.10
Configured with: ../gcc-4.4.7/configure --prefix=/root/development/rtems/4.10.3-rc2 --bindir=/root/development/rtems/4.10.3-rc2/bin --exec_prefix=/root/development/rtems/4.10.3-rc2 --includedir=/root/development/rtems/4.10.3-rc2/include --libdir=/root/development/rtems/4.10.3-rc2/lib --libexecdir=/root/development/rtems/4.10.3-rc2/libexec --mandir=/root/development/rtems/4.10.3-rc2/share/man --infodir=/root/development/rtems/4.10.3-rc2/share/info --datadir=/root/development/rtems/4.10.3-rc2/share --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=i386-rtems4.10 --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --verbose --with-newlib --with-system-zlib --disable-nls --without-included-gettext --disable-win32-registry --enable-version-specific-runtime-libs --disable-lto --enable-newlib-io-c99-formats --enable-newlib-iconv --enable-newlib-iconv-encodings=big5,cp775,cp850,cp852,cp855,cp866,euc_jp,euc_kr,euc_tw,iso_8859_1,iso_8859_10,iso_8859_11,iso_8859_13,iso_8859_14,iso_8859_15,iso_8859_2,iso_8859_3,iso_8859_4,iso_8859_5,iso_8859_6,iso_8859_7,iso_8859_8,iso_8859_9,iso_ir_111,koi8_r,koi8_ru,koi8_u,koi8_uni,ucs_2,ucs_2_internal,ucs_2be,ucs_2le,ucs_4,ucs_4_internal,ucs_4be,ucs_4le,us_ascii,utf_16,utf_16be,utf_16le,utf_8,win_1250,win_1251,win_1252,win_1253,win_1254,win_1255,win_1256,win_1257,win_1258 --enable-threads --disable-plugin --enable-languages=c,c++
Thread model: rtems
gcc version 4.4.7 20120313 (RTEMS 4.10, RSB no-repo, Newlib 1.18.0) (GCC)
切换到/root/build-dir目录下
Cd /root/build-dir
运行
../rtems-4.10.3-rc2/configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=i386-rtems4.10 --enable-posix --enable-networking --enable-cxx --prefix=/root/development/rtems-4.10.3-rc2-install
make –j 32
make install
32core机器不费吹灰之力,几分钟搞定
因为--prefix=/root/development/rtems-4.10.3-rc2-install
Make install
之后是到/root/development/rtems-4.10.3-rc2-install
编译NETWORK DEMO示例
4系列的版本中包含一网络相关的示例,文件:network-demos-4.10.2.tar.bz2
先设置RTEMS代码编译库的路径
export RTEMS_MAKEFILE_PATH=/root/development/rtems-4.10.3-rc2-install/i386-rtems4.10/pc386
解压缩后切换到network-demos目录下
make
既生成相关的例子,例如http.exe 在如下目录:
[root@localhost build-dir]# ls /root/network-demos-4.10.0/http/o-optimize/
FilesystemImage.o http.bin http.exe http.num http.ralf init.o mongoose_ext.o shttpd_ext.o
[root@localhost build-dir]#
RTEMS 的i386 BSP 默认安装的是DEC21140 网卡,而QEMU 中仿真的
是NE2000 网卡,所以要重新定义相关的宏:
在文件 /root/rtems-4.10.3-rc2/c/src/lib/libbsp/i386/ts_386ex/tools/network_ada/networkconfig.h 中修改如下:
//MAC地址,注意与虚拟机QEMU运行时指定的相同,在另外一篇文章中,我会重点列出QEMU结合TAP网络方式注意事项:
static char ethernet_address[6] = { 0x52, 0x54, 0x00, 0x38, 0xFE, 0x22 };
#define RTEMS_BSP_NETWORK_DRIVER_NAME BSP_NE2000_NETWORK_DRIVER_NAME
#define RTEMS_BSP_NETWORK_DRIVER_ATTACH BSP_NE2000_NETWORK_DRIVER_ATTACH
//wx
/*
* Default network interface
*/
static struct rtems_bsdnet_ifconfig netdriver_config = {
RTEMS_BSP_NETWORK_DRIVER_NAME, /* name */
RTEMS_BSP_NETWORK_DRIVER_ATTACH, /* attach function */
NULL, /* No more interfaces */
"192.168.137.2", /* IP address */
"255.255.255.0", /* IP net mask */
ethernet_address, /* Driver supplies hardware address */
0, /* ignore broadcast */
0, /* mtu */
0, /* rbuf_count */
0, /* xbuf_count */
0x300, /* port */
9, /* irq */
0, /* bpar */
NULL /* driver control pointer */
};
QEMU 仿真NE2000 ISA方式,默认采用IOBASE 0X300 IRQ9, 这里需要对应,当然也可以修改为其他地址,但比较麻烦,不再讨论
/*
* Network configuration
*/
struct rtems_bsdnet_config rtems_bsdnet_config = {
&netdriver_config,
NULL, /* do not use bootp */
8, /* Default network task priority */
256 * 1024, /* Default mbuf capacity */
256 * 1024, /* Default mbuf cluster capacity */
"leo", /* Host name */
"leo", /* Domain name */
"192.168.137.1", /* Gateway */
"192.168.137.2", /* Log host */
{"192.168.137.1" }, /* Name server(s) */
{"192.168.137.1" }, /* NTP server(s) */
0, /* efficiency */
0, /* udp TX buffer */
0, /* udp RX buffer */
0, /* tcp TX buffer */
0, /* tcp RX buffer */
};
QEMU从QEMU for Windows – Installers (64 bit) 下载最新版,我使用的是qemu-w64-setup-20240828.exe
安装TAP网卡之后,运行
qemu-system-i386.exe -m 128 -vga cirrus -kernel p:\http.exe -netdev tap,id=n2,ifname=tap-nic -device ne2k_isa,netdev=n2,mac=52:54:00:38:fe:22
在HOST中打开浏览器,输入地址 http://192.168.137.2 效果如下

QEMU仿真rtems pc386平台网络http server示例编译
1116

被折叠的 条评论
为什么被折叠?



