Building your own toolchain

Source: Internet
Author: User
Tags gmp
Building your own toolchain
Contents

[Hide]

  • 1
    Selecting the right hardware

    • 1.1
      ARM 7
    • 1.2
      ARM 9
    • 1.3
      Arm 11
  • 2
    Steps of cross compilation
  • 3
    Specifing target for your toolchain

    • 3.1
      Eabi target
  • 4
    Setting Up Build Environment.
  • 5
    Scripts

    • 5.1
      Configure default settings for the toolchain
    • 5.2
      Scripts for compiling toolchain
Selecting the right hardware

Before you build your toolchain, you shoshould know which architecture you are building the toolchain. though the code generated wowould execute perfectly irrespective of the ARM architecture, you wocould not be able to take advantage of the features specific
To that architecture because of slight difference in
Instruction set.

Let us consider arbitrary e.g. Of a chip which does not have math co-processor.

So a simple instruction in C like

x=y*z 

Wocould translate in assembly language

loop:add y to itselfdnz z, loop

If you are multiplying 10*100, the loop wocould run for 100 times. Just imagine what wowould happen for floating point arithmetics.

If the chip has math co-processor, the compiler wowould generate

mul y,z

Which wowould possibly take just 1 machine cycle.

ARM 7
  • ARM7 + thumb + debug + multiplier + ice
  • This generation introduced the thumb 16 bit Instruction Set

Some famous gadget built on ARM 7 series.

  • Audio Controller in the Sega Dreamcast
  • Dlink dsl604 + wireless ADSL Router.
  • Ipod, iriver
  • Most of Nokia's mobile phone range.
ARM 9
  • Arm moved from a Von norann architecture (Princeton architecture) to a Harvard architecture with separate instruction and Data Bus (and caches), significantly increasing its potential speed.
  • Most important change was introduction of MMU, POSIX compliant OS cocould be ported.

All smart phones are based on ARM 9 architecture.

Arm 11
  • SIMD instructions which can double MPEG4 and Audio Digital Signal Processing Algorithm speed
  • Cache is physically addressed, solving implements cache aliasing problems and bridging context switch overhead.
  • Ti omap2 series Processors.
  • All touch based smart phones

Code cross-complied on ARM 7 toolchain wocould run perfectly on ARM 9 or arm 11 processors, but then you won't be able to utilize hardware features implemented by those ubuntures. hence it is important that you build your toolchain for correct architecture.

Steps of cross compilation
  • GCC: run the cross-compiler on the host machine to produce runner er files for the target machine.
  • As: assemble the files produced by the cross-compiler.
  • Ld: link those files to make an executable. You can do this either with a linker on the target machine, or with a cross-linker on the host machine.
Specifing target for your toolchain
  • Arm-Linux: Generic ARM processor
  • Armv4l: This makes support for the arm V4 architecture, as used in the Strongarm, ARM7TDMI, ARM9.
  • Armv5l: This makes support for the arm V5 architecture, as used in the XScale and arm11.
Eabi target

You wowould most likely want to use build your toolchain compliant
Eabi standards. Eabi is like POSIX standard for cross-compilers.

Eabi target

* arm-none-gnueabi: this is the name as arm none-eabi (specific to GNU compiler)* arm-unknown-eabi: bare metal * arm-linux-eabi: Designed to be used to build programs with glibc under a Linux environment.  This would what you would use to build programs for an  embedded device running on Linux OS.

Setting Up Build Environment.
  • Preferably use virtual box/Vmware
  • Create a new user for the installation.
  • Set up the configure parameters in the. Profile
  • Create separate dir for build and source.
  • Set prefix dir. it is very important that the directory shocould be anything apart from your/usr/bin directory. the output of our activity wocould generate binaries for ARM processor. now these wowould have same name as that of your x86 binaries. so if you specify
    /Usr/bin directory all your existing binary wocould be replaced by arm ELF binary and then you won't be able to run a single application on your machine.
Scripts configure default settings for the toolchain

Copy this in your ~ /. Bashrc file.

  1. LFS is the root directory for your installation.
export LFS=/mnt/lfsexport TARGET=arm-none-eabiexport PREFIX=/usr/armexport PATH=$PATH:$PREFIX/binexport PATH=$PATH:$PREFIX/libexport TOOLPATH=$PREFIX
Scripts for compiling toolchain
 #!/bin/bash cd $LFS/source #get the source code for bin utils wget -c http://ftp.gnu.org/gnu/binutils/binutils-2.20.tar.bz2 $LFS/source  #get the source code for gmp: required for multi precision wget -c ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.bz2  #get the source code for gmp: required for mpfr wget -c http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2   #get the source code for gcc wget -c  http://ftp.gnu.org/gnu/gcc/gcc-4.4.3/gcc-4.4.3.tar.bz2  #get newlib wget -c ftp://sources.redhat.com/pub/newlib/newlib-1.18.0.tar.gz   # 1. Install binutils , extarct tar file. Run configure, make, make install tar -xjf $LFS/source/binutils-2.20.tar.bz2  cd binutils-2.20 ./configure --target=$TARGET --prefix=$PREFIX --enable-interwork --enable-multilib --disable-nls --disable-werror make sudo make install  # 2. Install gcc dependancies:  #  2.1 Install gmp #  2.2 Install MFPR #  2.3 Install mpc if required   #    2.1 Install gmp cd  $LFS/build/source tar -xjf $LFS/source/gmp-5.0.1.tar.bz2 mkdir $LFS/build/gmp build all the sources from the build directory and not the source directory cd $LFS/build/gmp  # run this command if error for "checking for suitable m4... configure: error: No usable m4 in $PATH or" # sudo aptitude install build-essential m4 $LFS/source/gmp-5.0.1/configure --prefix=$PREFIX  #Tue Sep  7 13:36:14 IST 2010 make sudo make install   #  2.2 Install MFPR cd  $LFS/source tar -xjf $LFS/source/mpfr-2.4.2.tar.bz2 mkdir $LFS/build/mpfr cd  $LFS/build/mpfr  $LFS/source/mpfr-2.4.2/configure --prefix=$PREFIX --with-gmp=$PREFIX  make  # Tue Sep  7 14:22:08 IST 2010 sudo make install  

This is probably the trickiest stage to get right. there are a few factors to consider: Do you have a fully-working and installed version of glibc for the same abi (I. e. selection of binary format, processor type, etc .) as that for which you are building
GCC? If this is your first time building a cross compiler, then the answer is almost certainly no. if this is not your first time building, and you built glibc previusly, in the same format as you're using for GCC now, then the answer might be yes. if the answer
Is no, then you cannot build support for any language than C, because all the other front-ends depend on libc (I. e. the final GCC binary wowould would keep CT to link with libc) If this is your category, then you must append ages = "C" to each make command line
Inside GCC.

 #  3 Installation of gcc first pass cd  $LFS/source tar -xjf $LFS/source/gcc-4.4.3.tar.bz2 mkdir $LFS/build/gcc cd  $LFS/build/gcc  $LFS/source/gcc-4.4.3/configure --target=$TARGET --prefix=$PREFIX --enable-interwork --enable-multilib --enable-languages="c" --with-newlib --without-headers --disable-shared --with-gmp=$PREFIX --with-mpfr=$PREFIX  make all-gcc   # Tue Sep  7 17:54:37 IST 2010 sudo make install-gcc    #    4 Installation of newlib cd  $LFS/source tar -xzf $LFS/source/newlib-1.18.0.tar.gz mkdir $LFS/build/newlib cd  $LFS/build/newlib  $LFS/source/newlib-1.18.0/configure --target=$TARGET --prefix=$PREFIX --enable-interwork --enable-multilib  --disable-nls --disable-newlib-supplied-syscalls  --with-gmp=$PREFIX/lib --with-mpfr=$PREFIX # in case there is a makeinfo error run this command. delete the makefile and run configuration againg # sudo apt-get install texinfo  # In case of arm-none-eabi-cc error create a softlink for arm-none-eabi-gcc # In case of libgmp.so.10 error, create a softlink in /usr/lib directory  make  # Thu Sep  9 00:01:39 IST 2010 sudo make install  cd $LFS/build/gcc $LFS/source/gcc-4.4.3/configure --target=$TARGET --prefix=$PREFIX --enable-interwork --enable-multilib --enable-languages="c" --with-newlib --without-headers --disable-shared --with-gmp=$PREFIX --with-mpfr=$PREFIX make sudo make install

Now link the path.

 # Thu Sep  9 05:04:51 IST 2010 sudo sh -c 'echo "/usr/arm/bin/" > /etc/paths.d/arm-none-eabi' sudo sh -cn 'echo "/usr/arm/share/man\n/usr/arm/man"> /etc/manpaths.d/arm-none-eabi'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.