#linxu下编译i386架构的rtems
rtems相关的文件汇总压缩包,下载链接:链接:https://pan.baidu.com/s/1CGrnnakPs8j93Bpgrzko6A 提取码:6uz0
###rtems介绍
rtems是一个为嵌入式设计的实时操作系统,整个编译过程分为:1.编译rtems的编译工具链2.编译rtems的内核
##编译rtems工具链
###准备:
1.解压文件
解压下载的压缩包,解压的文件中,文件`rtems-source-builder-4.11.3.tar.xz`为编译工具链的源码,`rtems-4.11.3.tar.xz`为rtems内核源码,将这两个文件解压到工作目录下。
2.检查环境
进入源码的目录,执行`./source-builder/sb-check`检查当前环境是否满足要求
```
RTEMS Source Builder - Check, 4.11.not_released
Environment is ok
```
若提示如上则证明环境满足要求,不存在缺编译工具,若提示缺少工具,尝试安装以下工具,然后再执行检查环境指令,直到出现以上提示:
```
$ sudo apt-get install build-essential
$ sudo apt-get install git
$ sudo apt-get install python-dev
$ sudo apt-get build-dep binutils gcc g++ gdb unzip git
```
3.新建文件夹,有这样几个工作文件需要:1.编译工具链的安装路径2.内核的配置路径3.内核的安装路径,注意:2和3不是同一个路径,
```
#新建编译工具链路径
mkdir compiler
#新建内核配置路径
mkdir configrtems
#新建内核安装路径
mkdir installrtems
```
3.准备编译工具链所需要的工具包,编译工具链还需要这些文件:
```
autoconf-2.69.tar.gz gcc-4.9.3.tar.bz2 mpfr-3.0.1.tar.bz2
automake-1.12.6.tar.gz gdb-7.9.tar.xz newlib-2.2.0.20150423.tar.gz
binutils-2.26.tar.bz2 gmp-5.0.5.tar.bz2 rtems-4.11.2.tar.xz
expat-2.1.0.tar.gz mpc-0.8.2.tar.gz rtems-tools-4.11.2.tar.xz
```
这些文件再解压的文件`4.11/source`下,将他们复制到(不要解压)`rtems-source-builder-4.11.3/rtems/sources`目录下
到此,准备工作完成。
###编译工具链
1.编译
进入`rtems-source-builder-4.11.3/rtems`目录,执行指令
```
../source-builder/sb-set-builder --log=build-log.txt \
--prefix=*替换compiler*/4.11\
4.11/rtems-i386
```
将*替换`compiler*`替换为你的compiler目录(之前新建的目录),目录必须为绝对路径,安装会自动进行,直到结束。
2.修改环境变量
编译完后还需修改环境变量,方便以后编译工具链的使用。
```
#修改profile文件
vi ~/.profile
#加入环境变量到最后一行,添加的内容为:
export PATH=*替换compiler*/compiler/4.11/bin:$PATH
```
同样,将*替换compiler*替换为你的compiler目录,然后执行`source ~/.profile`使环境生效.
3.测试环境变量
切换到任意目录,执行`i386-rtems4.11-gcc -v`命令,观察是否有说明gcc的版本,若有,则说明安装成功
###编译内核
1.配置内核
打开两个shell,一个进入rtems的源码目录,一个进入rtems的配置目录(注意一个是配置目录,一个是源码目录,后面多次会用到)且这两个目录不能为同一个。首先在源码目录执行 `./bootstrap`执行完后提示:
```
./testsuites/sptests
./testsuites/fstests
./testsuites/psxtmtests
./testsuites/psxtests
./testsuites/smptests
./testsuites/tools/generic
./testsuites/tools
./testsuites/mptests
./testsuites/rhealstone
./testsuites/samples
./testsuites/tmtests
./testsuites/libtests
./testsuites
```
执行结束后,在配置目录执行:
```
../rtems-4.11.3/configure
--target="i386-rtems" --enable-rtemsbsp=pc386 --enable-tests=samples --prefix=$HOME/installrtems
```
注意,configure为rtems的源码文件夹下的文件,你需要通过相对路径来指定,`--prefix=`后的路径为rtems安装目录,必须是绝对路径,执行完后提示:
```
target architecture: i386.
available BSPs: pc386.
'make all' will build the following BSPs: pc386.
other BSPs can be built with 'make RTEMS_BSP="bsp1 bsp2 ..."'
config.status: creating Makefile
```
2.编译
在rtems的配置目录执行:
```
make
make install
```
编译完成,这个步骤可能会报错:
```
Makefile:755: recipe for target 'pc386' failed
make[2]: *** [pc386] Error 1
make[2]: Leaving directory '/home/netlab/rtems/temp_build/i386-rtems/c'
Makefile:286: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/netlab/rtems/temp_build/i386-rtems/c'
Makefile:410: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
```
解决方法:
1.在rtems的源码目录执行
```
./bootstrap -c
./bootstrap
```
2.删除rtems的配置目录的所有文件(注意,是rtems的配置目录!!!)。
3.重新执行
```
../rtems-4.11.3/configure
--target="i386-rtems4.11" --enable-rtemsbsp=pc386 --enable-tests=samples --prefix=$HOME/installrtems
make
make install
```
3.测试:
1.安装qemu
```
sudo apt-get install qemu
```
2.运行测试案例
切换到配置目录下的`i386-rtems4.11/c/pc386/testsuites/samples/hello/`目录下,该目录有这几个文件
```
hello.bin hello.exe hello.num hello.ralf init.o Makefile
```
执行
```
qemu-system-i386 -kernel hello.exe
```
测试成功!!