[3mdeb blog]

Thoughts dereferenced from scratchpad noise

0x2: Toolchain for Virtual Development Board

| Comments

Table of contents


This is probably the most complicated topic of all related to embedded development but we need to deal with it at the beginning. I read a lot about toolchains but still don’t know enough to explain details. I think that best answers are in crosstool-ng documentation.

What is toolchain ?

Toolchain as the name said is a set of tools chained together, so output of one tool is the input for different tool. This is well known concept in Linux (eg. pipes). In embedded environment toolchain is called cross-toolchain or cross-compiler, because usually it compiles on one architecture and generate code for another (eg. it compiles on x86 and generate code for arm)[1].

Why we need cross-toolchain ?

I suspect that your laptop/PC is not based on ARM processor, most probably it based on x86 architecture so you cannot simply compile code and run it in our virtual-arm-based environment. To prepare operating system and tools for it we need cross-toolchain.

How to create toolchain ?

Process of creating cross-toolchain from scratch is not easy and takes some time. There are few other ways to get toolchain, than creating it from scratch. First we can use prebuilt toolchain providers like: CodeSourcery, Linaro, DENX EDLK or Emdebian. Second we can create toolchain using special building system like: Buildroot, Crosstool-NG or Bitbake. I will not deal with preparing toolchain in this series because procedure for creating it takes pretty long. So we have two options:

Emdebian path

Add below lines to you /etc/apt/sources.list:

deb http://ftp.uk.debian.org/emdebian/toolchains unstable main

Install Emdebian keys, update and install cross-compiler with all related packages:

sudo apt-get install emdebian-archive-keyring
sudo apt-get update
sudo apt-get install gcc-4.7-arm-linux-gnueabi
Dependency problems during installation

If above attempt to install cross-compiler ends with:

pietrushnic@eglarest:~/src$ sudo apt-get install gcc-4.7-arm-linux-gnueabi
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-4.7-arm-linux-gnueabi : Depends: libgomp1-armel-cross (>= 4.7.2-5) but it
 is not going to be installed
 E: Unable to correct problems, you have held broken packages.

This means that Debian ustable cross-compiler is not available for you configuration. You can read more about that here. To fix that issue simply change emdebian toochain repository to testing in /etc/apt/source.list:

deb http://ftp.uk.debian.org/emdebian/toolchains testing main
Emdebian toolchain configuration

Check where arm-linux-eabi-gcc-4.7 was installed:

whereis arm-linux-gnueabi-gcc-4.7
arm-linux-gnueabi-gcc-4: /usr/bin/arm-linux-gnueabi-gcc-4.7 /usr/bin/X11/arm-linux-gnueabi-gcc-4.7

It is not linked to arm-linux-gnueabi-gcc, so we cannot give its prefix as CROSS_COMPILE variable value, which is needed for bootloader and kernel compilation. We have to link it to arm-linux-gnueabi-gcc:

sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-4.7 /usr/bin/arm-linux-gnueabi-gcc

Toolchain is ready to use.

Note: I tried CodeSourcery toolchain arm-2012.09-64-arm-none-linux-gnueabi.bin, but it contain binutils defect that not allow correctly build kernel. If you see something like this in log:

Error: selected processor does not support ARM mode `ldralt lr,[r1],#4'

That means you experience same thing, please use Emdebian or Crosstool-NG toolchain.

Note 2: If you’re Ubuntu user I have to suggest experiments with toolchain build by your own, because I get really hard times trying to go through this tutorial with Ubuntu/Linaro cross compiler provided in repository. Finally I used this to push things forward. U-boot compiled with Ubuntu/Linaro toolchain had problem with __udivsi3 instruction. This cause loop in initialization process.


If you take effort of creating toolchain using Crosstool-NG than congratulations. But for simplifying whole Virtual Development Board series I will use Emdebian toolchain in further posts. Of course you can use your brand new Crosstool-NG toolchain by simply remember that tools prefixes are different. Emdebian uses arm-linux-gnueabi- and Crosstool-NG was created with arm-unknown-linux-gnueabi-. Replace one with another every time when needed. In next post we will deal with bootloader.


[1] Toolchains