Installing an ARM cross-compiler on Mac Mountain Lion

Here I will describe my installation of an ARM cross compiler, on a MacBook Air with Mac OS Mountain Lion.

After some searching on the net I decided to try the YAGARTO toolchain.

Navigating to the download place for Mac, I downloaded the file

yagarto-bu-2.22_gcc-4.7.1-c-c++_nl-1.20.0_gdb-7.4.1_eabi_intelmac_20120616.dmg

Using this file however led to an error, saying

selected processor does not support requested special purpose register -- `mrs r0,cpsr'

I reverted to an older version, found at YAGARTO’s Sourceforge page. This led to download of the file

yagarto-bu-2.21_gcc-4.6.2-c-c++_nl-1.19.0_gdb-7.3.1_eabi_intelmac_20111119.dmg

Double-clicking on this downloaded file, I was able to install the toolchain.

I then added the following changes

export ARM_GCC_LOCATION=/Users/oladahl/yagarto/yagarto-4.6.2/bin
export PATH=$ARM_GCC_LOCATION:$PATH

to my setup script, where I also set up other environment variables.

Now I can start programming for ARM!

As an example, I can compile, link, and run the example described in Chapter The Bare Metal in the book Into Embedded.

Advertisements

Installing QEMU

QEMU is an open source computer emulator. Here I describe how I installed QEMU on Linux and on Mac Mountain Lion.

My goal was to create a simulator for machines with ARM architecture and for machines with x86 architecture.

Updates to this post

  • July 15, 2013 – changed the section on Ubuntu Linux to cover QEMU 1.5.1 instead of QEMU 1.2.0.

Ubuntu Linux

Starting from the QEMU home page I navigated to the download page. From there I downloaded the file

qemu-1.5.1.tar.bz2

I unpacked the file, and navigated to the directory created during the unpacking, using the commands

tar xvjf qemu-1.5.1.tar.bz2
cd qemu-1.5.1

As a preparation, I needed to update my Ubuntu 13.04 installation. It turned out that the following installations were needed:

sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0
sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install libsdl-console
sudo apt-get install libsdl-console-dev

I could then configure QEMU, using the command

./configure --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc --enable-sdl

I could then build and install, using

make
sudo make install

I could then use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.elf

and simulation of an x86 computer, e.g. as

qemu-system-x86_64 -kernel prog_x86_grub_target.elf

Problems encountered – I had some trouble before realizing which packages to add to Ubuntu in order to get QEMU to build. The first thing that happened was that the configure command failed, with

ERROR: zlib check failed
Make sure to have the zlib libs and headers installed.

which, after some searching, led me to install zlib as

sudo apt-get install zlib1g-dev

Then I got a message I recognized from my installation of QEMU on Mac, saying that

ERROR: glib-2.12 required to compile QEMU

which, again after some searching, led to the installation of glib as

sudo apt-get install libglib2.0

Configure was now happy but make was not. The make command gave an error, as

(cd /home/ola/Downloads/qemu-1.5.1/pixman; autoreconf -v --install)
/bin/sh: autoreconf: command not found
make: *** [/home/ola/Downloads/qemu-1.5.1/pixman/configure] Error 127

Trying the command autoreconf, as

ola@ola-Aspire-S3-391:~/Downloads/qemu-1.5.1$ autoreconf
The program 'autoreconf' can be found in the following packages:
* autoconf

led to the installation of autoconf, as

sudo apt-get install autoconf

An error telling me to install libtool then appeared, as

../../lib/autoconf/general.m4:2678: AC_LINK_IFELSE is expanded from...
configure.ac:552: the top level
configure.ac:75: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
make: *** [/home/ola/Downloads/qemu-1.5.1/pixman/configure] Error 1
make: *** Deleting file `/home/ola/Downloads/qemu-1.5.1/pixman/configure'

which, by help from Erik Rull, led me to the installation of libtool, as

sudo apt-get install libtool

Now everything built, and I could also do an installation of QEMU, as

sudo make install

The ARM simulation worked fine, but there was no screen in the x86 simulation. I guessed that I needed also SDL for this purpose, and after the installation of sdl, as

sudo apt-get install libsdl-console
sudo apt-get install libsdl-console-dev

I could see a console, and the long-awaited “Hello, world”-message from my program.

Linux

I downloaded and unpacked QEMU in the same way as described above for Ubuntu Linux.

Then, since I was not root on the machine, I used the configure command

./configure --prefix=/nobackup/local/prog/qemu --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

followed by commands for build and installation, as

make
make install

I also added the following changes

export PATH=/nobackup/local/prog/qemu/bin:$PATH

to my setup script, where I also set up other environment variables.

I could then use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.bin

Mac Mountain Lion

I downloaded and unpacked QEMU 1.2.0 in the same way as described above for Ubuntu Linux.

Then, based on information from Ruben Schade, I used the configure command

./configure --enable-cocoa --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

This command generated an error, telling me that “glib-2.12” was “required to compile QEMU”. I searched for this error, and after having read at this MacPorts-related page, I ended up doing

sudo port install glib-2.12
sudo port selfupdate
sudo port upgrade outdated

which, as a result, made it possible to redo the configure command as decribed above.

I then built QEMU, which succeeded but with several warnings, and installed it, using

make
sudo make install

I could now use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.bin

Installing an ARM cross compiler on Ubuntu

Here I will describe my installation of an ARM cross compiler, on an x86 machine with Ubuntu Linux.

Updates to this post

  • July 12, 2013 – changed to a later version of the Sourcery ARM compiler – now using version 2013.05-23
  • March 1, 2013 – changed to a later version of the Sourcery ARM compiler – now using version 2012.09-63

I had decided to use the Sourcery ARM compiler, formerly from CodeSourcery and now from Mentor.

I go to the page

http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

at which I decide to use the EABI release for ARM processors.

Then, I continue to the installation page for the ARM EABI version.

After having created an account (this was my first time here) and then logging in, I get an e-mail with a download link from which I can proceed to a page where I can download the IA32 GNU/Linux Installer. Doing this results in download of a file named arm-2013.05-23-arm-none-eabi.bin.

I make the file executable by doing

chmod +x arm-2013.05-23-arm-none-eabi.bin

and then I run the file, using the command

./arm-2013.05-23-arm-none-eabi.bin

This command results in an error message, and I am instructed to issue the command

sudo dpkg-reconfigure -plow dash

and then answer the question that comes up as instructed by the error message.

Now, again running the command

./arm-2013.05-23-arm-none-eabi.bin

results in the installation being started. After having gone through steps involving reading and accepting license agreements, followed by a decision to not create any symbolic links, and to not send anonymous information about usage of the ARM compiler, the installation is complete.

As a last step, I modify the PATH environment variable using the commands (where /home/ola is my home directory)

export ARM_GCC_LOCATION=/home/ola/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin
export PATH=$ARM_GCC_LOCATION:$PATH

I put the above two lines in a setup file, called setup.sh, that I run every time I want to use the ARM toolchain.

Now I can start programming for ARM!

As an example, I can compile, link, and run the example described in Chapter The Bare Metal in the book Into Embedded.