2014/12/10

How To Build GCC ARM Cross-Compiler for Xilinx ZYNQ on ZC702


Intro:
   In this How To we are going to build an ARM cross-compiler based upon GCC 4.8.2.
Since the original tool chain does not support OpenMP. I create my GCC to support OpenMP and Neon.
Reference from this.

Tar Balls:
   binutils-2.24.tar.bz2
   glibc-2.18.tar.gz
   gcc-4.8.2.tar.bz2
   gmp-4.3.2.tar.bz2
   mpfr-2.4.2.tar.bz2
   mpc-0.8.1.tar.gz
   xlnx-3.14  --> copy from /opt/pkg/petalinux-v2014.2-final/components/linux-kernel/xlnx-3.14

Create a Workspace:
$ export SRCDIR=~/workbench/gcc-4.8.2/xtools/src
$ mkdir -pv ~/workbench/gcc-4.8.2/xtools
$ mkdir $SRCDIR
$ cd $SRCDIR

Gather the Sources:
binutils
$ tar -pxzf binutils-2.24.tar.gz

glibc
$ tar -pxzf glibc-2.18.tar.gz

gcc
$ tar -pxjf gcc-4.8.2.tar.bz2
$ cd gcc-4.8.2
$ tar -pxjf ../gmp-4.3.2.tar.bz2
$ tar -pxjf ../mpfr-2.4.2.tar.bz2
$ tar -pxzf ../mpc-0.8.1.tar.gz
$ mv gmp-4.3.2/ gmp
$ mv mpfr-2.4.2/ mpfr
$ mv mpc-0.8.1/ mpc
$ cd $SRCDIR

kernel
copy from /opt/pkg/petalinux-v2014.2-final/components/linux-kernel/xlnx-3.14 to $SRCDIR/xlnx-3.14


Build Environment:
Build Environment save to file envsetting.sh
#!/bin/sh
export SRCDIR=~/workbench/gcc-4.8.2/xtools/src
export BINUTILS_SRC=$SRCDIR/binutils-2.24
export KERNEL_SRC=$SRCDIR/xlnx-3.14
export GCC_SRC=$SRCDIR/gcc-4.8.2
export GLIBC_SRC=$SRCDIR/glibc-2.18
export BUILDDIR=~/workbench/gcc-4.8.2/xtools/build
export TARGETMACH=arm-none-linux-gnueabi
export BUILDMACH=i686-pc-linux-gnu
export INSTALLDIR=~/workbench/gcc-4.8.2/arm
export SYSROOTDIR=$INSTALLDIR/sysroot

Build binutils:
$ mkdir $BUILDDIR
$ mkdir $BUILDDIR/binutils
$ cd $BUILDDIR/binutils
$ $BINUTILS_SRC/configure --disable-werror --build=$BUILDMACH --target=$TARGETMACH --prefix=$INSTALLDIR --with-sysroot=$SYSROOTDIR
$ make
$ make install

Kernel Headers:
$ cd ~/workbench/gcc-4.8.2/xtools/src/xlnx-3.14
$ make mrproper
$ make ARCH=arm xilinx_zynq_defconfig
$ mkdir -pv $INSTALLDIR/sysroot/usr
$ make ARCH=arm headers_check
$ make ARCH=arm INSTALL_HDR_PATH=$INSTALLDIR/sysroot/usr headers_install
$ cd $SRCDIR

Bootstrap gcc:
$ mkdir $BUILDDIR/bootstrap-gcc
$ cd $BUILDDIR/bootstrap-gcc
$ $GCC_SRC/configure --build=$BUILDMACH --host=$BUILDMACH --target=$TARGETMACH --prefix=$INSTALLDIR --without-headers --enable-boostrap --enable-languages="c" --disable-threads --enable-__cxa_atexit --disable-libmudflap --with-gnu-ld --with-gnu-as --disable-libssp --disable-libgomp --disable-nls --disable-shared --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=neon --with-float=hard
$ make all-gcc install-gcc
$ make all-target-libgcc install-target-libgcc
$ ln -s $INSTALLDIR/lib/gcc/arm-none-linux-gnueabi/4.8.2/libgcc.a $INSTALLDIR/lib/gcc/arm-none-linux-gnueabi/4.8.2/libgcc_sh.a
$ cd $SRCDIR

glibc Headers:
$ mkdir -pv $BUILDDIR/libc
$ cd $BUILDDIR/libc
$ echo "libc_cv_forced_unwind=yes" > config.cache
$ echo "libc_cv_c_cleanup=yes" >> config.cache
$ export PATH=$INSTALLDIR/bin:$PATH
$ export CROSS=arm-none-linux-gnueabi
$ export CC=${CROSS}-gcc
$ export LD=${CROSS}-ld
$ export AS=${CROSS}-as
$ $GLIBC_SRC/configure --build=$BUILDMACH --host=$TARGETMACH --prefix=$SYSROOTDIR/usr --with-headers=$SYSROOTDIR/usr/include --config-cache --enable-kernel=3.14
$ make -k install-headers cross_compiling=yes install_root=$SYSROOTDIR
 
*** We need to move some files ***
$ pushd $SYSROOTDIR/$INSTALLDIR/sysroot/usr/include
$ cp -rv * $SYSROOTDIR/usr/include/
$ popd
 
$ ln -s $INSTALLDIR/lib/gcc/arm-none-linux-gnueabi/4.8.2/libgcc.a $INSTALLDIR/lib/gcc/arm-none-linux-gnueabi/4.8.2/libgcc_eh.a
$ cd $SRCDIR

Building glibc:
$ rm -rf $BUILDDIR/libc
$ mkdir -pv $BUILDDIR/libc
$ cd $BUILDDIR/libc
$ echo "libc_cv_forced_unwind=yes" > config.cache
$ echo "libc_cv_c_cleanup=yes" >> config.cache
 
*** check to make sure these are still set, they should be ***
$ echo $PATH
$ echo $CROSS
$ echo $CC
 
$ $GLIBC_SRC/configure --build=$BUILDMACH --host=$TARGETMACH --prefix=/usr --with-headers=$SYSROOTDIR/usr/include --config-cache --enable-kernel=3.14
$ make -k install-headers cross_compiling=yes install_root=$SYSROOTDIR
$ ln -s $INSTALLDIR/lib/gcc/arm-none-linux-gnueabi/4.8.2/libgcc.a $INSTALLDIR/lib/gcc/arm-none-linux-gnueabi/4.8.2/libgcc_s.a
$ make
$ make install_root=$SYSROOTDIR install

Building The Next gcc:
*** unset CC, LD, and AS. We do not want to xcompile the xcompiler :-) ***
$ unset CC
$ unset LD
$ unset AS
 
*** delete gcc-x.x.x and re-install it ***
$ cd $SRCDIR
$ rm -rf gcc-4.8.2
$ tar -pxjf gcc-4.8.2.tar.bz2
$ cd gcc-4.8.2/
$ tar -pxjf ../gmp-4.3.2.tar.bz2
$ tar -pxjf ../mpfr-2.4.2.tar.bz2
$ tar -pxzf ../mpc-0.8.1.tar.gz
$ mv gmp-4.3.2/ gmp
$ mv mpfr-2.4.2/ mpfr
$ mv mpc-0.8.1/ mpc
$ mkdir -pv $BUILDDIR/final-gcc
$ cd $BUILDDIR/final-gcc
$ echo "libc_cv_forced_unwind=yes" > config.cache
$ echo "libc_cv_c_cleanup=yes" >> config.cache
$ BUILD_CC=gcc
$ $GCC_SRC/configure --build=$BUILDMACH --target=$TARGETMACH --prefix=$INSTALLDIR --with-sysroot=$SYSROOTDIR --enable-languages="c,c++" --with-gnu-as --with-gnu-ld --disable-multilib --disable-sjlj-exceptions --disable-nls --enable-threads=posix --enable-long-longx --enable-libgomp --disable-shared --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=neon --with-float=hard
$ make all-gcc
$ make install-gcc

Building The Final gcc:
*** make sure these are still unset ***
$ echo $CC
$ echo $LD
$ echo $AS
 
*** delete gcc-x.x.x and re-install it ***
$ cd $SRCDIR
$ rm -rf gcc-4.8.2
$ tar -pxjf gcc-4.8.2.tar.bz2
$ cd gcc-4.8.2/
$ tar -pxjf ../gmp-4.3.2.tar.bz2
$ tar -pxjf ../mpfr-2.4.2.tar.bz2
$ tar -pxzf ../mpc-0.8.1.tar.gz
$ mv gmp-4.3.2/ gmp
$ mv mpfr-2.4.2/ mpfr
$ mv mpc-0.8.1/ mpc
$ mkdir -pv $BUILDDIR/final-gcc-2
$ cd $BUILDDIR/final-gcc-2
$ echo "libc_cv_forced_unwind=yes" > config.cache
$ echo "libc_cv_c_cleanup=yes" >> config.cache
$ $GCC_SRC/configure --build=$BUILDMACH --target=$TARGETMACH --prefix=$INSTALLDIR --with-sysroot=$SYSROOTDIR --enable-languages="c,c++" --with-gnu-as --with-gnu-ld --disable-multilib --with-float=soft --disable-sjlj-exceptions --disable-nls --enable-threads=posix --disable-libmudflap --disable-libssp --enable-long-longx --enable-libgomp --with-shared --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=neon --with-float=hard
$ make
$ make install

Usage:
export INSTALLDIR=~/workbench/gcc-4.8.2/arm
export PATH=$INSTALLDIR/bin:$PATH
export TARGETMACH=arm-none-linux-gnueabi
export BUILDMACH=i686-pc-linux-gnu
export CROSS=arm-none-linux-gnueabi
export CC=${CROSS}-gcc
export LD=${CROSS}-ld
export AS=${CROSS}-as

Now compile your test program:
$CC -Wall -Wextra .c -o 

No comments:

Post a Comment