CrossCompilation/GameBoyAdvance

Compiling/Linking/Packaging Gameboy Advance Images

In order to build binaries that you can actually use on a GBA (or emulator) you need to compile/link/package things properly. You need at least the following:

crt0 and the linker script have already been put together; you just need to grab them and build them:

Assemble CRT0.S using something like arm-elf-as CRT0.S -o crt0.o. Grab crt0.o and lnkscript, and bring them to your project directory. Compiling, Linking, and then extracting a suitable GBA image then becomes something similar to:

arm-elf-gcc -c test.c -c -Wall -Wall -marm -mapcs-32 -mcpu=arm7tdmi
arm-elf-ld -T lnkscript ./crt0.o test.o -o test.elf
arm-elf-objcopy -O binary test.elf test.gba

You can then run test.gba with any emulator (e.g. [VisualBoyAdvance] , BoycottAdvance?).


I encountered a problem when I try to compile the gbatune.

It seems the linker is not working correctly.

Here is the result of make:

 make
arm-linux-as   -o crt0.o crt0.s
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o screen_ve.o screen_ve.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o table.o table.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o ui.o ui.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o comm.o comm.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o screen.o screen.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o widget.o widget.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o widget_table.o widget_table.c
arm-linux-gcc -Wall -marm -mapcs-32 -mcpu=arm7tdmi   -c -o gbatune.o gbatune.c
arm-linux-ld -T lnkscript crt0.o screen_ve.o table.o ui.o comm.o screen.o widget.o widget_table.o gbatune.o -o gbatune.elf -lc -lm `arm-linux-gcc -print-libgcc-file-name`
arm-linux-ld: section .data [08014e84 -> 08014ea7] overlaps section .rodata [08001ec8 -> 08014ed3]
arm-linux-ld: section .dynamic [08014ea8 -> 08014f4f] overlaps section .rodata [08001ec8 -> 08014ed3]
arm-linux-ld: section .got.plt [08014f50 -> 08014f6f] overlaps section .dynsym [08014f14 -> 08014f73]
arm-linux-ld: section .rel.dyn [08014f70 -> 08014f97] overlaps section .dynsym [08014f14 -> 08014f73]
arm-linux-ld: BFD 2.15 assertion fail ../../src/bfd/elf32-arm.h:3737
arm-linux-ld: BFD 2.15 assertion fail ../../src/bfd/elf32-arm.h:3737
arm-linux-ld: BFD 2.15 assertion fail ../../src/bfd/elf32-arm.h:3737
arm-linux-ld: BFD 2.15 assertion fail ../../src/bfd/elf32-arm.h:3737
arm-linux-ld: BFD 2.15 assertion fail ../../src/bfd/elf32-arm.h:3737
arm-linux-ld: BFD 2.15 assertion fail ../../src/bfd/elf32-arm.h:3905
make: *** [gbatune.elf] Segmentation fault
make: *** Deleting file `gbatune.elf'

The cross compiling system is configured regarding: [Setting up a Cross Development Environment on Debian GNU/Linux]

and cross complier/linker is working fine with this little test:

int
AgbMain(void)
{
        return (0);
}

I've successfully compiled the gbatune with this tool:

[Devkitpro]