November 2014

Bare Metal coding on FreeBSD

I recently got interested in the technical details of how ARM OS’s work, so I decided to try my hand at writing a simple one.  This blog post is not about the OS itself, but about setting up the development environment. In my case, I’m developing in a terminal session, on FreeBSD 10 on an AMD-64 host, so I’ll need to cross-compile all my code.  Luckily, the ports tree includes gcc-arm-embedded a port of the launchpad ARM cross tools.  It’s easy to install: pkg install gcc-arm-embedded This package includes all the tools which are needed: -rwxr-xr-x 1 root wheel 711488 Oct 3 11:17 arm-none-eabi-addr2line -rwxr-xr-x 2 root wheel 740040 Oct 3 11:17 arm-none-eabi-ar -rwxr-xr-x 2 root wheel 1298680 Oct 3 11:17 arm-none-eabi-as -rwxr-xr-x 2 root wheel 620816 Oct 3 11:17 arm-none-eabi-c++ -rwxr-xr-x 1 root wheel 710528 Oct 3 11:17 arm-none-eabi-c++filt -rwxr-xr-x 1 root wheel 620608 Oct 3 11:17 arm-none-eabi-cpp -rwxr-xr-x 1 root wheel 29416 Oct 3 11:17 arm-none-eabi-elfedit -rwxr-xr-x 2 root wheel 620816 Oct 3 11:17 arm-none-eabi-g++ -rwxr-xr-x 2 root wheel 620608 Oct 3 11:17 arm-none-eabi-gcc -rwxr-xr-x 2 root wheel 620608 Oct 3 11:17 arm-none-eabi-gcc-4.8.4 -rwxr-xr-x 1 root wheel 24480 Oct 3 11:17 arm-none-eabi-gcc-ar -rwxr-xr-x 1 root wheel 24448 Oct 3 11:17 arm-none-eabi-gcc-nm -rwxr-xr-x 1 root wheel 24448 Oct 3 11:17 arm-none-eabi-gcc-ranlib -rwxr-xr-x 1 root wheel 271072 Oct 3 11:17 arm-none-eabi-gcov -rwxr-xr-x 1 root wheel 3992568 Oct 3 11:17 arm-none-eabi-gdb -rwxr-xr-x 1 root wheel 776672 Oct 3 11:17 arm-none-eabi-gprof -rwxr-xr-x 4 root wheel 1025912 Oct 3 11:17 arm-none-eabi-ld -rwxr-xr-x 4 root wheel 1025912 Oct 3 11:17 arm-none-eabi-ld.bfd -rwxr-xr-x 2 root wheel 722928 Oct 3 11:17 arm-none-eabi-nm -rwxr-xr-x 2 root wheel 906848 Oct 3 11:17 arm-none-eabi-objcopy -rwxr-xr-x 2 root wheel 1123424 Oct 3 11:17 arm-none-eabi-objdump -rwxr-xr-x 2 root wheel 740056 Oct 3 11:17 arm-none-eabi-ranlib -rwxr-xr-x 1 root wheel 365208 Oct 3 11:17 arm-none-eabi-readelf -rwxr-xr-x 1 root wheel 712976 Oct 3 11:17 arm-none-eabi-size -rwxr-xr-x 1 root wheel 712080 Oct 3 11:17 arm-none-eabi-strings -rwxr-xr-x 2 root wheel 906864 Oct 3 11:17 arm-none-eabi-strip Additionally, an ARM simulator such as QEMU will be needed.  FreeBSD also include that port: pkg install qemu-devel I can easily use BSD Make, however I prefer GNU Make, so I’ve installed that too pkg install gmake With these tools installed, I have enough to cross-compile ARM assembler and C code, link it, and run it in QEMU and debug with GDB.