Pages

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 

12 comments:

  1. This comment has been removed by the author.

    ReplyDelete


  2. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.

    angularjs Training in bangalore

    angularjs Training in electronic-city

    angularjs Training in online

    angularjs Training in marathahalli

    ReplyDelete
  3. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    blueprism training in chennai | blueprism training in bangalore | blueprism training in pune | blueprism online training

    ReplyDelete
  4. I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
    Java training in Marathahalli | Java training in Btm layout

    Java training in Jaya nagar | Java training in Electronic city

    ReplyDelete
  5. You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.
    Data Science training in kalyan nagar | Data Science training in OMR

    Data Science training in chennai | Data science training in velachery

    Data science training in tambaram | Data science training in jaya nagar

    ReplyDelete
  6. I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  7. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  8. It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
    Data science Course Training in Chennai |Best Data Science Training Institute in Chennai
    matlab training chennai | Matlab course in chennai

    ReplyDelete
  9. I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.
    MCSE Training in chennai | mcse training class chennai


    ReplyDelete