在MAC系统下构建uboot的gcc编译环境

29 篇文章 1 订阅
16 篇文章 0 订阅

前言

一直想在MAC系统下搭建路由器的开发环境,OpenWrt官方已经全面支持MAC系统下编译,然而,MT7620的uboot却始终无法顺利编译。原因在于,MT7620的uboot需要用到老版本的gcc342来进行编译,因此,如何在MAC环境中编译gcc342成为本文讨论的重点。


准备工作

下载binutils-2.24.tar.bz2和gcc-3.4.2.tar.bz2源码。二者缺一不可,binutils用于生成as(汇编语言编译器)。


编译

在编译binutils的时候,出现一处错误:

as.c: In function 'dump_statistics':
as.c:977:3: error: 'sbrk' is deprecated (declared at /usr/include/unistd.h:582) [-Werror=deprecated-declarations]
   char *lim = (char *) sbrk (0);
   ^
as.c: In function 'main':
as.c:1146:3: error: 'sbrk' is deprecated (declared at /usr/include/unistd.h:582) [-Werror=deprecated-declarations]
   start_sbrk = (char *) sbrk (0);
   ^
cc1: all warnings being treated as errors
make[4]: *** [as.o] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-gas] Error 2
make: *** [all] Error 2

通过参照

http://stackoverflow.com/questions/20426213/error-building-ellcc

设置编译参数:

./configure --prefix=/opt/mips-gcc --target=mipsel-linux --disable-werror

编译通过。


总结

编译binutils时,需要

./configure --prefix=/opt/mips-gcc --target=mipsel-linux --disable-werror

编译gcc342时,需要

./configure --prefix=/opt/mips-gcc --target=mipsel-linux --enable-languages=c --without-headers --with-newlib --disable-shared --disable-threads

然后分别make,sudo make install

最后编译uboot时,出现了这些错误:

sed: RE error: illegal byte sequence
"/opt/mips-gcc/bin"/mipsel-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
"/opt/mips-gcc/bin"/mipsel-linux-objcopy --gap-fill=0xff -O binary u-boot uboot.bin #temp.bin

===============<<IMPORTANT>>==================
Notes:Uboot firmware is uboot.bin NOT uboot.img
================================================

/bin/sh: readelf: command not found
./tools/lzma --best --keep uboot.bin
./tools/lzma: ./tools/lzma: cannot execute binary file
make: *** [uboot.img] Error 126

这些问题应该就比较好解决了。

对于sed: RE error: illegal byte sequence,可以参考http://stackoverflow.com/questions/19242275/re-error-illegal-byte-sequence-on-mac-os-x

在sed命令前加入 LC_ALL=C sed ...

对于 readelf的问题,可以用sudo port install binutils,得到greadelf

至于lzma,相信聪明的你已经想到解决的办法了吐舌头




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值