🤓 Build your own toolchain for gba dev
Inspired by build-your-own-x.
Artifacts are released here.
Only for education purpose. Don't use it for non-trivial development.
Read crosstool-NG's doc. The version I use is 1.24.0.
You can load .config
file in its config menu. Don't forget to change Toolchain ID string
and Toolchain bug URL
in Toolchain options
pls. Feel free to tweak other options for your own toolchain. You can also load your own patches in CT_TOP_DIR
if you have.
Here are problems I met and solutions I found:
-
My OS is CentOS 7. Accoding to crosstool-NG 1.24.0's release note, its g++ version cannot build gdb. Solution: Follow this doc to update it.
-
OS's setting up. According to crosstool-NG's doc, you should read its dockerfile to figure out its dependencies. Solution: Read dockerfile as it says. For CentOS 7,
yum install -y autoconf gperf bison file flex texinfo help2man gcc-c++ libtool make patch ncurses-devel python36-devel perl-Thread-Queue bzip2 git wget which xz unzip
. -
[ERROR] You must NOT be root to run crosstool-NG.
Solution: Run it as another user orCT_ALLOW_BUILD_AS_ROOT=y
according to this. -
[ERROR] Don't set LD_LIBRARY_PATH. It screws up the build.
Solution:unset LD_LIBRARY_PATH
accoding to this doc.
To sum up, Google Is Your Best Friend.
Now we have our own toolchain, let's test it.
All files in test
directory are borrowed from somewhere else (first.c
from tonc and others from here with a little modifications). I know the code is ugly, but it is only for test.
arm-gba-eabi-gcc -nostartfiles -Xlinker -T gba.ld first.c crt0.s gba-syscalls.c
arm-gba-eabi-objcopy -O binary a.out first.gba
Then we get first.gba
and test it. It works fine. Don't forget to gbafix it for release.
Here are some notes:
-
This is only to test toolchain. For non-trivial development, use build automation.
-
gba.ld
here is linker script for gba cartridge. Use this for multiboot. -
crt0
andsyscalls
can also be merged into libc which is a part of our toolchain. Here are docs for porting newlib (Google Is Your Best Friend again).