How to configure QEMU and Linaro toolchain for ARM development?

qemu-logo-thumbFundamental to any kind of development are compilers and the underlying platform. Compiler  transforms our code into underlying platform and the platform itself is to run the compiled executables. This is also true in case of embedded development. But unlike normal desktop environment we cannot develop a program on an embedded development device because of various limitations of the device. Instead, What we do is write the program on our desktop(X86) and cross compile it for the required target platform. This effectively accomplishes the job of first component, But to run the cross compiled binary we do need the second component, that is, the target platform itself. Earlier, embedded developers had no choice other than using the real developement devices to test their cross compiled binaries. But with the help of QEMU, now we can emulate, most of todays popular target platforms.  The main theme of this post is to set up the above said components for ARM developement.   

  1. Linaro ARM cross compiler installation
  2. QEMU installation

Linaro ARM cross compiler installation

Linaro is a non-profit organisation developing cross compiler tools for ARM development. Following command installs the required tools.

sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install libc6-dev-armel-cross

These tools are simply collection gnu compiler collection ported for ARM target. The required libraries and binaries are installed into /usr/arm-linux-gnueabi/ . Every binary installed in the above suite will start with arm-linux-gnueabi- .

Cross compiler tools for ARM
Cross compiler tools for ARM

QEMU installation

QEMU is basically a processor emulator capable of emulating most of todays popular architectures.  Primarily QEMU operates in two modes.

  1. Full system emulation: In this mode, QEMU emulates a full system (for example a PC), including one or several processors and various peripherals. It can be used to launch different Operating Systems without rebooting the PC or to debug system code. This mode is mainly used for emulating full operating systems.
  2. User mode emulation: In this mode, QEMU can launch processes compiled for one CPU on another CPU. This eases in cross-compilation and cross-debugging.

When you install QEMU, binaries for both modes are installed. Full system emulation binaries of QEMU starts with qemu-system-xxx and User mode emulation binaries of QEMU starts with qemu-xxx Where xxx denotes the name of the emulation architecture example, i386, arm, mips.

The following command can be used to install QEMU

sudo apt-get install qemu
QEMU installed binaries
QEMU installed binaries

The above screenshot shows all the installed qemu binaries.

Once both the components are set up, Now we can test it by writing a simple hello world C program compiled for ARM architecture and run using QEMU for ARM platform.

#include<stdio.h>

int main()
{
	printf("Hello ARM world");
	return 0;
}

Now we compile the above program as shown below

arm-linux-gnueabi-gcc test.c -o test

We can verify the architecture of the executable created using file command

file command on ARM executable
file command on ARM executable

Now we can emulate the compiled binary using QEMU as shown below

User mode emulation of ARM executable with QEMU
User mode emulation of ARM executable with QEMU

In the above command we need to specify the library path because QEMU will try to dynamically link all the required system calls in to system calls on the host machine.

Since the executable is ARM ABI it cannot be run directly on our machine(which happens to be x86). Following is the message I got when I run it on my machine directly

ARM binary ran on x86
ARM binary ran on x86

References:
http://qemu.weilnetz.de/qemu-doc.html

Leave a comment

Leave a Reply