最近花了點時間重建了給Intel IXP4XX-based Target用的Toolchain
由於IXP4XX系列的CPU事實上是XScale (Strong ARM)的SoC,
所以建立Toolchain時只要指定Target為arm-linux即可
 
Host平台: Fedora Core 10(Kernel為Linux 2.6.27.5-117.fc10.i686)
以下是詳細步驟:
1. Prepared packages
1.1 Software source code packages
binutils-2.19.tar.gz
gcc-4.3.2.tar.gz
glibc-2.8.tar.bz2
glibc-linuxthreads-2.5.tar.bz2
glibc-ports-2.8.tar.bz2
mpfr-2.3.2.tar.gz
 
1.2 Patches
gcc-4.3.2-specs-1.patch
glibc-2.8-alpha_fixes-1.patch
glibc-2.8-libgcc_eh-1.patch
glibc-2.8-localedef_segfault-1.patch
 
1.3 Linux kernel source
Linux kernel 2.6.26
 
2. Before building toolchain
2.1 Prepare for the location to install toolchain
Make the directory to store the target toolchain.
$ sudo mkdir -p /usr/tools-chain/arm/tools
$ sudo mkdir -p /usr/tools-chain/arm/tools/include
$ sudo mkdir -p /usr/tools-chain/arm/tools/lib
 
2.2 Prepare the environment for building toolchain
(Assume the prepared packages are stored on directory /home/ixpgw/arm-toolchain, and current user is ixpgw.)
$ cd /home/ixpgw/arm-toolchain
$ tar -zxvf binutils-2.19.tar.gz
$ tar -zxvf gcc-4.3.2.tar.gz
$ tar -jxvf glibc-2.8.tar.bz2
 
2.3 Create new folders to build each package of toolchain. (Strongly Recommanded!!)
$ mkdir binutils-build gcc-build glibc-build
 
2.4 Do patches for glibc
2.4.1 Batch patch
$ cd ../glibc-2.8
$ tar -jxvf ../glibc-linuxthreads-2.5.tar.bz2
$ tar -jxvf ../glibc-ports-2.8.tar.bz2
$ mv glibc-ports-2.8 ports
$ patch -Np1 -i ../glibc-2.8-alpha_fixes-1.patch
$ patch -Np1 -i ../glibc-2.8-libgcc_eh-1.patch
$ patch -Np1 -i ../glibc-2.8-localedef_segfault-1.patch
2.4.2 Manual patch
Edit glibc-2.8/nptl/sysdeps/unix/sysv/linux/lowlevellock.c
Insert this line of content before #include <lowlevellock.h> at line 23
#include <tls.h>
(Fix the bug of missing THREAD_GETMEM.)
 
2.5 Do patches for gcc
$ cd ../gcc-4.3.2
$ patch -Np1 -i ../gcc-4.3.2-specs-1.patch
Edit gcc/config/linux.h. Add these two lines of content at the tail of file.
#undef  STARTFILE_PREFIX_SPEC
#define STARTFILE_PREFIX_SPEC "/usr/tools-chain/arm/tools/lib/"
$ cp -v gcc/Makefile.in{,.orig}
$ sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /usr/tools-chain/arm/tools/include@g" gcc/Makefile.in.orig > gcc/Makefile.in
 
2.6 Prepare kernel headers
(Assume a copy of kernel source tree is now at /home/ixpgw/arm-toolchain/linux-2.6.26.)
$ cd ../linux-2.6.26
$ make mrproper
$ make ARCH=arm headers_check
$ sudo make ARCH=arm INSTALL_HDR_PATH=/usr/tools-chain/arm/tools headers_install
 
3. Build Toolchain
3.1 Build binutils
Do the following commands
$ AR=ar
$ AS=as
$ ../binutils-2.19/configure --prefix=/usr/tools-chain/arm --target=arm-linux --disable-multilib --with-local-prefix=/usr/tools-chain/arm/tools/lib --disable-nls --enable-shared --disable-multilib
$ make configure-host
$ make
$ make install
$ cp -v ../binutils-2.19/include/libiberty.h /usr/tools-chain/arm/tools/include
 
3.2 Build gcc static
Do the following commands
$ ../gcc-4.3.2/configure --prefix=/usr/tools-chain/arm --target=arm-linux --disable-multilib --with-local-prefix=/usr/tools-chain/arm/tools --disable-nls --disable-shared --disable-threads --enable-language=c
$ make all-gcc all-target-libgcc
$ sudo make install-gcc install-target-libgcc
 
3.3 Build glibc
Do the following commands
$ export PATH=$PATH:/usr/tools-chain/arm/bin
$ echo "libc_cv_forced_unwind=yes" > config.cache
$ echo "libc_cv_c_cleanup=yes" >> config.cache
$ BUILD_CC=gcc
$ CC=arm-linux-gcc
$ AR=arm-linux-ar
$ RANLIB=arm-linux-ranlib
$ ../glibc-2.8/configure --prefix=/usr/tools-chain/arm/tools --host=arm-linux --build=i686-pc-linux-gnu --disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.0 --with-__thread --with-binutils=/usr/tools-chain/arm/bin --with-headers=/usr/tools-chain/arm/tools/include --cache-file=config.cache
$ make
$ sudo make install
 
3.4 Build gcc final
Do the following commands
$ export PATH=$PATH:/usr/tools-chain/arm/bin
$ rm -rf *
$ ../gcc-4.3.2/configure --prefix=/usr/tools-chain/arm --target=arm-linux --disable-multilib --with-local-prefix=/usr/tools-chain/arm/tools --with-headers=/usr/tools-chain/arm/tools/include --disable-nls --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 -enable-long-long --enable-threads=posix
$ make AS_FOR_TARGET=arm-linux-as LD_FOR_TARGET=arm-linux-ld
$ sudo make install
 
4. Check if there are programs with prefix arm-linux under /usr/tools-chain/arm/bin.
If there are, building of toolchain is done successfully.
 
接下來的工作是用此Toolchain來做bootable kernel image
那又是另外一個故事了...
 
參考資料:
Kernel: http://www.kernel.org
glibc: http://ftp.gnu.org/gnu/glibc/
GCC: http://gcc.gnu.org/
Binutils: http://ftp.gnu.org/gnu/binutils/
Patches: http://ftp.osuosl.org/pub/clfs/clfs-packages/svn/
http://svn.cross-lfs.org/svn/repos/cross-lfs/trunk/patches/
arrow
arrow
    全站熱搜

    爽爽小五郎 發表在 痞客邦 留言(0) 人氣()