Preparing for GBA development

This document aims to guide you in the process of seting up the necessary tools in order to start programming for the Game Boy Advance. You are going to need a cross-compiler capable of producing code for the ARM7 line of processors, assorted binary utilities (assembler, linker, etc), and a C library.

The good news, are that all these tools are available as free software, from the GNU project. We are going to use the GNU C compiler (GCC), GNU binutils, and newlib, which is much smaller than the GNU C library (glibc), and targeted towards embedded systems.

The bad news are... well actually there are no bad news... :)

Downloading the necessary tools

GNU C compiler

Just head over to the gcc mirror sites page, and download a recent version of gcc from your nearest mirror. I got gcc 4.0.2.

GNU binutils

Again, go to the binutils web site, and download a recent version of binutils. I got binutils 2.16.1.

Newlib

By now you should know the drill, head over to the newlib web site and grab a recent version.

By the way I got mine from cvs like this:

Getting newlib from CVS
$ cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src login
{enter "anoncvs" as the password}
$ cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src co newlib

But you can get one of the gzipped snapshots available through ftp instead.

Building

Building a cross-compiler, is actually very easy. We have to specify the target system by passing "--target=arm-agb-elf" and that's it. I also include a program prefix, so as to avoid chaos afterwards, i.e. the installed gcc binary will be named arm-agb-elf-gcc, and so on for the rest of them.

I'll assume that after unpacking everything, you have three directories, named: gcc, binutils, and newlib.

Now I will follow the recommended procedure and use a seperate directory to compile everything, so you'll need GNU make. If your system doesn't run GNU make when you run make, substitute all the make commands from now on, to gmake.

Create the build directory:
$ mkdir objdir
$ cd objdir

Building binutils

Nothing fancy, just configure, make, make install, and clean everything up for the next compilation. As I mentioned earlier, we have to pass the appropriate --target=arm-agb-elf and --program-prefix=arm-agb-elf- to the configure script, but that's all there is to it:

$ ../binutils/configure --target=arm-agb-elf --program-prefix=arm-agb-elf-
$ make
$ sudo make install
$ rm -rf *

Building GCC

For gcc we have to provide two additional arguments to the configure script. --enable-languages=c for building only the C compiler and not C++, Java, Objective-C or whatever, and --with-newlib which is supposed to fix some issues when gcc is used with newlib instead of glibc, I am not entirely sure that this last one is needed, but it seemed prudent to include it.

$ ../gcc/configure --target=arm-agb-elf --program-prefix=arm-agb-elf- --enable-languages=c --with-newlib
$ make
$ sudo make install
$ rm -rf *

Building Newlib

Again, the same process, nothing really tricky here:

$ ../newlib/configure --target=arm-agb-elf --program-prefix=arm-agb-elf-
$ make
$ sudo make install

Compiling a GBA program

Now let's test our new cross-development environment. Download this small example and try to build it by typing make. If everything went ok, you should have a file called example.gba which is a flat binary image of the test program compiled for the GBA. Try it out in an emulator, you should see a red screen.

What this makefile does is, create an elf binary first, and then use objcopy to convert it into a flat binary. Note that you should use the provided ld link script, and the crt0.s file from the example tarball in your programs. The defaults of gcc won't work with the gba. Also, feel free to use the makefile from the example as a basis for your own projects.