In normally, if you want to development for an embedded-system with ARM cpu, you need a cross-compilation toolchain. There have three ways to obtain the toolchain :
External hyperlinks, like Python.
- Acquire toolchain from manufacturer of your evaluation-board.
- Acquire toolchain from third-party organization, just as :
- Compile your cross-compilation toolchain
The way 1 maybe the best choice if it fit for your requirement, because it has been well tested and stable enough for your development on specific board.
The way 2 sometimes may not fit for your kernel or source code. It could successfully finished your compilation that does not means it do not have any problems. This choice is for whom do not have much time to compile their toolchain and their probject must start immediately.
The way 3 maybe a better way to suit for your requirement, you could use the stable “linaro” version GCC, that version sometimes more stable than upstream. With this way you could use any version GCC you want and compile the toolchain with specific kernel source without any compatibility problems. Certainly this way do not have much test on your board, that’s the risk you have to afford.
How we compile our cross-compilation toolchain? You could compile the toolchain’s libraries, utilities one by one, but we introduce an easier way to achieve that: crosstool-ng.
Assume we are using Ubuntu 12.04
Assume we using user named “bob”
First we prepare the crosstool-ng running environment, we must have these utilities installed:
aptitude install bison flex texinfo automake libtool patch gcj-jre gcj-jdk gawk
We download crosstool-ng from http://crosstool-ng.org and decompress to home directory, now the decompressed crosstool-ng source code directory is “/home/bob/crosstool-ng-1.18.0”.
Enter the crosstool-ng source code directory, and execute these commands :
./configure -prefix=~/crosstool-ng make make install
After that, the crosstool-ng will be installed into directory “/home/bob/crosstool-ng”.
3 Start our journey!
3.1 Initialize default configuration
Enter samples directory in crosstool-ng source code directory :
Find out which toolchain you want to compile, we assume “arm-unknown-linux-gnueabi”.
Enter the directory :
You will see there have two files:
The crosstool.config is what we want! Copy it to the installed crosstool-ng directory and renamed to “.config” :
cp crosstool.config ~/crosstool-ng/.config
Ok, now we have the default configuration for our toolchains, those parameters in the configuration are been tested, so we need not to try our configuration again.
3.2 Modify configuration to fit for our requirement
Now we should do little modification to make the compiled toolchain fit for our requirement.
Enter the installed crosstool-ng directory :
cd ~/crosstool-ng ./ct-ng menuconfig
Go to option : Operating System —> Linux kernel version, You could specific your kernel version, if you have a custom modified kernel, you have to set it to “custom tarball or directory” and specific the custom directory to your kernel source tree directory, for example we specific it to “/home/bob/linux-126.96.36.199”.
Go to option : C compiler, enable “Show Linaro versions”, the linaro GCC versions are much stable , you have better use that one.
You have better disable Fortran and Java compilation, they will cause much complications.
You have to check other options to fit for you embedded board .
After all configuration done, we now go for our long trip :
All needed packages will be download to “~/src”, so you need to keep connection to internet.
But during compile process, may be have some issues:
Sometimes ct-ng will download some packages with *.tar.lzma, but the ct-ng can’t recognize those format and failed to unpack lead build process stopped, so you need to download the *.tar.gz of specific package and put it into ~/src. For example :
If build faild to unpack expat-2.1.0.tar.lzma, you will see there have a file named “expat-2.1.0.tar.lzma” in ~/src, so you have to download expat-2.1.0.tar.gz manuall from expat’s offical website and put it into ~/src and delete the expat-2.1.0.tar.lzma.
After success builded, the whole toolchain will be put into ~/x-tools, that’s what you want.