Building a GCC toolchain on Linux


These instructions are for building gcc 3.3.2, with binutils 2.14 and newlib 1.11.0. It's pretty simple to build a toolchain, and it gives you a nice warm fuzzy feeling of being in control :-). These instructions are for Linux, you could use them with pretty much any Unix version that runs gcc (I think). You can also use them with Cygwin under Windows; there are a few little changes but if you know basically what you're doing then it's easy.

I put all of the tools in
/usr/ , which is appropriate for any Linux that conforms to the Linux Filesystem Standard (LFS). Most, if not all, modern distros follow this standard. If you want the tools somewhere else (like /usr/local/), then change the "--prefix" switch in all of the configure commands below, and also in the bgcc script.

By the way, I really do recommend using version 3.3.1 or later of gcc. Version 3.3.2 is the current stable release. 3.3.1 fixed a major bug in the ARM port of gcc, related to generating interrupt handlers with stack frames. Also the ARM port is a pretty active one with improvements being made all the time. Version 3.4 will have a new floating-point library which is reported to be 10 to 25 times as fast as the current one!

You need the following files:

gcc-3.3.2.tar.bz2
binutils-2.14.tar.bz2
newlib-1.11.0.tar.gz
bgcc

Put all of the files in a folder which will be the base for building the toolchain.

For gcc, go to The GNU project, click on a mirror close to you. You'll probably get a directory listing, go to "releases", "gcc-3.3.2".

For binutils, go to The GNU project again, choose a mirror from the list, you'll get another directory listing. Go to the binutils folder.

For newlib, you could use The RedHat site but it might be slow. Most general mirror sites will have it but it might be hidden under a directory called "sourceware" or "sources", for example it's at mirror.ac.uk.

Depending on your browser configuration, the bgcc file may not be downloaded with execute access. Enter

chmod 755 bgcc

to make it executable.

I've found that some mirror sites don't have the
.tar.bz2 files, they only have .tar.gz. It's fine to use those files, they're just a bit bigger. If you do use a .tar.gz, use tar -xvzf instead of tar -xvjf to extract it.

BUILDING BINUTILS

In the folder where you placed the files, enter the following commands:

tar -xvjf binutils-2.14.tar.bz2
cd binutils-2.14
mkdir build
cd build
../configure --prefix=/usr --target=arm-elf
make
su
<... enter root password ...>
make install
exit

When this is done, you'll have a working linker, assembler etc. Type "arm-elf-ld -v" and you should get a version printout. Next, get rid of the binutils folder, which is of no more use:

cd ../..
rm -rf binutils-2.14

BUILDING GCC AND NEWLIB

tar -xvzf newlib-1.11.0.tar.gz
tar -xvjf gcc-3.3.2.tar.bz2
cd gcc-3.3.2
ln -s ../newlib-1.11.0/newlib .
mkdir build
cd build
../../bgcc
su
<... enter root password ...>
make install
exit

Look at the bgcc script, it just sets some environment variables for building newlib, libgcc, libstdc++ etc. The reason I've done that is that I like to have everything in the project, including standard libraries, compiled with the same compiler options. Obviously this isn't possible for the Gamepark SDK libraries, but it's as good as I can do.

Once all that's done, you have a build environment with all the standard libraries and support for C. I don't use thumb mode (it really doesn't do anything useful that I can see) so I disable multilibs. I would disable thumb interworking, but the Gamepark libraries I use have it enabled and you shouldn't link code with interworking enabled to code with interworking disabled.

C++ can be compiled with this compiler, but I have not put in code to call global constructors or destructors, so C++ programs probably won't work. Or maybe the Gamepark libs handle that? I haven't tested it yet, when I do I'll update this page.

Get rid of the gcc and newlib source folders with:

cd ../..
rm -rf gcc-3.3.2
rm -rf newlib-1.11.0

You can check that gcc is there with "arm-elf-gcc -v" which should print out version information.

INSTALLING THE GAMEPARK SDK AND SDL LIBRARIES

Make a new folder to put the libraries in. These files will be used whenever you build a GP32 program. My home directory is
/home/rfbrown, and so I put the libraries in /home/rfbrown/gp32/sdl/ . Make a directory to put the libraries in, and then put this file in that directory. cd to the directory and enter

tar -xvjf gp32libs.tar.bz2

This will extract all of the Gamepark SDK libraries (compiled with soft floating point, and thumb interworking enabled), the SDL libraries, and the required header files. It also extracts the startup files that every GP32 program needs, like crt0.s and a linker script.

DOWNLOAD GPRUN

This tool was created by mithris and is simply invaluable for developing on GP32. Download it and put it in a directory that's in your path (I just put it in
/usr/bin).

You should also flash your bios with multifw2, which you can get from Mr. Spiv's site. Once you have done that, press "Select" while powering up the GP32 and select "PC-Link v1.01", and press "B" to make it the default selection for your developing/debugging sessions.

MAKING A SIMPLE GP32 APPLICATION

For any GP32 program, you need at least two files: a Makefile, and at least one 'C' file.

Make a new directory, and download this file into it. Enter

tar -xvjf hello1.tar.bz2

This will produce two files: Makefile and gpmain.c. These files are very simple, you will find them easy to follow. Edit Makefile and change anything that you need to (usually this will just mean changing the GPSDK_HOME line to the folder where you extracted the libraries).

Then, enter

make

and the hello program should build, using all the tools you've built above! If it doesn't work, mail me and tell me the error messages that are reported, and I'll try help you fix it (it could very well be a mistake in my instructions :-).

With your GP32 connected to your PC and switched on with PC-link saying "Waiting", enter

make send

The program should be downloaded to the GP32 and should start executing. You can press any button on the GP32 to exit the program (which will reset the GP32 and take you back to PC-link): this is a very quick and very useful load-test cycle.

MAKING A SIMPLE SDL APPLICATION

SDL on the GP32 is the result of some hard work by Chui, and its home page is at Sourceforge. Many thanks to Chui for this!

Make a new directory, and download this file into it. Enter

tar -xvjf sdl_test.tar.bz2

This will produce three files: Makefile, sdltest.c, and data.h. data.h has data for a sound and a picture. Edit Makefile as you did above, and then enter

make

the sdltest program should build. Try "
make send" again, and you should see the "SDL Now!" icon and hear a sound played. Once again, you can press any button on the GP32 to exit the program.

Valid XHTML 1.0! Valid CSS!