Lab 01 Toolchain
Lab 01 Toolchain
Setup
Go to the $HOME/embedded-linux-qemu-labs/toolchain directory.
$ 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
$ ./bootstrap
$ ./ct-ng help
$ ./ct-ng menuconfig
$ ./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
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.
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
$ 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:
/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.