Nuttx编译过程记录

 

Nuttx开发

1开发环境

该系统需要在linux环境下开发, 本人在VMware Workstation虚拟机中安装centos 6.6作为开发环境; 一下开发均在centos6中开发、编译。

 

 

2安装kconfig配置前端

   网上下载kconfig-frontends-3.9.0.0.tar.xz配置工具,编译、安装

   tar –xJvf  kconfig-frontends-3.9.0.0.tar.xz   解压

   cd  kconfig-frontends

   ./configure

   make

   make install

        

 注意:依赖ncurses和gperf,先要安装ncurses和gperf。

 

3安装gcc toolchain

安装gcc交叉编译器

  

  从网站http://www.yagarto.org/下载安装交叉开发环境YAGARTO - Yet another GNU ARM toolchain,并安装到/opt目录

  cd  /opt

  tar  -xjvf  gcc_arm-none-eabi-4_8-2014q2-20140609-linux.tar.bz2

  mv   gcc_arm-none-eabi-4_8-2014q2-20140609-linux  gcc_arm-none-eabi

再编辑/etc/profile添加arm-none-eabi-gcc编译器路径到linux系统

 

4 安装源代码

   1》 下载nuttx, apps, ucLibc++源代码包

   2》 解压代码包

   3》 安装ucLibc++ 到nuttx代码树中;

       <1>  cd   ucLibc++

       <2>  ./install.sh    ../nuttx   将include头文件复制到nuttx/include,将uclibc++ 复制到源目录libxx

 

最后目录结构为:

<some-dir>/

       |----/app     //应用代码

       |----/nuttx   // os代码

 

 

5 编译代码

 步骤一: 复制默认配置

      cd   ${TOPDIR}/tools

      ./configure.sh    <board-name>/<config-dir>

 

运行上面的命令将configs/<board-name>/<config-dir>目录下的3个配置文件复制到顶层目录${TOPDIR},(也可以手动复制):

  <1> 复制configs/<board-name>/<config-dir>/setenv.sh到 ${TOPDIR}/setenv.sh

  <2> 复制configs/<board-name>/<config-dir>/defconfig到 ${TOPDIR}/.config

  <3> 复制 configs/<board-name>/<config-dir>/setenv.sh到 ${TOPDIR}/setenv.sh

 

 

 步骤二: 设置环境变量

     cd  ${TOPDIR}

     .   ./setenv.sh

 

 

步骤三: 修改配置

     Make  menuconfig

    通过图形界面修改默认参数,并保存退出,在${TOPDIR}目录下生成.config配置文件

 

步骤四: 编译目标文件

方法1:  隐藏不需要的编译信息

     make

方法2:  显示详细编译信息, 但编译出错时,用该方法可以迅速定位问题。

     make  V=1

 

   在${TOPDIR}目录生成nuttx执行文件

 

 

说明:

   Make  clean     清除编译中间文件

   Make  distclean  清除全部生成文件,包括3个配置文件

 

 

例1 -编译nsh

     [root@centos nuttx]#   cd tools

     [root@centos tools]#   ./configure.sh stm32f4discovery/nsh

     [root@centos tools]#   cd  ..

     [root@centos nuttx]#   .  ./setenv.sh

     [root@centos nuttx]#   make menuconfig

    修改build setup à build host platform(windows) 为linux

 

修改system type --->  toolchain selection为generic GNU EABI toolchain under linux

 

     [root@centos nuttx]#  make

 

  编译后生成nuttx, nuttx.bin, nuttx.hex文件。

  nuttx     为elf格式文件;

  nuttx.bin 为二进制文件;

  nuttx.hex 为hex文件,可以直接烧写到mcu中。

 

 

例2 -编译cxxtest

     [root@centos nuttx]#   cd tools

     [root@centos tools]#   ./configure.sh stm32f4discovery/cxxtest

     [root@centos tools]#   cd  ..

     [root@centos nuttx]#   .  ./setenv.sh

     [root@centos nuttx]#   make menuconfig

 修改build setup à build host platform(windows) 为linux

 

     [root@centos nuttx]#  make

 

 

问题1:

编译时出现出现如下错误信息:库libsupc++.a(vterminate.o)需要_impure_ptr标号无法找到。

     .../lib/libsupc++.a(vterminate.o): In function `__gnu_cxx::__verbose_terminate_handler()':     vterminate.cc:(....): undefined reference to `_impure_ptr'

 

解决方法:(读取/configs/ stm32f4discovery/README.txt)

   编译器arm-none-eabi-gcc中用的时newlib库, 而nuttx中用uclibc++库,两者不兼容。需要用uclibc++中的vterminate.o 替代libsupc++.a中的(vterminate.o)。

步骤:

   1. Get the directory where you can find libsupc++:

          arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -print-file-name=libsupc++.a

 

     2. Go to that directory and save a copy of vterminate.o (in case you want to restore it later):

          cd <the-directory-containing-libsupc++.a>

          arm-none-eabi-ar.exe -x libsupc++.a vterminate.o

 

     3. Then remove vterminate.o from the library.  At build time, the  uClibc++ package will provide a usable replacement vterminate.o.

 

       Now NuttX should link with no problem.  If you want to restore the vterminate.o that you removed from libsupc++, you can do that with:

       arm-none-eabi-ar.exe  -rcs  libsupc++.a  vterminate.o

 

  1. 执行如下命令查找libsupc++所在的目录

         arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -print-file-name=libsupc++.a

2. 进入libsupc++.a所在目录,并从库libsupc++.a中解压出vterminate.o文件备份。

     cd  /opt/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/

     arm-none-eabi-ar  -x  libsupc++.a  vterminate.o

    此时,目录下多出文件vterminate.o

3. 从库libsupc++.a中删除vterminate.o文件,使用nuttx自带的uclibc++中的对应文件。

    arm-none-eabi-ar  -d  libsupc++.a  vterminate.o

 

   现在重新编译连接nuttx,将不会再出现问题。

如果需要将vterminate.o重新添加到库libsupc++.a文件中,则执行如下命令:

    arm-none-eabi-ar.exe  -rcs  libsupc++.a  vterminate.o

  

 

 

问题2:

uClibc++/vector.cxx:50:79: error: duplicate explicit instantiation of 'void std::vector<T, Allocator>::reserve(std::vector<T, Allocator>::size_type) [with T = unsigned char; Allocator = std::allocator<unsigned char>; std::vector<T, Allocator>::size_type = unsigned int]' [-fpermissive]

  template _UCXXEXPORT void vector<bool, allocator<bool> >::reserve(size_type n);

                                                                               ^

uClibc++/vector.cxx:64:95: error: duplicate explicit instantiation of 'void std::vector<T, Allocator>::resize(std::vector<T, Allocator>::size_type, const T&) [with T = unsigned char; Allocator = std::allocator<unsigned char>; std::vector<T, Allocator>::size_type = unsigned int]' [-fpermissive]

  template _UCXXEXPORT void vector<bool, allocator<bool> >::resize(size_type sz, const bool & c);

                                                

 

解决方法: 注释掉 50行, 64行

    template _UCXXEXPORT void vector<bool, allocator<bool> >::reserve(size_type n);

    template _UCXXEXPORT void vector<bool, allocator<bool> >::resize(size_type sz, const bool & c);

 

 

 

 

 

 

 

 

 

 

 

编译buildroot工具链

1.1安装kconfig配置前端

   网上下载kconfig-frontends-3.12.0.0.tar.gz配置工具,编译、安装

  1. xz工具解压
  2. tar工具解压
  3. 配置、编译、安装configure; make; make install

     注意: 依赖ncurses和gperf

 

 

1.2 安装源代码

   1》 下载nuttx, apps, ucLibc++源代码包

   2》 解压代码包

   3) 安装ucLibc++ 到nuttx代码树中;

       <1>  cd   ucLibc++

       <2>  ./install.sh    ../nuttx  

       <3>  修改make.def中的项,加入ucLIBC++的支持(参考ucLibc++目录下的readme文件)。

头文件:

修改前ARCHINCLUDESXX =  -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx

修改后ARCHINCLUDESXX =  -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx  -isystem $(TOPDIR)/include/uClibc++

 

 

1.3 准备需要的文件

 

  1. 下载buildroot工具链

   到开源网站,下载最新的buildroot包

  1. 下载unitil源代码

    ftp://mirrors.kernel.org/gnu/binutils/binutils-2.24.tar.bz2

  1. 下载gcc源代码

    ftp://mirrors.kernel.org/gnu/gcc/gcc-4.3.2/gcc-4.8.2.tar.bz2

 

4. 下载GMP+MPFR+MPC

 去官网ftp://gcc.gnu.org/pub/gcc/infrastructure/下载

mpfr-2.3.2.tar.gz,gmp-4.2.4.tar.gz,mpc,mpc-0.8.1.tar.gz编译gcc时要用到它们。

 

 

1.4 编译buildroot工具链

  1. 将下载的工具包buildroot-x.x.tar.gz解压到nuttx的根目录,得到buildroot-x.x/目录;

    再将buildroot-x.x/目录改名为buildroot/

  2 建立目录misc/archives/ 并将下载的源代码包binutils-2.24.tar.gz2 , gcc-4.8.2.tar.bz2放到该目录下, 编译时make自动解压包文件。 目录结构如下:

  

<some-dir>/

       |----/app

       |----/nuttx

       |----/misc/buildroot

       |----/misc/archives/

       |-----------/archives/binutils-2.24.tar.bz2

       |-----------/archives/gcc-4.8.2.tar.bz2

 

 

3 编译步骤:(参考程序中的readme文件)

 1> . 进入<some-dir>/nuttx目录,配置nuttx系统, buildroot需要用到该目录的文件和配置信息。.

     cd tools

     ./configure.sh STM32F3Discovery/<sub-dir>

 

  2.>  复制configs目录下的模板到根目录下,并改为配置文件.config

      cd <some-dir>/buildroot

      cp configs/cortexm3-eabi-defconfig-4.8.2   .config

 

  3>  通过菜单修改配置文件.config;

       make  menuconfig

     

需要修改如下:并保存。

  • build options à GNU build hostname  suffix; 去掉前缀
  • toolchain à  binutils Version; 修改为下载的版本(binutils-2.24.tar.bz2
  • toolchain à  Gcc compiler Version; 修改为下载的版本(gcc-4.8.2.tar.bz2

 

  1. 编译

     make

     如果编译过程中不出现问题,则在buildroot/build_xxx_xxx/ staging_dir目录下生成gcc交叉编译环境。

 

5 >  将staging_dir目录copy成/usr/arm-nuttx;并将bin目录添加到PATH路径。

 

 

 

 

1.5 问题解决

   编译时,必定会出现一些问题导致无法正常编译。 需要逐步解决

 

 

问题1:

运行make时出现如下错: 提示没有gcc编译器

 

该错误来自文件toolchain/dependencies/dependencies.sh中

将该文件中第3行set –x打开,重新运行make会输出执行的信息。对信息分析发现

不能从gcc –v中得到版本号。 (因为我的linux设置为中文版)

     需要将linux系统默认语言设置为英文(修改文件/etc/sysconfig/i18n 将LANG=zh_CN.UTF-8修改为LANG=en_US.UTF-8;重启linux即可)

 

 问题2:  编译binutils时出错

    配置无法完成, 出现下图错误:

 

方法1:修改文件(some_dir)/ buildroot/toolchain/package/makefile.in中的宏定义为:

         GNU_HOST_NAME:=$(subst ",,$(BR2_GNU_BUILD_SUFFIX))

方法2:  修正文件(some_dir)/ buildroot/toolchain/binutils/binutils.mk

删除 下图中的2行,则删—build=i386-\  --host=i386-\两行, 编译通过。

 

 

 

 

 

问题3: 编译gcc出错

    

 

方法1: (同binutils)

方法2: 将文件buildroot/toolchain/gcc/gcc-nuttx-4.x.mk中的113、114行删除

 

 

问题4: 编译gcc出错

一般会出现错误:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.

说明gcc需要以来GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+

所以需要去gcc官方下载相应包:ftp://gcc.gnu.org/pub/gcc/infrastructure/

先安装GMP,其次MPFR,最后才是MPC

(一) 编译安装步骤如下:

    1. ./configure
    2. make
    3. make  check
    4. make   install

(二)将安装目录添加到搜索路径中:

      添加文件 /etc/ld.so.conf.d/nuttx.conf , 在文件中加入搜索路径“/usr/local/lib”并保存

      执行 ldconfig  重新加载搜索路径。

 

重新执行make   

   ---大功告成---

 

 

 

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值