我在VMware上搭建,平台是RHEL 5.1SERVER 。

 由于最近忙于找工作,有点忙,本文还有没完善之处,请多多见谅!!!

 

 

Buildroot是一个Makefiles和patches的命令集,它可以非常简单的为你的目标系统产生一个交叉编译工具链和根文件系统。这个交叉编译工具使用uClibc (http://www.uclibc.org/),一个很小的标准库。

      下载一个buildroot,这是个工具集,接下来所要做的事情就是把gcc、binutils等文件下载下来,放在buildroot下的dl目录下(如果没有这个目录就自己创建一个就OK了)当然,你也可以让buildroot自动下载,MAKE的时候会自动解析DL目录下的文件,不过速度较慢。
      选择目标的为MIPS,以及一些工具的版本,顺利的话,你编译完后就能得到MIPS的gcc交叉编译器了。

还包括文件系统(busybox),n多的可选应用程序(sqlite等)。



 

 获取 Buildroot

Buildroot通过每天的SVN镜像文件或者直接使用SVN就可以得到。最新的镜像文件一直都放置在 http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2   ,并且之前的镜像也是放置在 http://buildroot.uclibc.org/downloads/snapshots/   。

可以在linux上用命令下载:

#wget http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2 

也可以在window上下载后,再放到vm linux上

 

 


解压:

   #tar -jxvf buildroot-snapshot.tar.bz2

   #cd buildroot

linux上搭建mips交叉编译工具链 - 风之子 - 风之子
 
安装ncurses libraries(这是在执行make menuconfig时需要的一个库),可以在系统光盘上的Server这个文件夹上找到下面的rpm包。
     #rpm -ivh ncurses-5.5-24.20060715.i386.rpm
     #rpm -ivh ncurses-devel-5.5-24.20060715.i386.rpm
make 时需要bison、flex、texinfo
    #rpm -ivh bison-2.3-2.1.i386.rpm
    #rpm -ivh bison-devel-2.3-2.1.i386.rpm
    #rpm -ivh bison-runtime-2.3-2.1.i386.rpm
    #rpm -ivh flex-2.5.4a-41.fc6.i386.rpm
    #rpm -ivh texinfo-4.8-14.el5.i386.rpm     // 不装会出现makeinfo错误
 


 

 第一步是运行配置助手:

 # make menuconfig

linux上搭建mips交叉编译工具链 - 风之子 - 风之子
 

            一个关键的配置项目是PROFECT,它决定了在构建这些包的位置,以及结果安装的位置。

        一旦所有的都配置完成了,配置工具将产生一个.config文件,里面包含了了你的配置信息,它将会被Makefile使用,来决定需要哪些文件

 

Target Architecture (MIPS (little endian))

Target Architecture Variant (mips 32)

Target ABI (o32)  --->

Toolchain type (Buildroot toolchain)  --->                   │ │ 

  │ │        *** Kernel Header Options ***                                │ │ 

  │ │        Kernel Headers (Linux 2.6.36.x kernel headers)  --->  //修改所使用的内核挑版本

 


编译:

       #make FORCE_UNSAFE_CONFIGURE=1

  注:如果用#make编译,会出现下面的问题:

checking whether mknod can create fifo without root privileges... configure: error: in `/home/mya/buildroot/output/build/host-tar-1.26':
configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
See `config.log' for more details.
make: *** [/home/mya/buildroot/output/build/host-tar-1.26/.stamp_configured] Error 1

 


报错:

[ALL  ]   
/home/myb/buildroot/output/host/usr/lib/ct-ng-1.13.4/scripts/functions: line 158: 23250 Aborted                 "${@}" 2>&1
     23251 Done                    | CT_DoLog "${level}"
[ALL  ]    --00:37:35--  http://ftp.kernel.org/pub/linux/kernel/v3.x/longterm/v3.0/linux-3.0.4 (longterm/v3.0/linux-3.0.4这个文件是没有的)
[ALL  ]    Resolving ftp.kernel.org... 149.20.4.69
[ALL  ]    Connecting to ftp.kernel.org|149.20.4.69|:80... connected.
[ALL  ]    HTTP request sent, awaiting response... 404 Not Found
[ALL  ]    File `/home/myb/buildroot/output/build/build-toolchain/.build/tarballs/linux-3.0.4.tmp-dl' already there; not retrieving.
[ALL  ]   

./output/build/host-crosstool-ng-1.13.4/scripts/build/kernel/linux.sh
CT_KERNEL_VERSION

[root@localhost buildroot]# pwd
/home/buildroot

[root@localhost buildroot]# find . -name "*" | xargs grep CT_KERNEL_VERSION

 

2

e4defrag.c:210:2: warning: #warning Using locally defined sync_file_range interface.

e4defrag.c:237:2: warning: #warning Using locally defined fallocate syscall interface.

e4defrag.c:240:2: error: #error Your kernel headers dont define __NR_fallocate

e4defrag.c: In function ‘fallocate64’:

e4defrag.c:253: error: ‘__NR_fallocate’ undeclared (first use in this function)

e4defrag.c:253: error: (Each undeclared identifier is reported only once

e4defrag.c:253: error: for each function it appears in.)

make[3]: *** [e4defrag.o] Error 1

make[3]: *** Waiting for unfinished jobs....

        SUBST tune2fs.8

make[3]: Leaving directory `/home/buildroot/output/build/host-e2fsprogs-1.42.2/misc'

make[2]: *** [all-progs-recursive] Error 1

make[2]: Leaving directory `/home/buildroot/output/build/host-e2fsprogs-1.42.2'

make[1]: *** [all] Error 2

make[1]: Leaving directory `/home/buildroot/output/build/host-e2fsprogs-1.42.2'

make: *** [/home/buildroot/output/build/host-e2fsprogs-1.42.2/.stamp_built] Error 2

解决方法: 

按如下形式修改/misc/e4defrag.c: 

[root@localhost buildroot]# find -name e4defrag.c

./output/build/host-e2fsprogs-1.42.2/misc/e4defrag.c

[root@localhost buildroot]# gedit ./output/build/host-e2fsprogs-1.42.2/misc/e4defrag.c

 

新增 

#ifndef __NR_fallocate

#define __NR_fallocate 324

#endif

 

注释掉这些行 

/#ifndef __NR_sync_file_range

//#ifndef __NR_sync_file_range2 /* ppc */

//#error Your kernel headers dont define __NR_sync_file_range

//#endif

//#endif

 

sync_file_range 函数修改为如下形式:

int sync_file_range(int fd, loff_t offset, loff_t length, unsigned int flag)

{

#ifdef __NR_sync_file_range

  return syscall(__NR_sync_file_range, fd, offset, length, flag);

//#else

  #elif defined(__NR_sync_file_range2)

    return syscall(__NR_sync_file_range2, fd, flag, offset, length);

  #else

    return fsync(fd);

#ifndef SYNC_FILE_RANGE_WAIT_BEFORE

#define SYNC_FILE_RANGE_WAIT_BEFORE 0

#endif

#ifndef SYNC_FILE_RANGE_WRITE

#define SYNC_FILE_RANGE_WRITE 0

#endif

#ifndef SYNC_FILE_RANGE_WAIT_AFTER

#define SYNC_FILE_RANGE_WAIT_AFTER 0

#endif

#endif

}

 

 



 

如果你的电脑不能上网,那就需要你自己上网下载编译时需要的各种包,你可以根据提示到相应的网站下载,如:make时需要tar-1.26.cpio.gz,这个压缩包,你可以根据显示的网站 http://ftp.gnu.org/pub/gnu/tar/tar-1.26.cpio.gz下载tar-1.26.cpio.gz,然后将这个包放到buildroot/dl/ 下(开始时是没有dl文件夹的,可以用mkdir创建dl文件夹)。

我编译时所需的文件如下:

linux上搭建mips交叉编译工具链 - 风之子 - 风之子
上面的所需文件的下载地址:
http://ftp.gnu.org/pub/gnu/tar/tar-1.26.cpio.gz
 

 

 

 

 

 


参考:

http://www.jtben.com/document/861432
http://www.eefocus.com/bbs/article_864_101801.html

http://blog.csdn.net/songguozhi/article/details/3085718