arm-linux-cross compile chain building

44 篇文章 0 订阅
33 篇文章 0 订阅

http://blog.csdn.net/pandazhu/article/details/693930


ARM-Linux Cross-Compile Chain - Building From Scratch

binutils 2.16.1, gcc 3.4.5, glibc-2.3.5, Kernel 2.6.15
Author:Zhu Zhenyong      Date:2006-4-27
Email:pandazhu@gmail.com
Host Environment:
Source                       Version
Gentoo                                 2006.0
gcc                                       3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)
binutils                                 2.16.1
glibc                                     2.3.5
linux-kernel                          2.6.15-gentoo-r5
Destination Board
s3c2410(arm920t)
1.     Sources and Patches
Source                     Version
binutils                              2.16.1
http://ftp.gnu.org/gnu/binutils/binutils-2.16.1.tar.bz2
gcc-core                            3.4.5
http://ftp.gnu.org/gnu/gcc/gcc-3.4.5/gcc-core-3.4.5.tar.bz2
gcc                                     3.4.5
http://ftp.gnu.org/gnu/gcc/gcc-3.4.5/gcc-3.4.5.tar.bz2
glibc                                   2.3.5
http://ftp.gnu.org/gnu/glibc/glibc-2.3.5.tar.bz2
glibc-linuxthreads            2.3.5
http://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.5.tar.bz2
linux-kernel                      2.6.15
http://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.tar.bz2
 
Patch
1.        flow.c
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flow.c.diff?cvsroot=gcc&only_with_tag=csl-arm-branch&r1=1.563.4.2&r2=1.563.4.3
2.        t-linux.diff
http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff
3.        ioperm.c.diff
http://frank.harvard.edu/~coldwell/toolchain/ioperm.c.diff
2.     Build Variables
During the building of the cross-compile chain, you will need to set a few variables dependent on your particular needs.
echo "export PREFIX=/usr/arm" >> /etc/bash/bashrc
echo "export TARGET=arm-linux" >> /etc/bash/bashrc
echo "export HOST=i686-pc-linux-gnu" >> /etc/bash/bashrc
echo "export PATH=$PATH:/usr/arm/bin" >> /etc/bash/bashrc
Finally, to have the environment fully prepared for building the tools, source the profile:
source /etc/bash/bashrc
Build the source directory, which stores all the source codes.
mkdir -p ${PREFIX}/src
3.     GNU binutils
The Binutils package contains a linker, an assembler, and other tools for handling object files.
cd ${PREFIX}/src
tar xjf binutils-2.16.1.tar.bz2
mkdir -p BUILD/binutils-2.16.1
cd BUILD/binutils-2.16.1
../../binutils-2.16.1/configure --prefix=${PREFIX} –host=${HOST} /
--target=${TARGET} --disable-nls
The meaning of the configure options:
l         --prefix=${PREFIX}
This tells the configure script to prepare to install the package in the ${PREFIX} directory
l         --host=${HOST}
When used with --target, this creates a cross-architecture executable that creates files for ${TARGET} but runs on ${HOST).
l         --target=${TARGET}
When used with --host, this creates a cross-architecture executable that creates files for ${TARGET} but runs on ${HOST).
l         --disable-nls
This disables internationalization as i18n is not needed for the cross-compile tools.
Compile the package:
make
Install the package:
make install
4.     Linux Kernel Headers
The GNU C Library cannot be built without the Linux kernel headers. Most C library functions are implemented using system calls, and the kernel headers define the system call interface. The headers come with the kernel source.
cd ${PREFIX}/src
tar xjf linux-2.6.15.tar.gz
mkdir –p ${PREFIX}/${TARGET}/include
cd linux-2.6.15
According to the destination board, we use the default configuration of s3c2410.
cp arch/arm/configs/s3c2410_defconfig ./.config
make ARCH=arm menuconfig
Generate “version.h”
make include/linux/version.h
Copy the headers to the destined directory
cp –dR include/linux ${PREFIX}/${TARGET}/include/linux
cp –dR include/asm-arm ${PREFIX}/${TARGET}/include/asm
cp –dR include/asm-generic ${PREFIX}/${TARGET}/include/asm-generic
Copy the headers to the destined directory
cd ${PREFIX}/${TARGET}
ln –s include sys-include
5.     Glibc headers
cd ${PREFIX}/src
tar xjf glibc-2.3.5.tar.bz2
patch -d glibc-2.3.5 -p1 <ioperm.c.diff
cd glibc-2.3.5
tar xjf ../glibc-linuxthreads-2.3.5.tar.bz2
cd ..
mkdir -p BUILD/glibc-2.3.5-headers
cd BUILD/glibc-2.3.5-headers
../../glibc-2.3.5/configure --prefix=${PREFIX} --host=${TARGET} /
--build=${HOST} --with-headers=${PREFIX}/${TARGET}/include /
--enable-kernel=2.6.0
The meaning of the configure options:
l         --prefix=${PREFIX}
This tells the configure script to prepare to install the package in the ${PREFIX} directory
l         --host=${HOST}
When used with --build, this creates a cross-architecture executable that creates files for ${TARGET} but runs on ${HOST).
l         --build=${LFS_HOST}
When used with --host, this creates a cross-architecture executable that creates files for ${TARGET} but runs on ${HOST).
l         --enable-kernel=2.6.0
This tells Glibc to compile the library with support for 2.6.x Linux kernels.
l         --with-headers=${PREFIX}/${TARGET}/include
This tells Glibc to compile itself against the headers recently installed to the ${PREFIX} directory, so that it knows exactly what features the kernel has and can optimize itself accordingly.
Now, install the headers:
make cross-compiling=yes install-headers
Two files aren't installed by the above command, so copy the additional header files that are needed:
First copy a common file over to /tools/include:
cp -v bits/stdio_lim.h $PREFIX/include/bits
Now create a blank stub file:
touch $PREFIX/include/gnu/stubs.h
Move the headers to ${PREFIX}/${TARGET}/include
cd ${PREFIX}/include
mv * ../${TARGET}/include
cd ../${TARGET}
6.     GCC-Stage1
cd ${PREFIX}/src
tar xjf gcc-core-3.4.5.tar.bz2
patch -d gcc-core-3.4.5 -p1 < flow.c.diff
patch -d gcc-core-3.4.5 -p1 < t-linux.diff
mkdir -p BUILD/gcc-3.4.5-stage1
cd BUILD/gcc-3.4.5-stage1
../../gcc-core-3.4.5/configure --prefix=${PREFIX}/
--target=${TARGET} --enable-languages=c /
--with-headers=${PREFIX}/TARGET/include /
--disable-nls --disable-shared --disable-threads
The meaning of the configure options:
l         --prefix=${PREFIX}
This tells the configure script to prepare to install the package in the ${PREFIX} directory
l         --disable-shared
Disables the creation of the shared libraries.
l         --disable-threads
This will prevent GCC from finding the multi-thread include files, since they haven't been created for this architecture yet. GCC will be able to find the multi-thread information after the Glibc headers are created.
l         --enable-languages=c
This option ensures that only the C compiler is built.
Compile and install the package:
make && make install
7.     GNU C Library
Patch glibc source
File location:
glibc-2.3.5/Makeconfig
From:
libgcc_eh := -lgcc_eh $(libunwind)
To:
libgcc_eh := $(libunwind)
From:
static-gnulib := -lgcc -lgcc_eh $(libunwind)
To:
static-gnulib := -lgcc $(libunwind)
 
cd ${PREFIX}/src
mkdir -p BUILD/glibc-2.3.5
cd BUILD/glibc-2.3.5
BUILD_CC=gcc CC=${TARGET}-gcc AR=${TARGET}-ar /
RANLIB=${TARGET}-ranlib AS=${TARGET}-as LD=${TARGET}-ld /
../../glibc-2.3.5/configure ${TARGET} /
--prefix=${PREFIX}/${TARGET} --build=${HOST} /
--host=${TARGET} --enable-add-ons=linuxthreads /
--enable-shared --with-headers=${PREFIX}/${TARGET}/include /
--enable-kernel=2.6.0
The meaning of the configure options:
l         BUILD_CC="gcc"
This sets Glibc to use the current compiler on our system. This is used to create the tools Glibc uses during its build.
l         CC="${LFS_TARGET}-gcc"
This forces Glibc to use the GCC compiler that we made for our target architecture.
l         AR="${LFS_TARGET}-ar"
This forces Glibc to use the ar utility we made for our target architecture.
l         RANLIB="${LFS_TARGET}-ranlib"
This forces Glibc to use the ranlib utility we made for our target architecture.
l         --enable-add-ons=linuxthreads
This tells Glibc to utilize the linuxthreads add-ons.
Compile and install the package:
make && make install
8.     GCC-Stage2
cd ${PREFIX}/src
tar xjf gcc-3.4.5.tar.bz2
patch -d gcc-3.4.5 -p1 < flow.c.diff
mkdir -p BUILD/gcc-3.4.5-stage2
cd BUILD/gcc-3.4.5-stage2
../../gcc-3.4.5/configure --prefix=${PREFIX} --target=${TARGET}
--with-local-prefix=${PREFIX}/${TARGET} --disable-nls --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-c99 --enable-_cxa_atexit --enable-long-long
The meaning of the configure options:
l         --enable-languages=c,c++
This option ensures that only the C and C++ compilers are built.
l         --enable-__cxa_atexit
This option allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects and is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions.
l         --enable-c99
Enable C99 support for C programs.
l         --enable-long-long
Enables long long support in the compiler.
l         --enable-threads=posix
This enables C++ exception handling for multi-threaded code.
Compile and install the package:
make && make install
9.     References
1.        Building a GNU/Linux ARM Toolchain (from scratch)
Author: Charles M. "Chip" Coldwell
http://frank.harvard.edu/~coldwell/toolchain/
2.        Compile cross-compiler gcc-3.4.3 wth glibc-2.3.4 for ARM(920, v4) platform mini howto
Author: Andylin (andylin@wellsyn.com)
3.        Cross-Compiled Linux From Scratch - Version CLFS-SVN-20060407-x86

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值