先下载binutils、gcc、glibc、linux-kernel等包和几个插件,可到
~coldwell/toolchain/
处下载,先解压glibc-2.3.5,打开INSTALL文件,看其中对gcc、awk、sed等软件的要求,此处为:
GNU `make' 3.79 or newer
GCC 3.2 or newer
GNU `binutils' 2.13 or later
GNU `texinfo' 3.12f
GNU `awk' 3.0, or some other POSIX awk
Perl 5
GNU `sed' 3.02 or newer
GNU `autoconf' 2.53 or higher
GNU `gettext' 0.10.36 or later
1、设置环境变量
TARGET=arm-unknown-linux-gnu
PREFIX=/usr/arm
SYSROOT=${PREFIX}/sysroot
export ARCH=arm
export CROSS_COMPILE=${TARGET}-
export PATH=$PATH:${PREFIX}/bin
体系结构和TAEGET变量的对应如下表:
可以在通过glibc下的config.sub脚本来知道,TARGET变量是否被支持:
glibc-2.3.5/scripts/config.sub arm-linux
arm-unknown-linux-gnu
2、建立二进制工具
mkdir -p ${PREFIX}/src
cd ${PREFIX}/src
tar zxvf binutils-2.16.tar.gz
mkdir -p BUILD/binutils-2.16
cd BUILD/binutils-2.16
../../binutils-2.16/configure --prefix=${PREFIX} --target=${TARGET} --with-sysroot=${SYSROOT} && make && make install && echo ok (如果最后一行显示ok则表示安装成功)
3、建立内核头文件
cd ${PREFIX}/src
tar zxvf linux-2.6.10.tar.gz
ln -s linux-2.6.10 linux
zcat 2.6.10-at91.patch.gz | patch -d linux -p1
cd linux
make at91rm9200dk_defconfig
make include/linux/version.h
mkdir -p ${SYSROOT}/usr/include
cp -a ${PREFIX}/src/linux/include/linux ${SYSROOT}/usr/include/linux
cp -a ${PREFIX}/src/linux/include/asm-arm ${SYSROOT}/usr/include/asm
cp -a ${PREFIX}/src/linux/include/asm-generic ${SYSROOT}/usr/include/asm-generic
4、安装glibc头文件
cd ${PREFIX}/src
tar zxvf glibc-2.3.5.tar.gz
patch -d glibc-2.3.5 -p1
cd glibc-2.3.5
tar xvfz ../glibc-linuxthreads-2.3.5.tar.gz
cd ..
mkdir -p BUILD/glibc-2.3.5-headers
cd BUILD/glibc-2.3.5-headers
../../glibc-2.3.5/configure --prefix=/usr --host=${TARGET} --enable-add-ons=linuxthreads --with-headers=${SYSROOT}/usr/include && make cross-compiling=yes install_root=${SYSROOT} install-headers && echo ok
touch ${SYSROOT}/usr/include/gnu/stubs.h
touch ${SYSROOT}/usr/include/bits/stdio_lim.h
5、建立初始编译器
cd ${PREFIX}/src
tar jxvf gcc-3.4.4.tar.bz2
patch -d gcc-3.4.4 -p1 < flow.c.diff
patch -d gcc-3.4.4 -p1 < t-linux.diff
mkdir -p BUILD/gcc-3.4.4-stage1
cd BUILD/gcc-3.4.4-stage1
../../gcc-3.4.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c --with-sysroot=${SYSROOT} && make && make install && echo ok
6、建立c库
cd ${PREFIX}/src
mkdir -p BUILD/glibc-2.3.5
cd BUILD/glibc-2.3.5
BUILD_CC=gcc CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar RANLIB=${CROSS_COMPILE}ranlib AS=${CROSS_COMPILE}as LD=${CROSS_COMPILE}ld ../../glibc-2.3.5/configure --prefix=/usr --build=i386-redhat-linux --host=arm-unknown-linux-gnu --target=arm-unknown-linux-gnu --without-__thread --enable-add-ons=linuxthreads --with-headers=${SYSROOT}/usr/include && make && make install_root=${SYSROOT} install && echo ok
7、建立全套编译器
cd ${PREFIX}/src
mkdir -p BUILD/gcc-3.4.4
cd BUILD/gcc-3.4.4
../../gcc-3.4.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c,c++ --with-sysroot=${SYSROOT} && make && make install && echo ok
8、测试
1)编写一个HelloWorld程序,然后arm-unknown-linux-gnu-gcc helloworld.c -o helloworld
2)file helloworld
aa: ELF 32-bit LSB executable, ARM, version 1, for GNU/Linux 2.0.0, dynamically linked (uses shared libs), not stripped
如果显示出上面的输出,说明你编译了一个能在arm体系结构下运行的 helloworld,证明你的编译工具做成功了。
9、内核镜像(选做)
下载一个26_at91_serial.c.gz文件
1)
cd ${PREFIX}/src/
zcat 26_at91_serial.c.gz > linux/drivers/serial/at91_serial.c
2)
cd ${PREFIX}/src/linux
make zImage
make modules
make INSTALL_MOD_PATH=${SYSROOT} modules_install
阅读(2558) | 评论(0) | 转发(0) |