Wednesday, January 19, 2011

Installing the GNU Toolchain for ARM Processors

So far, so good. You have the Android source and the libraries for the device. The final software you need
is a C compiler. This tool provides the C library, binary utilities, preprocessor, compiler, debugger,
profiler, and linker required to build software for the ARM hardware used by the Android device. You will
use the toolchain provided by the Sourcery G++ Lite Edition for ARM (http://www.codesourcery.com/
sgpp/lite/arm/portal/subscription?@template=lite). You have two choices:
• Download the easy installer.
• Get the tool in tar format and simply unzip it in your system. (I prefer to do it this way, as it is much faster).
If you choose to install from the tarball, you can unzip the archive on your desktop using the following command:

$ cd $HOME/Desktop
$ tar zxvf arm-2008q3-72-arm-none-linux-gnueabi.tar.gz

Either way you choose to install the toolchain, you must add the bin folder to your system path so the toolchain can be invoked from the console. Add the following text to your $HOME/.bashrc file:
ARM_HOME=$HOME/Desktop/arm-2008q3
export PATH=$PATH:$ARM_HOME/bin



Now you should have the toolchain ready for use. Perform a quick test by typing the following:
user@ubuntu:~$ arm-none-linux-gnueabi-gcc --version

Let’s take a quick look at some of the most useful commands provided by the toolchain:
• arm-none-linux-gnueabi-gcc: This is the C compiler and is equivalent to the Linux gcc command. Most of the options are very close to those provided by its Linux counterpart.
• arm-none-linux-gnueabi-g++: This is the C++ compiler, which wraps the gcc command with extra options for C++.
• arm-none-linux-gnueabi-ld: This is the linker used to build a final binary, either as a monolithic file (statically) or as a shared library (dynamically).
• arm-none-linux-gnueabi-objdump: This displays information about binary files.
• arm-none-linux-gnueabi-strip: This removes symbols and sections from binary files, including symbol and relocation information, debugging symbols and sections, nonglobal symbols, and others. This can help to reduce the size of the final executable.

For example, arm-none-linux-gnueabi-objdump is a very useful tool for peeking into your binaries. It shows you information such as the following:
• Archive header information
• Contents of the overall file header
• Assembler contents of executable sections
• Intermix source code with disassembly
• Contents of the dynamic symbol table
• Relocation entries in the file
So, to display symbol table information about the device C runtime (libc.so) pulled from the device into $HOME/tmp/android/system/lib, use this command:
$ arm-none-linux-gnueabi-objdump -T ~/tmp/android/system/lib/libc.so

As you can see, the toolchain mirrors the GNU GCC toolchain. In fact, the only noticeable difference is that all the commands start with the prefix arm-none-linux-gnueabi. With the toolchain in place, the last piece is a set of custom scripts to invoke the preceding commands.

0 comments:

Post a Comment