0% found this document useful (0 votes)
53 views3 pages

Lab 01 Toolchain

Uploaded by

ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Lab 01 Toolchain

Uploaded by

ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Embedded Linux System Development

Building a cross-compiling 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

Setup
Go to the $HOME/embedded-linux-qemu-labs/toolchain directory.

Install needed packages


Install the packages needed for this lab:

$ sudo apt install build-essential git autoconf bison flex texinfo help2man \
gawk libtool-bin libncurses5-dev

Getting Crosstool-ng
Let’s download the sources of Crosstool-ng, through its git source repository, and switch to
a commit that we have tested:
$ git clone https://github.com/crosstool-ng/crosstool-ng.git
$ cd crosstool-ng/
$ git checkout 79fcfa17

Building and 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 at https://crosstool-ng.
github.io/docs/install/#hackers-way, do:

$ ./bootstrap

You can continue:


$ ./configure --enable-local
$ make

Then you can get Crosstool-ng help by running

$ ./ct-ng help

Configure the toolchain to produce


A single installation of Crosstool-ng allows to produce as many toolchains 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 list-samples.
We will load the Cortex A9 sample. Load it with the ./ct-ng command.

© 2019-2021 Bechir Zalila, CC BY-SA license 5


Embedded Linux System Development

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

$ ./ct-ng menuconfig

In Path and misc options:


• Change Maximum log level to see to DEBUG (look for LOG_DEBUG in the interface, us-
ing the / key) so that we can have more details on what happened during the build in
case something went wrong.
In Toolchain options:
• Set Tuple's vendor string (TARGET_VENDOR) to training.
• Set Tuple's alias (TARGET_ALIAS) to arm-linux. This way, we will be able to use the
compiler as arm-linux-gcc instead of arm-training-linux-uclibcgnueabihf-gcc,
which is much longer to type.
In C-library:
• If not set yet, set C library to uClibc (LIBC_UCLIBC)
• Keep the default version that is proposed
• If needed, enable Add support for IPv6 (LIBC_UCLIBC_IPV6)2 , Add support for WCHAR
(LIBC_UCLIBC_WCHAR) and Support stack smashing protection (SSP) (LIBC_UCLIBC_
HAS_SSP)
In C compiler:
• Make sure that C++ (CC_LANG_CXX) is enabled
In Debug facilities, disable every option, except strace (DEBUG_STRACE), with default
settings. Some of these options will be useful in a real toolchain, but in our labs, we will
do debugging work with another toolchain anyway. strace is an exception as we will use it
earlier. Hence, not compiling debugging features here will reduce toolchain building time.
Explore the different other available options by traveling through the menus and looking at
the help for some of the options. Don’t hesitate to ask your trainer for details on the available
options. However, remember that we tested the labs with the configuration described above.
You might waste time with unexpected issues if you customize the toolchain configuration.

Produce the toolchain


Nothing is simpler:

$ ./ct-ng build

The toolchain will be installed by default in $HOME/x-tools/. That’s something you could
have changed in Crosstool-ng’s configuration.
And wait!

Known issues
Source archives not found on the Internet
It is frequent that Crosstool-ng aborts because it can’t find a source archive on the Inter-
net, when such an archive has moved or has been replaced by more recent versions. New
Crosstool-ng versions ship with updated URLs, but in the meantime, you need work-arounds.
If this happens to you, what you can do is look for the source archive by yourself on the
Internet, and copy such an archive to the src directory in your home directory. Note that
2 That’s needed to use the toolchain in Buildroot, which only accepts toolchains with IPv6 support

6 © 2019-2021 Bechir Zalila, CC BY-SA license


Embedded Linux System Development

even source archives compressed in a different way (for example, ending with .gz instead of
.bz2) will be fine too. Then, all you have to do is run ./ct-ng build again, and it will use
the source archive that you downloaded.

Testing the toolchain


You can now test your toolchain by adding $HOME/x-tools/arm-training-linux-uclibcgnueabihf/
bin/ to your PATH environment variable and compiling the simple hello.c program in your
main lab directory with arm-linux-gcc:

$ arm-linux-gcc -o hello hello.c

You can use the file command on your binary to make sure it has correctly been compiled
for the ARM architecture.
Did you know that you can still execute this binary from your x86 host? To do this, install
the QEMU user emulator, which just emulates target instruction sets, not an entire system
with devices:
$ sudo apt install qemu-user

Now, try to run QEMU ARM user emulator:

$ qemu-arm hello
/lib/ld-uClibc.so.0: No such file or directory

What’s happening is that qemu-arm is missing the shared C library (compiled for ARM)
that this binary uses. Let’s find it in our newly compiled toolchain:

$ find ~/x-tools -name ld-uClibc.so.0

/home/tux/x-tools/arm-training-linux-uclibcgnueabihf/
arm-training-linux-uclibcgnueabihf/sysroot/lib/ld-uClibc.so.0
We can now use the -L option of qemu-arm to let it know where shared libraries are:

$ qemu-arm -L ~/x-tools/arm-training-linux-uclibcgnueabihf/\
arm-training-linux-uclibcgnueabihf/sysroot hello

Hello world!

Cleaning up
Do this only if you have limited storage space. In case you made a mistake in the toolchain
configuration, you may need to run Crosstool-ng again, keeping generated files would save a
significant amount of time.
To save about 11 GB of storage space, do a ./ct-ng clean in the Crosstool-NG source
directory. This will remove the source code of the different toolchain components, as well
as all the generated files that are now useless since the toolchain has been installed in
$HOME/x-tools.

© 2019-2021 Bechir Zalila, CC BY-SA license 7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy