Difference between revisions of "Toolchain"

From MILEDROPEDIA
Jump to: navigation, search
(Prebuilt toolchain)
m
 
(6 intermediate revisions by the same user not shown)
Line 17: Line 17:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
make mapphone_defconfig
 
make mapphone_defconfig
make headers_install ARCH=arm INSTALL_HDR_PATH=~/build/kern_h/
+
make headers_install ARCH=arm INSTALL_HDR_PATH=~/cross/kern_h/
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
and then you need pack this '''kern_h''' directory in tar.gz  because in crosstool config we have this option.
 
You must know, what proccessor chip you have on target device, and set optimisation options  
 
You must know, what proccessor chip you have on target device, and set optimisation options  
from (http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/ARM-Options.html#ARM-Options)
+
from [http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/ARM-Options.html#ARM-Options]
For example, if you have Motorola Milestone - so processor chip is TI OMAP3430 - ARM Cortex a8 (armv7a arch)
+
For our case, we have Motorola Milestone - so processor chip is TI OMAP3430 - ARM Cortex a8 (armv7a arch)
(http://en.wikipedia.org/wiki/ARM_architecture)
+
[http://en.wikipedia.org/wiki/ARM_architecture]
So you need use configs with -omap3430 suffix.
+
  
Also, I recommend use kernel-...configs instead of XVilka-...configs for creating toolchain for kernel building and hacking.
+
[[File:omap3430-milestone.tar.bz2 | Toolchain build configs for Milestone OMAP3430]]
  
 
Set enviroment variable for building options:
 
Set enviroment variable for building options:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
export _XXCFLAGS=" -march=armv7-a -mtune=cortex-a8 -mfpu=neon" (if you have Milestone/Droid or other device on TI OMAP3430)
 
export _XXCFLAGS=" -march=armv7-a -mtune=cortex-a8 -mfpu=neon" (if you have Milestone/Droid or other device on TI OMAP3430)
export _XXCFLAGS=" -march=armv6j -mtune=arm1136jf-s" (if you have HTC Hero or other device on Quallcomm MSM 7200A)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
2. Download crosstool-ng (http://ymorin.is-a-geek.org/dokuwiki/projects/crosstool),
+
2. Download crosstool-ng (http://crosstool-ng.org/),
 
Unpack, build (you need for: make,install,bash,cut,sed,grep,gcc,awk,bison,flex,automake,libtool,stat,
 
Unpack, build (you need for: make,install,bash,cut,sed,grep,gcc,awk,bison,flex,automake,libtool,stat,
 
wget,cvs,patch,tar,gzip,bzip2,lzma,readlink,ncurses, mpfr-dev, gmp-dev)
 
wget,cvs,patch,tar,gzip,bzip2,lzma,readlink,ncurses, mpfr-dev, gmp-dev)
Line 41: Line 40:
 
make install
 
make install
 
</syntaxhighlight>
 
</syntaxhighlight>
3. Create dir toolchain-android, cd to it and copy files:
+
 
XVilka-crosstool-<suffix>.config in .config
+
3. Create dir toolchain-android, cd to it and copy file:
XVilka-uClibc-<suffix>.config in uClibc-0.9.30.2.config
+
'''crosstool-<suffix>.config''' in '''.config'''
 
and then run:  
 
and then run:  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 54: Line 53:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
4. Done! We have toolchain in build/x-tools.  
+
4. Done! We have toolchain in cross/x-tools.  
 
All tools have this triplet: arm-android-linux-uclibsgnueabi-*
 
All tools have this triplet: arm-android-linux-uclibsgnueabi-*
 
just add them in PATH
 
just add them in PATH
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
export PATH=$HOME/build/x-tools/arm-android-linux-uclibcgnueabi/bin:$PATH
+
export PATH=$HOME/cross/x-tools/arm-android-linux-uclibcgnueabi/bin:$PATH
 
export CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
 
export CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
 
export KERNEL_CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
 
export KERNEL_CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
 
</syntaxhighlight>
 
</syntaxhighlight>
 
So we can run '''arm-android-linux-uclibcgnueabi-gcc'''
 
So we can run '''arm-android-linux-uclibcgnueabi-gcc'''
Also we have system root directory in: '''~/build/x-tools/arm-android-linux-uclibcgnueabi/arm-android-linux-uclibcgnueabi/sys-root'''
+
Also we have system root directory in: '''~/cross/x-tools/arm-android-linux-uclibcgnueabi/arm-android-linux-uclibcgnueabi/sys-root'''
For some reasons we just copy it in '''~/build/cross/sys-root'''
+
For some reasons we just copy it in '''~/cross/sys-root'''
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
chmod +w sys-root
 
chmod +w sys-root
Line 87: Line 86:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Download latest release of dietlibc (http://www.fefe.de/dietlibc/) from cvs:
 
Download latest release of dietlibc (http://www.fefe.de/dietlibc/) from cvs:
<syntaxhiglight lang="bash">
+
<syntaxhighlight lang="bash">
 
cvs -d :pserver:cvs@cvs.fefe.de:/cvs -z9 co $HOME/build/dietlibc
 
cvs -d :pserver:cvs@cvs.fefe.de:/cvs -z9 co $HOME/build/dietlibc
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 08:57, 27 August 2013

Prebuilt toolchain

There're several options:

Assume you've chosen 1 since it is the best current option. After downloaded the toolchain to r:\prebuilt-*.tar.gz, execute:

tar xzf /mnt/r/prebuilt-*.tar.gz -C ~

A prebuilt folder will be created in user home.

Compiling your own toolchain from scratch

1. Download your device kernel, unpack this and create configs and headers:

make mapphone_defconfig
make headers_install ARCH=arm INSTALL_HDR_PATH=~/cross/kern_h/

and then you need pack this kern_h directory in tar.gz because in crosstool config we have this option. You must know, what proccessor chip you have on target device, and set optimisation options from [1] For our case, we have Motorola Milestone - so processor chip is TI OMAP3430 - ARM Cortex a8 (armv7a arch) [2]

File:Omap3430-milestone.tar.bz2

Set enviroment variable for building options:

export _XXCFLAGS=" -march=armv7-a -mtune=cortex-a8 -mfpu=neon" (if you have Milestone/Droid or other device on TI OMAP3430)

2. Download crosstool-ng (http://crosstool-ng.org/), Unpack, build (you need for: make,install,bash,cut,sed,grep,gcc,awk,bison,flex,automake,libtool,stat, wget,cvs,patch,tar,gzip,bzip2,lzma,readlink,ncurses, mpfr-dev, gmp-dev)

.configure
make
make install

3. Create dir toolchain-android, cd to it and copy file: crosstool-<suffix>.config in .config and then run:

ct-ng menuconfig

change anything, if you need, and save to .config then exec:

ct-ng build

4. Done! We have toolchain in cross/x-tools. All tools have this triplet: arm-android-linux-uclibsgnueabi-* just add them in PATH

export PATH=$HOME/cross/x-tools/arm-android-linux-uclibcgnueabi/bin:$PATH
export CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
export KERNEL_CROSS_COMPILE=arm-android-linux-uclibcgnueabi-

So we can run arm-android-linux-uclibcgnueabi-gcc Also we have system root directory in: ~/cross/x-tools/arm-android-linux-uclibcgnueabi/arm-android-linux-uclibcgnueabi/sys-root For some reasons we just copy it in ~/cross/sys-root

chmod +w sys-root
chmod +w sys-root/usr
chmod +w sys-root/usr/lib

Building and using tiny toolchain

For compiling some small hacking utility or kernel module you don need in whole gcc toolkit (more than 60 MB) and whole libc. So we need for something small and tiny. It can be tiny C compiler (tcc) and dietlibc You can download, unpack, copy bin files in /usr/local/bin, lib files in /usr/local/lib, tiny-root in $HOME/build. Link for downloading

If you want to know how i building it - read below:

For example we choose working directory as $HOME/build Download latest release of tiny C compiler (http://tinycc.org/) from git:

git clone git://repo.or.cz/tinycc.git $HOME/build/tinycc

Download latest release of dietlibc (http://www.fefe.de/dietlibc/) from cvs:

cvs -d :pserver:cvs@cvs.fefe.de:/cvs -z9 co $HOME/build/dietlibc

After this we need to build tcc:

cd $HOME/build/tinycc
./configure --enable-cross --prefix=$HOME/build/tiny-toolchain
make
make install

So we have this tools in $HOME/build/tiny-toolchain/bin:

arm-eabi-tcc
arm-fpa-ld-tcc
arm-fpa-tcc
arm-vfp-tcc
c67-tcc
i386-win32-tcc
tcc
x86_64-tcc
x86_64-win32-tcc

Add them in enviroment variable PATH for easy executing:

export PATH=$HOME/build/tiny-toolchain/bin:$PATH

But also we need a C library. So make the "target root" directory: <syntaxhiglight lang="bash"> mkdir $HOME/build/tiny-root </syntaxhighlight> Building dietlibc:

cd $HOME/build/dietlibc
make prefix=$HOME/build/tiny-root
make prefix=$HOME/build/tiny-root ARCH=arm CROSS=arm-android-linux-uclibcgnueabi-
make install-headers prefix=$HOME/build/tiny-root ARCH=arm CROSS=arm-android-linux-uclibcgnueabi-
make install-bin prefix=$HOME/build/tiny-root ARCH=arm CROSS=arm-android-linux-uclibcgnueabi-

Prepare "target root" directory:

ln -s $HOME/build/tiny-root/lib-arm $HOME/build/tiny-root/lib
cp $HOME/build/tiny-toolchain/include/* $HOME/build/tiny-root/include/
cp $HOME/build/tiny-toolchain/lib/* $HOME/build/tiny-root/lib/

Also, for kernel development we need for kernel headers:

cd /path/to/you/kernel/sources
make headers_install ARCH=arm INSTALL_HDR_PATH=$HOME/build/tiny-root/include

So, we have all needed libraries and headers in $HOME/build/tiny-root You can use tcc for compiling your small utilities, for example by this command:

arm-eabi-tcc -nostdinc -nostdlib -I$HOME/build/tiny-root/include -L$HOME/build/tiny-root/lib -o example example.c

Enjoy!