Author: Peizhao Hu [peizhao at itee.uq.edu.au]
Last Update: 26/03/2006
Tutorial is written based on debian dist, slight difference on some step if you are using different dists.
Points to be noticed:
Throughout this tutorial, I will use $ as user privilege and # stands for root privilege.
Cross Compiling
firstly, you will need some tools for setting up cross-development environment. at this point, I suggest newbie to install buildroot http://buildroot.uclibc.org/
Note: Buildroot is a toy for create cross compile tools and root file system that based on Uclibc C library, which is a smaller library than glibc. Buildroot could be installed with normal user privilege.
$ wget http://buildroot.uclibc.org/downloads/buildroot-0.9.27.tar.bz2
$ tar vjxf buildroot-0.9.27.tar.bz2
$ cd builroot
$ make menuconfig
Configuration
I suggest remove some packages from make menuconfig command since, they cause some problems, I have tried different combination of them with no luck. they are gettext, udhcp, usbutil, ruby, thttpd. at this point, I suggest you to use the reference image provided by RouterBoard, because we could install/upgrade any package after you got your fresh kerenl. in this case there is no addition configuration need to be done. during make process you will be asked a few question of determining mips sub-arch.
$ make
I met a lot of problems while i was installing buildroot. Here, I attach some hits at the very end of this page for anyone who might need it. I suggest any of you read the documentation that available on the web, specially, you have to understand how make file for each package is located. After you excute make command, a few directories will be created within buildroot directory: dl - directory stores downloaded packages; package - stores packages configuration and make file; build-xxx - staging directory. you will find there are at least two files config.in and *.mk inside the package directory. These is how buildroot instructs the system to build the tools. many compilation issues can be resolved by change version of package or download repository within *.mk file (where * is package name).
hopefully, you could compile it without anymore additional errors. I would be please to help on any additional problem. please email: peizhao(at)itee.uq.edu.au
Now, you should have your cross compiling tools available from
../buildroot/build_XXX/staging_dir/bin (where XXX is your target architecture, in this case is mipsel), therefore, ../buildroot/build_mipsel/staging_dir/bin
puting this into PATH.
# export PATH=$PATH:/PROJECT_TOOL/buildroot/build_mipsel/staging_dir/bin
OR edit .bashrc file within user home root directory.
you should be able to access the cross compile tools anywhere.
Reference Image
You will need to install linux of reference image from www.routerboard.com.
Download the image from the website, and use linux command dd write it to CF card (here, 1GB CF card is preferred for testing)
# dd if=reference-image.img of=/dev/sdX
X should be your compact flash card read if you use USB, system will recognised it as /dev/sd(a,b,c...). be careful if you use SATA Harddisk, most likely, linux recognises them as /dev/sd(a,b,c) as well. check it with df linux command. at this point, don't worry about the size of reference image is actually bigger then the CF size (because real file system of image is only about 128MB). Next, We need to setup NFS on standard linux machine to provide linux kernel source(why we doing this, because the source tree is too large). Download the source from www.kernel.org and unpack the linux source to /usr/src/ and create a softlink to the kernel directory by:
# wget http://www.kernel.org/pub/linux/kernel/v2.4/(linux-2.x.y.tar.bz) or (linux-2.x.y.tar.gz)
# cd /usr/src
# tar vjxf linux-2.x.y.tar.bz2 OR # tar vzxf linux-2.x.y.tar.gz
then we need RB500 patch from http://www.routerboard.com/rb500.html. Currently, there are two patches availabe on the web site, 2.4.30 with yaffs support and 2.4.31 with NAND size fixed patch.
I suggest to use http://www.routerboard.com/files/linux-2.4.30-yaffs2.patch.gz
#
wget http://www.routerboard.com/files/linux-2.4.30-yaffs2.patch.gz
#
gunzip linux-2.4.30-yaffs2.patch.gz
# cd linux-2.x.y
# patch -p1 <../linux-2.4.30-yaffs2.patch
after patch the kernel source to specific to rb500 mips architecture. config.mipsel and config.i386 were generated.
# cp config.mipsel .config
# vim Makefile (change variable setting of TOOLPREFIX=kgcc to gcc; and CC=kgcc to gcc)
# make ARCH=mips CROSS_COMPILE=mipsel-linux-
Native Compiling (on Device){takes about 3 hours}
You will need to install linux of reference image from www.routerboard.com.Download the image from the website, and use linux command dd write it to CF card, the default image is 128MB, but you can expand it later with gnu parted package. (here, 512MB 140X CF card is preferred, when i tried to use 1GB same band compactflash card, i had problem with usage can't go over 40%, but ask me why I want to know as well).
# dd if=reference-image.img of=/dev/sdX bs=20M
X should be your compact flash card read if you use USB, system will recognised it as /dev/sd(a,b,c...). be careful if you use SATA Harddisk, most likely, linux recognises them as /dev/sd(a,b,c) as well. check it withdf linux command. at this point, don't worry about the size of reference image is actually bigger then the CF size (because real file system of image is only about 128MB). Next, We need to setup NFS on standard linux machine to provide linux kernel source(why we doing this, because the source tree is too large). Download the source from www.kernel.org and unpack the linux source to /usr/src/ and create a softlink to the kernel directory by:On your desktop:
# cd /usr/src
# tar vjxf linux-2.x.y.tar.bz2 OR # tar vzxf linux-2.x.y.tar.gz
# ln -s linux-2.x.y linux
# chmod -R a+rw linux
# vi /etc/exports
* you need to install NFS daemon first(I used nfs-user-server), apt-get install nfs-user-server
* add /usr/src/linux 192.168.1.device-ip/255.255.255.0(rw,no_root_squash) to exports file
* don't forget to restart your NFS server by: /etc/init.d/nfs-user-server restart
On your device:
# cd /usr/src
# mkdir linux
# mount -t nfs 192.168.1.machine-ip:/usr/src/linux linux {it can take some time}
* now, you have you linux kernel source in /usr/src/linux
First, we need to patch our kernel source to MIPS specific, to do this, we need to download kernel patch from www.routerboard.com, I suggest to use 2.4.31 patch, which can be found at linux-2.4.31
# cd /usr/src
# wget http://www.routerboard.com/files/linux-2.4.31.patch.gz
# gunzip linux-2.4.31.patch.gz
# cd linux-2.x.y
# patch -p1 <../linux-2.4.31.patch
after above commands, you should have a nice linux kernel source ready, now we need to install a few compiling packages.
# apt-get install libncurses5 libncurses5-dev {or any version available on your apt repository}
First, since we are compiling directly on the MIPS device. We don't need cross compile, therefore, disable the cross compile option in .config file by setting CONFIG_CROSSCOMPILE to
# CONFIG_CROSSCOMPILE is not set
{to be continued}
Tutorial is created base on following Linux Kernel Rebuild on MIPS
http://myrddin.org/howto/debian-kernel-recompiling/
http://www.gentoo.org/doc/en/handbook/handbook-mips.xml
http://caradhras.ccslab.aueb.gr/kernel.html#native
Errors Log
Gzip
make[1]: Leaving directory `/mnt/hda7/buildroot/build_i386/gzip-1.3.5' rm -rf /mnt/hda7/buildroot/build_i386/root/share/locale /mnt/hda7/buildroot/build_i386/root/usr/info \ /mnt/hda7/buildroot/build_i386/root/usr/man /mnt/hda7/buildroot/build_i386/root/usr/share/doc (cd /mnt/hda7/buildroot/build_i386/root/bin; \ ln -snf gzip gunzip; \ ln -snf gzip zcat; \ ln -snf zdiff zcmp; \ ln -snf zgrep zegrep; \ ln -snf zgrep zfgrep;) make: *** No rule to make target `linux', needed by `pcmcia'. Stop. Solution: remove hostap package by running (#make menuconfig) Gettext Solution: 1. Try different version, by changing .mk file under package/gettext/gettext.mk 2. Take away the gettext package and libintel library
Make
read.c: In function `multi_glob':
read.c:3069: error: `GLOB_ALTDIRFUNC' undeclared (first use in this function)
read.c:3069: error: (Each undeclared identifier is reported only once
read.c:3069: error: for each function it appears in.)
make[3]: *** [read.o] Error 1
make[3]: Leaving directory `/home/phu/rb532-linux/buildroot/build_i386/make-3.81beta4'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/phu/rb532-linux/buildroot/build_i386/make-3.81beta4'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/phu/rb532-linux/buildroot/build_i386/make-3.81beta4'
make: *** [/home/phu/rb532-linux/buildroot/build_i386/make-3.81beta4/make] Error 2
Solution: change to use version 3.77 and modify the configuration file, search for whether setvbuf arguments are reversed in configure file, comment out the exit 1
BusyBox
make install does not create links to libbusybox.so.1.1.1
Solution: make and make install manually.
CoreUtil
Solution: back ward to version 5.93 and change download site to ftp://ftp.gnu.org/gnu/coreutil
Sandbox
Solution: Change site to http://dev.gentoo.org/~azarah/sandbox/ use sandbox-1.2.17.tar.bz2
Thttpd
Cant overwrite sbin directory
Solution: Compile again.
Psmisc
Solution: change to version psmisc-22.1.tar.gz at http://prdownloads.sourceforge.net/psmisc
Ruby
Cant fix remove by make menuconfig
Udhcp
Cant fix
UsbUtil
checking whether the C compiler (/home/phu/rb532-linux/buildroot/build_i386/staging_dir/bin/i386-linux-uclibc-gcc -Os -pipe -I/home/phu/rb532-linux/buildroot/build_i386/root/usr/include -L/home/phu/rb532-linux/buildroot/build_i386/root/usr/lib) works... no
configure: error: installation or configuration problem: C compiler cannot create executables.
make: *** [/home/phu/rb532-linux/buildroot/build_i386/usbutils-0.8/.configured] Error 1
Cant fix
Xfsprogres
Re-enable mtd package that previously disabled. Since xfsprogres is dependent on mtd package.
MTD
mv: cannot overwrite directory `/home/phu/mipsel/buildroot/toolchain_build_mipsel/mtd_orig/mtd-20050122.orig'
Solution: runs make mtd-clean mtd-dirclean mtd-host-clean mtd-host-dirclean
Jiffs2
mkfs.jffs2.c:68:18: error: zlib.h: No such file or directory
/bin/sh: scripts/mkdep: cannot execute binary file
make***[dep-files] Error 126
You need to delete this file, and any other X86 binaries included in the tarball.
Try the following:
cp .config config.ps2
make mrproper
cp config.ps2 .config
make oldconfig
make dep
# wget http://www.routerboard.com/files/linux-2.4.30-yaffs2.patch.gz
# gunzip linux-2.4.30-yaffs2.patch.gz
# cd linux-2.x.y
