论文网
教师招聘网
万事OK网
发表论文
 
 首页 > IT文章 > 程序设计 >
从头设置ARM交叉编译工具链

[科技论文网] http://www.scipapers.com    2007-11-13  

    从头设置ARM交叉编译工具链

    Building a GNU/Linux ARM Toolchain (from scratch)

    Charles M. "Chip" Coldwell

    This article describes the steps necessary to build a cross-compiler toolchain for targeting ARM processors from an i386 workstation running the GNU/Linux operating system. The procedure described can be run automatically using a shell script, or you can just download the RPMs from the table below. Those interested in what's going on under the hood should read on.

    PackageBinarySource
    GNU Binutils arm-binutils-2.16-1.i386.rpm arm-binutils-2.16-1.src.rpm
    GNU Compiler Collection arm-gcc-3.4.4-1.i386.rpm arm-gcc-3.4.4-1.src.rpm
    GNU C Library arm-glibc-2.3.5-1.i386.rpm arm-glibc-2.3.5-1.src.rpm
    Linux Kernel arm-kernel-2.6.10-1.i386.rpm arm-kernel-2.6.10-1.src.rpm

    N.B., These RPMs were built on Red Hat Desktop v.3

    N.B., because of the bootstrapping problem described below, building any one of the gcc, glibc or kernel RPMs from the corresponding source RPM requires installing the other two binary RPMs. The only way to build the whole set from scratch is to use the shell script.

    N.B., this procedure builds a little-endian toolchain. Follow the link to learn why big-endianness is wrong.

    The files are installed in the directory /usr/arm. The build process described here assumes that all work is being done under this directory. This means that you must have read, write and execute permissions on this directory and all subdirectories and files contained therein to proceed. Probably that means you must be root.

    There's a bootstrapping problem that requires some of the components to be built twice. Briefly, the problem is that building the C cross-compiler requires having the ARM GNU C Library, but of course, building the ARM GNU C Library requires a C cross-compiler. The solution to this circular dependency is to first install the GNU C library headers, then build the C compiler without the C Library, use it to build the C library, then rebuild the full set of GNU compilers. Lather, rinse, repeat.

    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, of course, but the source must be patched and configured for the ARM architecture before they can be used to build the C library.

    Setup

    To start out, set up some variables and create the toplevel ARM directory and the source subdirectory. Also, make sure that the utilties we build will be on your PATH after they are installed.

      TARGET=arm-unknown-linux-gnu  PREFIX=/usr/arm  SYSROOT=${PREFIX}/sysroot  export ARCH=arm  export CROSS_COMPILE=${TARGET}-  export PATH=$PATH:${PREFIX}/bin  mkdir -p ${PREFIX}/src  

    Get the sources

    The versions chosen are not necessarily the most recent, but they do seem to work together with a minimum of patching. The last two files are only necessary if you are targeting the Atmel AT91RM9200 CPU.

      cd ${PREFIX}/src  for URL in \  http://ftp.gnu.org/gnu/binutils/binutils-2.16.tar.gz \  http://ftp.gnu.org/gnu/gcc/gcc-3.4.4/gcc-3.4.4.tar.bz2 \  "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" \  http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff \  http://ftp.gnu.org/gnu/glibc/glibc-2.3.5.tar.gz \  http://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.5.tar.gz \  http://frank.harvard.edu/~coldwell/toolchain/ioperm.c.diff \  http://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.10.tar.gz \  http://maxim.org.za/AT91RM9200/2.6/2.6.10-at91.patch.gz \  http://maxim.org.za/AT91RM9200/2.6/26_at91_serial.c.gz  do      FILE=${URL##*/}      FILE=${FILE%%\?*}      [ -f ${FILE} ] || wget -O ${FILE} ${URL}   done  

    GNU binutils

    These utilities (as, ar, ranlib, ld, etc.) are a prerequisite for building even the runt C compiler. In fact, many of the phases of compilation are accomplished by explicitly invoking some of these utilities (e.g as or ld).

    Fortunately, setting up the GNU binutils for targeting the ARM architecture is very straightforward:

      cd ${PREFIX}/src  tar xvfz 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} 2>&1 | tee configure.out  make 2>&1 | tee make.out  make install 2>&1 | tee -a make.out  

    Linux Kernel Headers

    In this step, the Linux kernel headers are installed in the SYSROOT directory. In the example below, the kernel is configured for the AT91RM9200 processor; default configurations for other processors are available in the linux-2.6.10/arch/arm/configs directory. Two patches are applied to the kernel source in order to build for the AT91RM9200; if this isn't your target CPU these patches are optional/irrelevant/harmless.

      cd ${PREFIX}/src  tar xvfz linux-2.6.10.tar.gz  ln -s linux-2.6.10 linux  zcat 2.6.10-at91.patch.gz | patch -d linux -p1  zcat 26_at91_serial.c.gz >linux/drivers/serial/at91_serial.c  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  

    Glibc headers

    This step installs the header files that come with glibc. Two of them are generated during the glibc build, which we don't do until later on. Fortunately, it is sufficient to substitute empty files.

      cd ${PREFIX}/src  tar xvfz glibc-2.3.5.tar.gz  patch -d glibc-2.3.5 -p1 <ioperm.c.diff  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 2>&1 | tee configure.out  make cross-compiling=yes install_root=${SYSROOT} install-headers 2>&1 | tee make.out  touch ${SYSROOT}/usr/include/gnu/stubs.h  touch ${SYSROOT}/usr/include/bits/stdio_lim.h  

    Stage 1 GCC

    Here we apply two patches to the GCC source. The first one forces the build process to generate the C Run Time files crti.o and crtn.o, which are needed later in the gcc build process. The second one fixes a bug that would otherwise cause an internal compiler error (ICE) during the glibc build process.

      cd ${PREFIX}/src  bunzip2 -c gcc-3.4.4.tar.bz2 | tar xvf -  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} 2>&1 | tee configure.out  make 2>&1 | tee make.out  make install 2>&1 | tee -a make.out  

    GNU C Library

    Glibc builds without any patching, provided you use the right configure switches.

      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 2>&1 | tee configure.out  make 2>&1 | tee make.out  make install_root=${SYSROOT} install  

    Stage 2 GCC

    Now rebuild gcc again, using the GNU C Library we just built.

      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 --with-sysroot=${SYSROOT} 2>&1 | tee configure.out  make 2>&1 | tee make.out  make install 2>&1 | tee -a make.out  

    Linux Kernel Image

    Finally, build a Linux kernel that can be used to boot the target.

      cd ${PREFIX}/src/linux  make zImage  make modules  make INSTALL_MOD_PATH=${SYSROOT} modules_install     

    The kernel will be in arch/arm/boot/zImage and the corresponding loadable modules will be installed /usr/arm/sysroot/lib/modules/[kernel-version]. Note that the directory /usr/arm/sysroot has been set that it is suitable for NFS export as a root filesystem for the target system.

    Resources

        来源:

声明:本文由网友推荐或作者提交,版权归原作者所有,刊登此文仅为传播知识,展示研究成果,提高文章引用率。未经原作者授权,禁止用于任何形式的商业行为。科技论文网倡导尊重知识、尊重劳动、保护原创、知识共享。由于部分论文文章来于网络,文章作者不祥,请相关的原创作者与我们联系,以便加上您的署名。

  
从头设置ARM交叉编译工具链
ARM C嵌入式编程     vivi开发笔记: MMU分析
最新论文
·[程序设计]嵌入式linux启动信息完全注释
·[程序设计]Linux2.6 启动传递命令行分析
·[程序设计]用systemtap研究内核
·[程序设计]Linux2.6内核epoll 网络编程
·[程序设计]Linux2.6下ESP包解析流程
·[程序设计]进程间通信的11种方法
·[程序设计]linux进程间通信总结
·[程序设计]Linux下select调用的过程
·[程序设计]Linux下多进程编程详细解析
·[程序设计]Linux 计时概要
 
 

搜索论文

Google
论文分类

 免费发布论文    中国论文网 2008版权所有  业务联系:pinjiao@126.com