标题:在Linux下用buildroot搭建mips/arm的交叉编译平台 出处:Felix021 时间:Sat, 24 Jan 2009 21:17:18 +0000 作者:felix021 地址:https://www.felix021.com/blog/read.php?1429 内容: @ 2009-06-08 p.s. 这个编译环境是不能编译for开源无线路由器的程序的,因为内核是2.6的 建议参考这篇: http://www.felix021.com/blog/read.php?1467 前两天买了NetGear WRT614 V9,搭载的是Broadcom的200MHz MIPS处理器。 由于使用的是开源操作系统Linux,所以可以刷网上一些NB的固件,比如dd-wrt, tomato, openwrt ... 于是决定把武大校园网的newstar ( felicia修改自superstar修改自mystar ) 集成进去。 想要自己编译newstar,就必须搭建一个交叉编译(cross-compile)平台 也有一种说法是cross compile toochain,交叉编译工具链 反正一个意思:就是能在你现在用的机器上(一般是x86)编译出mips架构的目标代码,很NB。 网上搜了一下,发现有一个好东西阿,它的名字是buildroot 它把制作交叉工具链的整个过程都包干了,你只要选择你想要什么东西就好了 详细介绍和使用见 http://buildroot.uclibc.org/buildroot.html 下面是我的搭建过程: 0. 先安装需要安装的东西 包括: build-essential bison flex ... # sudo apt-get install build-essential bison flex 1. 下载buildroot 我下载的是最新的版本 http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2 当然你也可以在这里找早期的版本 http://buildroot.uclibc.org/downloads/snapshots/ 我把它放在了 /cross 这个目录下面,你可以自己选择,但是下面都以 /cross 为例。 2. 打开terminal,解压buildroot # su root //然后输入密码 # mkdir /cross # cd /cross # mv /{你把它放在哪里了?}/buildroot-snapshot.tar.bz2 ./ # tar jxvf buildroot-snapshot.tar.bz2 //得到 /cross/buildroot 目录 # cd buildroot 3. 配置你需要的东西 # make menuconfig //然后看到了熟悉的界面了吧~~和编译Kernel的一样噢~~ 在Target Architecture里面,选择MIPS (当然,你也可以选择ARM,下面还是以MIPS为例 =.=) 在Toolchain里面选上你需要的编译工具,比如g++(编译newstar需要g++),是 [ ] Build/install c++ compiler and libstdc++? 移动到上面,按一下空格,就会变成 [*] Build/install c++ compiler and libstdc++? 全部确定OK以后选择Exit,点击YES,程序会自动生成一个.config文件 p.s. 建议不要加入对jffs2的支持(默认没有),因为我这里出现编译错误,有个函数没有定义,诡异。。。 4. 下载解压编译 # make 就这么简单,buildroot会帮你把所有需要的安装包下载到/cross/buildroot/dl/并解压编译 下载的文件比较多,大概131M,建议使用电信的ADSL下载,或者你可以自己下载了扔进去 这些文件如下: felix021@felix021-Intrepid:/cross/buildroot/dl$ ls -al 总用量 131M drwxr-xr-x 2 root root 4.0K 2009-01-24 14:58 . drwxr-xr-x 14 root root 4.0K 2009-01-24 20:39 .. -rw-r--r-- 1 root root 16M 2009-01-24 14:58 binutils-2.19.tar.bz2 -rw-r--r-- 1 root root 2.0M 2009-01-24 14:58 busybox-1.13.2.tar.bz2 -rw-r--r-- 1 root root 387K 2009-01-24 14:58 fakeroot_1.9.5.tar.gz -rw-r--r-- 1 root root 57M 2009-01-24 14:58 gcc-4.3.2.tar.bz2 -rw-r--r-- 1 root root 100K 2009-01-24 14:58 genext2fs-1.4.tar.gz -rw-r--r-- 1 root root 1.7M 2009-01-24 14:58 gmp-4.2.2.tar.bz2 -rw-r--r-- 1 root root 51M 2009-01-24 14:58 linux-2.6.28.1.tar.bz2 -rw-r--r-- 1 root root 612K 2009-01-24 14:58 lzo-2.03.tar.gz -rw-r--r-- 1 root root 22K 2009-01-24 14:58 mpfr-2.3.0.patch -rw-r--r-- 1 root root 853K 2009-01-24 14:58 mpfr-2.3.0.tar.bz2 -rw-r--r-- 1 root root 222K 2009-01-24 14:58 mtd-utils-1.1.0.tar.bz2 -rw-r--r-- 1 root root 2.2M 2009-01-24 14:58 uClibc-0.9.30.tar.bz2 -rw-r--r-- 1 root root 416K 2009-01-24 14:58 zlib-1.2.3.tar.bz2 然后就是漫长的下载和编译。。。 5. 如果出了意外。。。那你自己baidu或者google一下。。。 然后你不出意外的话就到这一步了,嗯。 # cd /cross/buildroot/build_mips/staging_dir/usr/bin # ls 然后看到这些好东西了没? felix021@felix021-Intrepid:/cross/buildroot/build_mips/staging_dir/usr/bin$ ls cc mips-linux-ld mips-linux-uclibc-g++ faked mips-linux-ldconfig mips-linux-uclibc-gcc fakeroot mips-linux-ldd mips-linux-uclibc-gcc-4.3.2 ldconfig mips-linux-nm mips-linux-uclibc-gccbug ldd mips-linux-objcopy mips-linux-uclibc-gcov mips-linux-addr2line mips-linux-objdump mips-linux-uclibc-gprof mips-linux-ar mips-linux-ranlib mips-linux-uclibc-ld mips-linux-as mips-linux-readelf mips-linux-uclibc-ldconfig mips-linux-c++ mips-linux-size mips-linux-uclibc-ldd mips-linux-cc mips-linux-strings mips-linux-uclibc-nm mips-linux-c++filt mips-linux-strip mips-linux-uclibc-objcopy mips-linux-cpp mips-linux-uclibc-addr2line mips-linux-uclibc-objdump mips-linux-g++ mips-linux-uclibc-ar mips-linux-uclibc-ranlib mips-linux-gcc mips-linux-uclibc-as mips-linux-uclibc-readelf mips-linux-gcc-4.3.2 mips-linux-uclibc-c++ mips-linux-uclibc-size mips-linux-gccbug mips-linux-uclibc-cc mips-linux-uclibc-strings mips-linux-gcov mips-linux-uclibc-c++filt mips-linux-uclibc-strip mips-linux-gprof mips-linux-uclibc-cpp 6. 加入环境变量 # vim /etc/profile 加入下面这一行: export PATH=$PATH:/cross/buildroot/build_mips/staging_dir/usr/bin # source /etc/profile //在重启之前,每次打开一个终端都要再运行一次这个 # mips-linux-gcc --version 如果看到下面这个,恭喜你,可以编译喽~~~~! 引用 mips-linux-g++ (GCC) 4.3.2 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 如果没看到,额,那个。。建议学习一下RP学导论以及Google的使用方法。 7. 修正一个小Bug 在编译newstar的时候遇到这个问题: 引用 /cross/buildroot/build_mips/staging_dir/usr/include/bits/socket.h:272: error: expected initializer before 'throw' Google之,发现是socket.h代码的BUG,修正一下就好了 参考 http://www.nabble.com/include-bits-socket.h-td20795290.html # vim /cross/buildroot/build_mips/staging_dir/usr/include/bits/socket.h 在第271行有一个Macro: extern struct cmsghdr * __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg)) __THROW; 这个宏有点错,注释掉就可以了,如果不放心,就加入下面这个宏,替换它: extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg) __THROW; 存盘退出,然后就可以用 mips-linux-gcc 或者 mips-linux-g++ 来编译拉,挖哈哈哈~~~ =========华丽的分割线=========== 由于netgear的flash才只有2M,所以决定回武汉去买一个更好的无线路由器,4M flash的,到时候再刷 现在呢,就先把newstar的源码(包括修改过的Makefile),编译好的newstar,以及 libpcap_0.9.4-1_mipsel.ipk 附上提供下载: 点击这里下载文件点击这里下载文件 回武汉以后一定要把它搞定,这样宿舍一个月可以省下来几十块上网费,一年下来也很可观的哦~~~~ Generated by Bo-blog 2.1.0