Lab2 - Cross Compilation for Beagle Board using ARM Toolchain

Objective: Learn how to compile your own cross-compiling toolchain for the uClibc C library.

    • After this lab, you will be able to
    • Configure the crosstool-ng tool Execute crosstool-ng, and
    • Build up your own cross-compiling toolchain


  1. Ubuntu 10.04 (Lucid Linux) as a virtual machine in VMware Server/Workstation.
  2. SD Card (Minimum 2 GB SD card required for later labs where you have to download linux kernel, Android, etc)
  3. If you are using a Laptop, then you need USB card reader (SD to USB)
  4. Vmware Player / Vmware Server [You can't access physical disks in VMware on Windows as a host machine. You can do it with VMware running on top of Linux though. In Linux you can edit the vmx file to specify that it is a physical disk then the filename is /dev/sdb1 or whatever your card shows up as.]


(1) Install Lab Data

For the different labs in this class, instructor has prepared a set of data (kernel images, kernel configurations, root file systems and more).

Download the tarball at Software Archieve

[Link is given in Reference [2]]. Then cut this file to your home directory. [cd ~]

Then, from a terminal, extract the tarball using the following command

Lab data are now available in a felabs directory in your home directory. For each lab there is a directory containing various data. This directory can also be used as a working space for each lab so that you properly keep the work on each lab well-separated.

(2) Install extra Packages

Ubuntu comes with a very limited version of the vi editor. Install vim, an improved version of this editor. Use command

sudo apt- get install vim

(3) Install Development Environment

The Ubuntu installation does not include gnu-compiler and header files so following commands are suggested:

sudo apt-get install build-essential

(4) Install needed packages

Go to the /home/<user>/felabs/sysdev/toolchain directory. Make sure you have at least 2 GB of free disk space.

Install the packages needed for this lab:

sudo apt-get install gawk autoconf automake libtool
sudo apt-get install libncurses5-dev bison flex patch
sudo apt-get install gettext texinfo curl subversion
sudo apt-get clean
cd ~                                                 (going to your home directory)
sudo tar xvjf embedded_linux.tar.bz2                 (Extracting tar file)
sudo chown - R <user>.<user> felabs                  (Recursively change ownership of felabs to user)
(for example if <user> = abc, so above command becomes[sudo chown - R felabs])

I am successfully able to install all packages.

[gawk, autoconf, automake, libtool, libncurses5-dev, bison, flex, patch, gettext, texinfo, curl, subversion]

(5) Getting Crosstool-ng

Get the 1.4.2 release of Crosstool-ng from

Expand the archive right in the current directory, and enter the Crosstool-ng source directory.

$ sudo tar xvjf crosstool-ng-1.4.2.tar.bz2

Go to the directory crosstool-ng-1.4.2

$ cd crosstool-ng-1.4.2

(6) Installing Crosstool-ng

We can either install Crosstool-ng globally on the system, or keep it locally in its download directory. We'll choose the latter solution. As documented in docs/overview.txt, do:

./configure --local


make install

Following Snapshot shows result of “make” and “make install” command.

Then you can get Crosstool-ng help by running

./ct-ng help

(7) Configure the toolchain to produce

A single installation of Crosstool-ng allows to produce as many tool chains as you want for different architectures, with different C libraries and different versions of the various components.

Crosstool-ng comes with a set of ready-made configuration files for various typical setups: Crosstool-ng calls them «samples». They can be listed by using ./ct-ng help.

We will use the arm-unknown-linux-uclibcgnueabi sample. It can be loaded by issuing:

./ct-ng arm-unknown-linux-uclibcgnueabi

[Execute it from directory /home/harshlavingia/felabs/sysdev/toolchain/crosstool-ng-1.4.2]

Then, to refine the configuration, let's run the menuconfig interface:

./ct-ng menuconfig

In Path and misc options:

Change the prefix directory to /usr/local/xtools/${CT_TARGET}

This is the place where the toolchain will be installed.

Change the number of parallel jobs to 2 times the number of CPU cores in your workstation. Building your toolchain will be faster.

In Toolchain options:

Set «Tuple's alias» to arm-linux. This way, we will be able to use the compiler as arm linux gcc instead of arm-unknown-linux-uclibcgnueabi-gcc which is much longer.

In the C compiler options:

Disable Java and Fortran. We won't need them, so let's reduce the toolchain compilation time by removing them.

In Debug facilities:

Enable gdb, strace and ltrace. Remove the other options. In gdb options, enable the “Cross gdb” and “Build a static gdbserver” options; the other options are not needed.

(8) Produce the toolchain

  1. Create the directory /usr/local/xtools/ and change its owner to your user, so that Crosstool-ng can write to it.

  1. If crosstool-ng complains about the LD_LIBRARY_PATH environment variable, unset it as follows:


  1. Build Cross-Compiler

$ ./ct-ng build

Then wait! [When I did it took more than 2 hours]

For Ubuntu 10.04 [Lucid Linux] version you will get build error. You can see detailed error in file /usr/local/xtools/arm-unknown-linux-uclibcgnueabi/build.log.

I resolve this error with the help of following link.

You need to patch this as below. Edit the following file.

$ vi ./targets/src/uClibc-

Complete file path:


There are three changes which are shown in different color and + sign for which line you must add and – sign for which line you must remove.

static void error(const char *);

static int findsym(const char *);

static void flushline(bool);

-static Linetype getline(void);

+static Linetype get_line(void);

static Linetype ifeval(const char **);

static void ignoreoff(void);

static void ignoreon(void);

@@ -517,7 +517,7 @@ process(void)

for (;;) {


- lineval = getline();

+ lineval = get_line();


debug("process %s -> %s depth %d",


@@ -531,7 +531,7 @@ process(void)

* help from skipcomment().


static Linetype




const char *cp;

int cursym;

@@ -889,9 +889,8 @@ skipcomment(const char *cp)

cp += 1;

} else if (strchr(" \t", *cp) != NULL) {

cp += 1;

- } else {

+ } else

return (cp);

- }



if (strncmp(cp, "\n", 1) == 0) {


Again follow the previous steps (6) from directory

[/home/[username]/felabs/sysdev/toolchain/crosstool-ng-1.4.2] and you can successfully build ARM tool chain.

(9) Testing the toolchain

You can now test your toolchain by adding /usr/local/xtools/arm-unknown-linux-uclibcgnueabi/bin/ to your PATH environment variable.

Content of directory [usr/local/xtools/arm-unknown-linux-uclibcgnueabi/bin] is shown as below.

Compile the simple hello.c program in your main lab directory with arm-linux-gcc. You can use the file command on your binary to make sure it has correctly been compiled for the ARM architecture.

$ arm-linux-gcc hello.c
$ file a.out

To write this code into first you need to compress this code and copy this code in SD card’s Root file system. Then extract it to get executable cross compiled binary. This is required to copy from one file system [Ubuntu linux] to SD card file system.

Now remove SD card from Laptop and plug into Beagle Board. [Check Lab3 document]

Then boot the kernel from SD card and you will get linux prompt. Type ls command to see the linux file system hierarchy which shown in following Snapshot.

Now you can execute your cross compiled binary file a.out of ARM platform on Beagle Board as below.

$ ./a.out

You can see the execution result in following Snapshot.

(10) Cleaning up

To save almost 2 GB of storage space, remove the targets/ subdirectory in the Crosstool-ng directory.