构建beagleboneblack的rtems5开发环境

      • 编译环境说明
      • 安装工具链
      • 下载RTEMS内核源码
      • 编译bsp包
      • 编译rtems-libbsd
      • 常见错误
      • 一些脚本

编译环境说明

  1. 时间:2018.04.28. rtems-source-builder版本哈希值:10d3aaf。rtems-src哈希值8b5a801,rtems-libbsd哈希值ef5d536。我只是在我当前的版本编译成功,如果遇到问题无法解决可以尝试回退到个版本,然后重新编译
  2. OS:Ubuntu14.04 LTS
  3. 硬件:i7+256G SSD 笔记本

安装工具链

$ git clone git://git.rtems.org/rtems-source-builder.git
$ cd rtems-source-builder/rtems
$ ../source-builder/sb-check
RTEMS Source Builder - Check, 5 (10d3aaf467ae modified)
error: exe: not found: (__bison) /usr/bin/bison
error: exe: not found: (__flex) /usr/bin/flex
error: exe: not found: (__makeinfo) /usr/bin/makeinfo
Environment is not correctly set up
$ sudo apt-get install cmake autoconf bison flex texinfo u-boot-tools libpython2.7-dev pax

其中makeinfo命令包含在texinfo, u-boot-tools包含了mkimage命令,在生成镜像的时候用,pax和libpython2.7都会在后期编译的时候用到

$  ../source-builder/sb-set-builder --log=arm.log --prefix=$HOME/opt/rtems/5  5/rtems-arm.bset 

–log表示保存编译时的Log信息,–prefix的路径是你工具链安装的位置,5/rtems-arm-bset表示构建arm平台的工具链,你也可以尝试其它bset.
下载和编译过程会比较漫长(i7,机械硬盘,编译时间大概是1个小时50分钟, 我的另外一台台式机总共只要半小时),最常遇到问题就是下载失败,每次重新下载的时候会重新编译之前已经编译的包。如果网络环境不,也可以手动下载,把文件原封不动的放在rtems-source-builder/rtems/sources目录下面。

下载RTEMS内核源码

~$ git clone git://git.rtems.org/rtems.git rtems-src
~$ cd rtems-src
rtems-src$ ./bootstrap -c && ./bootstrap

编译bsp包

RTEMS支持ARM,MIPS等多种架构,也支持很多BSP,包括beagleboneblack, raspberry pi, stm32f4 discovery等,我以beagleboneblack为例

~$ mkdir b-beagle
~$ cd b-beagle
b-beagle$ ../rtems-src/configure --target=arm-rtems5 --enable-rtemsbsp=beagleboneblack --enable-cxx --prefix=$HOME/opt/rtems/5 --disable-networking
~$ make 
~$ make install
~$ export PATH=PATH:~HOME/opt/rtems/5/bin

prefix是bsp安装路径,最好和工具链保持一致,后面会减小很多麻烦,而且一定要make install。因为我们要使用rtems-libbsd,所以需要增加选项–disbale-networking。意思就是不使用自带的network包,主要是内置的包功能太少了。export 路径之后会出现 arm-rtems5-gcc命令。

编译rtems-libbsd

~$ git clone git://git.rtems.org/rtems-libbsd.git
~$ cd rtems-libbsd
rtems-libbsd$ git submodule init
rtems-libbsd$ git submodule update rtems_waf

rtems-libbsd使用的是waf来进行编译管理,下载waf工具:

rtems-libbsd$ git clone https://github.com/waf-project/waf
rtems-libbsd$ cd waf
waf$ ./configure
waf$ cd ../
rtems-libbsd$ ./waf/waf configre --prefix=$HOME/opt/rtems/5 --rtems-bsps=arm/beagleboneblack
rtems-libbsd$ ./waf/waf build
rtems-libbsd$ ./waf/waf install

这里的prefix是指rtems-bsp的路径,与上面的保持一致就好。
到这里,rtems的工具链,beagleboneblack的bsp包,libbsd就安装好了。

常见错误

    1.
rtems-libbsd$ ./waf/waf configure --prefix=$HOME/opt/rtems/5 --rtems-bsps=arm/beagleboneblack
Setting top to                           : /home/figo/empty/gitwork/rtems-libbsd 
Setting out to                           : /home/figo/empty/gitwork/rtems-libbsd/build 
No valid arch/bsps found
(complete log in /home/figo/empty/gitwork/rtems-libbsd/build/config.log)

没有找到bsp包,一般情况下是在编译bsp的时候,没有make install
解决办法:

~$ cd b-beagle
b-beagle$ make && make install
    2.
RTEMS kernel contains the old network support; configure RTEMS with --disable-networking
(complete log in /home/figo/empty/gitwork/rtems-libbsd/build/config.log)

这个是在编译libbsd的时候出现的错误,原因就是在编译bsp的时候没有添加 –disable-networking选项
解决办法:

~$ cd b-beagle
~$ ../rtems-src/configure --target=arm-rtems5 --enable-rtemsbsp=beagleboneblack --enable-cxx --prefix=$HOME/opt/rtems/5 --disable-networking
~$ make -j12 && make install
    3.
RTEMS path is not valid. No lib/pkgconfig or rtems-config found.
(complete log in /home/messi/local/rtems-libbsd/build/config.log)

没有把rtems的路径添加到PATH当中去
解决办法:

export PATH=PATH:~HOME/opt/rtems/5/bin
  1. subdir-objects,主要是autoconf的版本问题,也可以使用后面的脚本来解决
Makefile.am:35: warning: source file 'xxx.c' is in a subdirectory,
Makefile.am:35: but option 'subdir-objects' is disabled

解决办法:

~$ cd rtems-src
rtems-src$ python add_subdir-objects.py
    5.
Could not create the directory ///h

这是waf的bug
解决办法:在rtems-libbsd下面有一个隐藏文件夹“.waf-1.9.2-xxx”,在里面找到Node.py,找到

if isinstance(lst,str):

改成:

if isinstance(lst,str) or isinstance(lst, unicode):

有3处,都修改了,然后重新./waf/waf configure

一些脚本

  1. add_subdir-objects.py, 解决subdir-objects警告的脚本,放在rtems-src目录下面,然后运行即可
# !/usr/bin/env python
# -*- coding: utf-8 -*-
""" This Script add "subdir-objects" option for configure.ac file """

import os
import os.path

def add_subdir_objects(filename):
    """ find AM_INIT_AUTOMAKE line and add option
    arg: configure.ac full path
    """
    fd = open(filename, 'r')
    lines = fd.readlines()
    fd.close()
    find = False
    dst_index = 0
    dst_line = ''
    for index, line in enumerate(lines):
        if line.find("AM_INIT_AUTOMAKE") >= 0:
            find = True
            dst_index = index
            dst_line = line
            break
    if find:
        add_option = "subdir-objects"
        options_start = dst_line.find('[')
        options_end = dst_line.find(']')
        if options_end > options_start > 0:
            options = dst_line[options_start+1:options_end].split(' ')
            add_count = options.count(add_option)
            if add_count == 0:
                options.append(add_option)
            elif add_count == 1:
                return False
            elif add_count > 1:
                while add_count > 1:
                    options.remove(add_option)
                    add_count -= 1
            new_line = "AM_INIT_AUTOMAKE([%s])\n" % ' '.join(options)
            print new_line
            lines[dst_index] = new_line
            fd = open(filename, 'w')
            fd.writelines(lines)
            fd.close()

    return True


def main():
    """ main function, no arg
    """
    dst_dir = './'
    for root, dirs, files in os.walk(dst_dir):
        if "configure.ac" in files:
            fullname = os.path.join(root, "configure.ac")
            if add_subdir_objects(fullname):
                print fullname
    pass


if __name__ == '__main__':
    main()
  1. 生成镜像文件的脚本, make_rtems_app.sh, 使用方法:./make_rtems_app.sh hello.exe,就会生成rtems-app.img的压缩的镜像文件
executable=$1
app=rtems-app.img

base=`basename $executable`
arm-rtems4.12-objcopy $executable -O binary ./$base.bin
gzip -9 -f ./$base.bin
mkimage -A arm -O rtems -T kernel -a 0x80000000 -e 0x80000000 -n RTEMS -d ./$base.bin.gz ./$app
rm ./$base.bin.gz

你可能感兴趣的:(ubuntu,嵌入式软件,嵌入式操作系统,嵌入式系统,beaglebone,rtems)