13 Jan 2014

Building gcc-arm-embedded on openSUSE 13.1

Ideally, if you were to start a Cortex-M-based development project today, you'd simply download the "latest and greatest" from GCC, build a cross-compiler targetting your device/CPU, and get coding. The reality, unfortunately, is that the latest improvements to GCC to support the latest CPUs tend to be found outside the latest GCC releases (as they await inclusion and/or the next release).

Over time, the "preferred" GCC compiler to use for Cortex-M development changes. Originally everyone used the compilers from CodeSourcery (now Mentor). Then the summon-arm-toolchain (SAT) became quite popular[1]. But even the people behind it have moved on to the current GCC compiler du jour: gcc-arm-embedded. The gcc-arm-embedded toolchain does seem to have good backing, as it is maintained by ARM employees.

In my experience (and, according to the download statistics) most people prefer to download pre-build binaries and simply install them into their system. If you're like me, however, you prefer to compile the toolchain yourself... just for fun.

The sources for every release of the gcc-arm-embedded are readily available. Unfortunately the tarballs of each of the components of the toolchain are themselves wrapped up in a mega-tarball. So if you download, for example, the source to the 4.8-2013-q4 release and unpack it, you'll end up with more tarballs (for each of the components) and a set of home-brew bash build scripts. The problem with not making the sources for each component available separately is that it becomes harder to integrate these sources into existing embedded development frameworks (such as OE, crosstool-ng, buildroot, etc).

Surprisingly, the verified build environment is a 32-bit Ubuntu 8.10 host! In any case,  using the provided "home-brew" bash build script works reasonably well for me on my 64-bit openSUSE 13.1 machine. Ironically, the only places where my build messes up is when it's trying to build the documentation. Building the documentation is fairly pointless, and wastes time and disk space.

Starting from a fresh, basic, default install of 64-bit openSUSE 13.1, the steps I use to build the 4.8-2013-q4 release of gcc-arm-embedded are as follows. Make sure, before starting, you have roughly 20GB of hard disk available.

$ sudo zypper -n install \
        autoconf \
        m4 \
        automake \
        libtool \
        patch \
        make \
        makeinfo \
        flex \
        bison \
        termcap \
        ncurses-devel \
        mpfr-devel \
        gmp-devel \
        mpc-devel \
        gcc-c++

<enter password>
$ wget https://launchpad.net/gcc-arm-embedded/4.8/4.8-2013-q4-major/+download/gcc-arm-none-eabi-4_8-2013q4-20131204-src.tar.bz2
$ bzip2 -d < gcc-arm-none-eabi-4_8-2013q4-20131204-src.tar.bz2 | tar xfv -
$ cd gcc-arm-none-eabi-4_8-2013q4-20131204/src
$ find . -name "*tar*" -print | xargs -I% tar -xvf %
$ cd zlib-1.2.5
$ patch -p1 < ../zlib-1.2.5.patch
$ cd ../..
$ ./build-prerequisites.sh --skip_mingw32 2>&1 | tee LOG.prereq


At this point you need to apply the patch provided below to the build-toolchain.sh script. The point of this patch is to turn off the building of the documentation. Find the patch below (between the dashed lines) save it to a file named build.patch, then carry on with the following instructions:

$ patch -p1 < build.patch
$ ./build-toolchain.sh --ppa --skip_mingw32 2>&1 | tee LOG.toolchain

The above should complete without issue. You'll find your results in the "install-native" folder. Be sure to add "~/gcc-arm-none-eabi-4_8-2013q4-20131204/install-native/bin" to your PATH so you can start using your freshly-built toolchain.

Enjoy!



patch:
-----------------------------------------
 --- old/build-toolchain.sh      2013-12-03 13:52:00.000000000 -0500
+++ new/build-toolchain.sh      2014-01-12 14:39:12.490232430 -0500
@@ -133,7 +133,7 @@
     make -j$JOBS
 fi

-make install install-html install-pdf
+make install

 copy_dir $INSTALLDIR_NATIVE $BUILDDIR_NATIVE/target-libs
 restoreenv
@@ -212,16 +212,6 @@

 make install

-make pdf
-mkdir -p $INSTALLDIR_NATIVE_DOC/pdf
-cp $BUILDDIR_NATIVE/newlib/arm-none-eabi/newlib/libc/libc.pdf $INSTALLDIR_NATIVE_DOC/pdf/libc.pdf
-cp $BUILDDIR_NATIVE/newlib/arm-none-eabi/newlib/libm/libm.pdf $INSTALLDIR_NATIVE_DOC/pdf/libm.pdf
-
-make html
-mkdir -p $INSTALLDIR_NATIVE_DOC/html
-copy_dir $BUILDDIR_NATIVE/newlib/arm-none-eabi/newlib/libc/libc.html $INSTALLDIR_NATIVE_DOC/html/libc
-copy_dir $BUILDDIR_NATIVE/newlib/arm-none-eabi/newlib/libm/libm.html $INSTALLDIR_NATIVE_DOC/html/libm
-
 popd
 restoreenv

@@ -302,7 +292,7 @@
   make -j$JOBS INHIBIT_LIBC_CFLAGS="-DUSE_TM_CLONE_REGISTRY=0"
 fi

-make install install-html install-pdf
+make install

 pushd $INSTALLDIR_NATIVE
 rm -rf bin/arm-none-eabi-gccbug
@@ -400,7 +390,7 @@
     make -j$JOBS
 fi

-make install install-html install-pdf
+make install

 restoreenv
 popd

-----------------------------------------



[1] Note: the SAT isn't really a toolchain in the same way the others are toolchains, technically the SAT is just a home-brew bash script to create an ARM toolchain based on the Linaro toolchain releases.

No comments: