GNU toolchain

Generally a toolchain is a chain of tools :)) obviously isn’t it ?

Before starting it is worthwile to say that the GNU toolchain is an essential component for building applications for embedded OSes (or RTOS- do not talk now about the differences between RTOS and embedded OS but this is good to have in mind for a future post)

The result of one tool is taken and used by next one and so on, in a serial way, in order to achieve the desired result. Tool-chain is some kind of ancestor of IDE’s, actually the main idea of having and IDE (Integrated Development Environment – something that “integrates” all development tools that you need) is to ease your work and not to strive with different versions of different tools. Using an IDE avoids unwanted dependency errors that may arise when using a tool-chain.

Its main purpose is to produce executables that can be linked to some standard libraries in order to form a complete operating environment (I mean operating system).

Why to discuss about it? Because it is very important in configuring and compiling RTOS (or embedded OS) kernels but also to develop applications on top of it for embedded systems.

Actually everywhere the Linux kernel is deployed GNU tool-chain is needed in order to configure and to build it for the specific target. As I mentioned in my previous post about Mobile OSes, there are other development tools used for creating mobile applications (even development for Android which is relying on Linux kernel can be done using Eclipse, so without the need of GNU tool-chain), but embedded world is bigger than mobile development …

It can worth a discussion about advantages / disadvantages of using GNU toolchain or an IDE, but I won’t cover this in detail. As far as I know IDEs cost money, well it depends also because if you take MPLAB from Microchip, this is free, but the C compiler costs some dollars, but GNU software is completely free and can be downloaded from here .

But what is it made of?

Basically there are three main components: binutils, compiler and C library.

Before going deeper into the internals it worth mentioning that there are three ways of generating tool-chains:

  • first one as I already mentioned, manually, by configuring and compiling the components in the right order,
  • second, the simplest, by using an already pre-compiled tool-chain and
  • third one by generating one automatically, via a script.

Using a pre-compiled tool-chain is quite similar with using an IDE. Depending on your host platform (the PC where you are developing embedded software) and on your chosen target platform ( that piece of embedded hardware which you want it to execute your software ) you can download from the Internet some precompiled GNU tool-chains.
For example this guy here wants to teach us how to install an already pre-compiled GNU tool-chain for ARM devices running Linux kernel. Another guy suggests other useful resources in finding pre-compiled tool-chains.

You can use NG (new generation) cross tool in order to generate a tool-chain appropriate for your target configuration. This software (crosstool-NG) pointed by the link has a kernel-like menuconfig where you can select the configuration for which you want to build the tool-chain. Besides this one you can use others like buildrootfor generating a tool-chain linked with uClibc library, or this one.

Enough with this! Let’s get to the serious stuff, how do we build a tool-chain on our own, by downloading all the components from the GNU project website?

Basically each component is downloaded from http://ftp.gnu.org/gnu/ and then unpacked, configured, built and installed, those are the main five steps (last three are the most important and the most embedded-focused).

If we start with binutils, and it should be the case because usually this is the first component to be prepared, things will go following way. This package is split, on its turn, into others: as (assembler), ld (linker), ar (manipulates and creates archives), nm (lists symbols in an object file), objcopy (copies and translates obj files), objdump (displays info about the content of obj files), ranlib(generate indexes for archives), readelf (displays content of EFL files), size (list total and section sizes), strings (list printable strings), strip (removes symbols from an object file) and few others.

First two of them are the main ones but are also tools which are very familiar to many embedded programmers, even to those who never worked with GNU tool-chain. Rest of them is generally very simple programs and I will try to have a look into their documentation and to provide a more detailed description.

Second tool-chain component is the GNU C compiler, the notorious GCC. This is more or less the most important piece of the tool-chain. It can compile C, C++, Objective-C, Java, Ada code and it provides supports for almost all well-known target processor families: ARM, Intel x86, AVR, MIPS, PowerPC, Motorola 68k, Blackfin and many more, less familiar.

The C library is also an essential component. The tool-chain has to be build in dependency to the C library used. There are several libraries available: classical glibc (from the GNU project) its main drawback consists in its big size, it is not optimized for small embedded architectures, uClibc (probably around 4 times smaller than glibc, optimized for embedded systems), eglibc (you gussed it – embedded glibc – lightweight counterpart of glibc).

Well I went in a rush through all the basic things that are part of a GNU tool-chain, now it is the time to say few words about how to use the tool-chain installed.
Before building the tool-chain there are few important to take into consideration:

    which C library to choose
    which version of tool-chain components to choose and finally… probably the most important one
    how to configure the tool-chain

We can distinguish four types of tool-chain builds

    -native: you build a toolchain on the host platform that generates code for host platform which will run on host platform (this is the classical case in developing desktop software)
    -cros-native build: build a toolchain on your host PC that will run on your target and will generate code for your target (this is rarely used due to size limitations of the target platform, it is seldom the case that the tool-chain runs on the target)
    -cross-build: build a tool-chain on your host, running on your host and generating code for the target platform (this is the most used case in embedded, all the development is done on host PC, then when everything is done executables are deployed on the target)
    – canadian build : three different machines — build a tool-chain on one machine, that tool-chain will have to run on another machine and will generate code for your target (I mean the third machine), rarely used, but intersting for its name 🙂

This was everything that I wanted to share with you, I have to keep something for next time too

PS: Always have to keep in mind post size (Never too big ! Remember Bogdan! Never too big! )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: