These notes describe building GCC 5.1.0 for the Cortex M4 on Mac OS X.
My target board is the STM32M4F29I Discovery.
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 GCC 5.1.0, built as described here. The sources from that build were still present; no further change was required.
Additional libraries used were
- binutils-2.24.tar.gz
- newlib-2.1.0.tar.gz
from their home sites, and
- gdb-7.7-gpl-2014-src.tar.gz
from AdaCore Libre.
I install the cross-environment components 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=/usr/local/gnat/5.1.0/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 build/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 make make install
Build GCC without any libraries
From subdirectory build/gcc-boot,
../../../gcc-5.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 \ --enable-languages="c" \ --with-system-zlib \ --with-newlib \ --with-libgloss \ --without-headers \ --disable-shared \ --disable-nls \ --with-gnu-as \ --with-gnu-ld \ --with-stage1-libs=no \ --with-stage1-ldflags=no \ --with-boot-libs=no \ --with-boot-ldflags=no \ --with-bugurl=URL:mailto:simon@pushface.org 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 build/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 make -j4 all make install
Rebuild GCC with Ada, C++ and newlib
From subdirectory build/gcc,
../../../gcc-5.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 \ --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-stage1-libs=no \ --with-stage1-ldflags=no \ --with-boot-libs=no \ --with-boot-ldflags=no \ --with-bugurl=URL:mailto:simon@pushface.org make -j4 make -C gcc cross-gnattools ada.all.cross Make install
Configuring with --disable-libada and the make -C gcc cross-gnattools ada.all.cross is the Right Way to build a cross-compiler; arrived at after much pain, see PR64492.
The --with-stage1-libs=no and --with-stage1-ldflags=no, together with the previously-applied gcc-5.1.0.diff patch, are a workround for PR61027.
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 make all -j4 cd gdb make install
Installing a dummy runtime system
In order for tools like gnatls (rather, arm-eabi-gnatls) and gprconfig to accept this as a valid compiler there must be something that they recognise as a run time system. At present, the minimum needed is
- a file ada_source_path containing the relative pathname of a directory adainclude containing
- a file system.ads
- a file ada_object_path containing the relative pathname of a directory adalib, which can be empty.
A suitable dummy is available on Sourceforge; I copied it, retaining the directory structure, to $HOME/local-arm/lib/gcc/arm-eabi/5.1.0.
Real STM32F429I Discovery runtime system
See the Cortex GNAT Run Time Systems project at Sourceforge.
No comments:
Post a Comment