Tuesday, 11 November 2014

Building GNAT GPL 2014 for arm-eabi

These notes describe building GNAT GPL 2014 for the Cortex M4 on Mac OS X.

My target board was the STM32M4F29I Discovery.

I'm going to leave out all the false steps along the way, they confused me and would no doubt confuse you, the reader.

The basis for the port was the source files provided at AdaCore Libre for the Linux version (binary archive gnat-gpl-2014-arm-elf-linux-bin.tar.gz):

  • gcc-47-gpl-2014-src.tar.gz
  • gdb-7.7-gpl-2014-src.tar.gz
  • gmp-4.3.2.tar.gz
  • gnat-gpl-2014-47-src.tar.gz
  • mpc-0.8.1.tar.gz
  • mpfr-2.4.2.tar.gz

together with

  • binutils-2.24.tar.gz
  • newlib-2.1.0.tar.gz

from their home sites.

By far the most helpful of the 'how I built a toolchain for the Cortex' sites was Iztok's HW/SW Sandbox, in particular Build Your Own GNU ARM Cross-Toolchain From Scratch.

Set up the environment

To build GNAT, you need a GNAT compiler. To build a cross-compiler, you need a host compiler built from the same sources.

In this case, the host compiler is GNAT GPL 2014, as supplied by AdaCore.

I plan to install the cross-compiler in a temporary location, ~/local-arm, so I set up PATH to pick first the host compiler, then the target compiler (when it exists):

PATH=/opt/gnat-gpl-2014/bin:~/local-arm/bin:$PATH

I unpacked the sources into, for example, ~/tmp/arm/binutils-2.24. I created a directory ~/tmp/arm/build with subdirectories for building each of the components: for example, ~/tmp/arm/build/binutils.

Build binutils

From subdirectory binutils,

../../binutils-2.24/configure \
 --build=x86_64-apple-darwin13 \
 --target=arm-eabi \
 --prefix=$HOME/local-arm \
 --with-cpu=cortex-m4 \
 --with-fpu=fpv4-sp-d16 \
 --with-float=hard \
 --with-mode=thumb \
 --enable-interwork \
 --enable-multilib \
 --with-gnu-as \
 --with-gnu-ld \
 --disable-nls \
 --disable-werror

followed by make; make install.

Build GCC without any libraries

This requires more setup than the other components.

Having unpacked gcc-47-gpl-2014-src.tar.gz, gmp-4.3.2.tar.gz, gnat-gpl-2014-47-src.tar.gz, mpc-0.8.1.tar.gz, and mpfr-2.4.2.tar.gz, the first thing is to move gnat-gpl-2014-47-src/src/ada to gcc-47-gpl-2014-src/gcc/ada. (There is a patch, gnat-gpl-2014-47-src/src/gcc-head.dif, but it was already applied).

Then, in gcc-47-gpl-2014-src/, set up symbolic links to the supporting components:

ln -s ../gmp-4.3.2 gmp
ln -s ../mpfr-2.4.2 mpfr
ln -s ../mpc-0.8.1 mpc

Then, apply the patch from GCC Bugzilla PR/61407 - this allows gcc to run on Mac OS X Yosemite.

Then, from arm/build/gcc-boot,

../../gcc-47-gpl-2014-src/configure \
 --build=x86_64-apple-darwin13 \
 --target=arm-eabi \
 --prefix=$HOME/local-arm \
 --with-cpu=cortex-m4 \
 --with-fpu=fpv4-sp-d16 \
 --with-float=hard \
 --with-mode=thumb \
 --enable-interwork \
 --enable-multilib \
 --enable-languages="c" \
 --with-system-zlib \
 --with-newlib \
 --with-libgloss \
 --without-headers \
 --disable-shared \
 --disable-nls \
 --with-gnu-as \
 --with-gnu-ld \
 --with-bugurl=URL:mailto:simon@pushface.org

followed by make -j4 all-gcc; make install-gcc

Build newlib

I first applied the newlib-2.1.0 patch from https://github.com/istarc/stm32.git. Then, from subdirectory newlib,

../../newlib-2.1.0/configure \
 --build=x86_64-apple-darwin13 \
 --target=arm-eabi \
 --prefix=$HOME/local-arm \
 --with-cpu=cortex-m4 \
 --with-fpu=fpv4-sp-d16 \
 --with-float=hard \
 --with-mode=thumb \
 --enable-interwork \
 --enable-multilib \
 --with-gnu-as \
 --with-gnu-ld \
 --disable-nls \
 --disable-newlib-supplied-syscalls

followed by make -j4 all; make install.

Rebuild GCC with Ada, C++ and newlib

Iztok says that the final GCC should be built in the same place as the bootstrap without cleaning. I didn't do that; instead, from subdirectory gcc,

../../gcc-47-gpl-2014-src/configure \
 --build=x86_64-apple-darwin13 \
 --target=arm-eabi \
 --prefix=$HOME/local-arm \
 --with-cpu=cortex-m4 \
 --with-fpu=fpv4-sp-d16 \
 --with-float=hard \
 --with-mode=thumb \
 --enable-interwork \
 --enable-multilib \
 --enable-languages="c,c++,ada" \
 --with-system-zlib \
 --with-newlib \
 --with-libgloss \
 --disable-shared \
 --disable-libada \
 --disable-nls \
 --with-gnu-as \
 --with-gnu-ld \
 --with-bugurl=URL:mailto:simon@pushface.org

followed by

  • make -j4
  • make -C gcc cross-gnattools builds gnat*.
  • (This is vital!) make renames gnat* to gnat*-cross
  • make install installs gnat*-cross as arm-eabi-gnat*

Building GDB

From subdirectory gdb,

../../gdb-7.7-gpl-2014-src/configure \
 --build=x86_64-apple-darwin13 \
 --target=arm-eabi \
 --prefix=$HOME/local-arm \
 --enable-interwork \
 --enable-multilib \
 --disable-werror

followed by make -j4 all, make install.

Installing the Zero Footprint (zfp) runtime system

I copied the runtime in lib/gcc/arm-eabi/4.7.4/rts-zfp from the Linux distribution to the new compiler, and made symbolic links in lib/gcc/arm-eabi/4.7.4/ to its adalib, adainclude.

Note, this isn't an RTS that is useful for more than ensuring that tools like gnatls (rather, arm-eabi-gnatls) will accept this as a valid compiler; it needs considerable work to make it fit for use with an STM32F4 device.

Installing the STM32F4 Discovery runtime system

AdaCore supply a runtime system for Ravenscar on the STM32F4 Discovery part in lib/gnat/arm-eabi/ravenscar-sfp-stm32f4.

I don't know why it's there, because as far as I can tell it's not automatically discoverable in that location. I moved it to lib/gcc/arm-eabi/4.7.4/rts-ravenscar-sfp-stm32f4.

Installing the STM32F429I Discovery runtime system

As an old Unix hand, I hadn't been quite prepared for the low-level setup needed for a bare-metal implementation (I have seen some of the innards of VxWorks, but only to recoil in amazement). I'd been expecting the 'STM32F4' mark to indicate commonality in the RTS: no such luck!

Jerry Petrey's ARMed and Ready blog post, and particularly the fifth comment, pointed me to gnat-stm324f29i-disco on github. This runtime system, installed as rts-ravenscar-sfp-stm32f429i-disco, works fine.


More on actually using this compiler later.

No comments:

Post a Comment