Let's make the world a better place using digital technologies!

Howto: Building gcc/g++ toolchain for Motorola Coldfire/M68K Processors (II)

In a previous post, I have described how to make a coldfire toolchain using gcc 4.2.3. In this post, we shall see how we can use the latest cvs trunks to build the toolchain based on latest sources.

You should have ample free space (ca. 3GB) on your hard disk and I assume you are root.

  • Become root
    sudo su
  • Install the tools:
    apt-get install gcc g++ build-essential gcc-3.4 automake autoconf gdb bzip2 texinfo patch flex bison subversion cvs
  • Make required folders:
    mkdir /usr/local/coldfire
    mkdir /usr/local/coldfire/source
    cd /usr/local/coldfire/source
  • Get and build binutils:
    mkdir binutils
    cd binutils
    cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login

    Enter “anoncvs” as password.
    cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
    mkdir build_binutils
    cd build_binutils
    ../src/configure --prefix=/usr/local/coldfire --target=m68k-elf --enable-multilib
    make -j2
    make install
    cd ../..
  • Make and install gmp and mpfr libraries:
    cd /usr/src
    wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.2.tar.gz
    tar -xvf gmp-4.2.2.tar.gz
    cd gmp-4.2.2
    make -j 2
    make install
    cd ..

    wget http://www.mpfr.org/mpfr-current/mpfr-2.3.1.tar.bz2
    bzcat mpfr-2.3.1.tar.bz2 | tar -xf -
    cd mpfr-2.3.1
    make -j 2
    make install
    cd ..

  • Update library configuration:
    depmod -a
  • Download and uncompress latest gcc sources, at the time of writing:
    wget ftp://ftp.mpi-sb.mpg.de/pub/gnu/mirror/gcc.gnu.org/pub/gcc/snapshots/4.3.1-RC-20080523/gcc-4.3.1-RC-20080523.tar.bz2
    bzcat gcc-4.3.1-RC-20080523.tar.bz2 | tar -xf gcc-4.3.1-RC-20080523.tar.bz2
  • Get newlib and link to gcc:
    mkdir newlib
    cd newlib
    cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src co newlib

    Enter "anoncvs" as the password.
    cd ../gcc-4.3.1-RC-20080523
    rm -rf newlib
    ln -s ../newlib/src/newlib newlib
    cd ..
  • Make and install gcc:
    mkdir build_gcc
    cd build_gcc
    export LD_LIBRARY_PATH=/usr/local/lib

    Configure the toolchain:
    ../gcc-4.3.1-RC-20080523/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=m68k-elf \
    --disable-libmudflap --disable-libssp --disable-libgomp --enable-threads \
    --enable-languages=c,c++ --disable-checking --disable-shared --with-newlib \
    --with-bugurl=http://deneb.homedns.org/things --with-pkgversion=HIRTS-0.1 \
    --disable-nls --prefix=/usr/local/coldfire --enable-poison-system-directories \ --with-build-time-tools=/usr/local/coldfire/bin

    Make and install the toolchain (can take ca. 1 hour on most computers!):
    make -j4
    make install

  • Add the tools to your path:
    emacs /etc/profile
    Add /usr/local/coldfire/bin to the end of PATH
    Press C-x C-s to save, C-x C-c to exit. Enter:
    source /etc/profile
    to load the new path information.
    This will add it to all the users' path except root. If you want to add it to root's path as well, you need to edit .bashrc file in /root folder by adding the following:
  • Check the toolchain:
    m68k-elf-gcc -v
    Using built-in specs.
    Target: m68k-elf
  • Compile a simple hello world program:
    cd /tmp
    emacs hello_world_m68k.c

    Enter the following simple program:
    #include <stdio.h>
    int hello_world (int argc, char *argv[])
    int i;
    printf ("Hello World\n");
    return (0);

    Press C-x C-s to save and C-x C-c to exit
    Compile the program:
    m68k-elf-gcc -g -c -mcpu=5282 hello_world_m68k.c

Feedback/comments are welcomed.



View more posts from this author
One thought on “Howto: Building gcc/g++ toolchain for Motorola Coldfire/M68K Processors (II)
  1. Jonathan

    Just found your tutorial, very helpful (I’ve searching for one for almost a week) …

    Anyway, just to give a hint for anyone who would use it, on the configure for gcc :
    ../gcc-4.3.1-RC-20080523/configure –build=i686-pc-linux-gnu –host=i686-pc-linux-gnu –target=m68k-elf \
    –disable-libmudflap –disable-libssp –disable-libgomp –enable-threads \
    –enable-languages=c,c++ –disable-checking –disable-shared –with-newlib \
    –with-bugurl=http://deneb.homedns.org/things –with-pkgversion=HIRTS-0.1 \
    –disable-nls –prefix=/usr/local/coldfire –enable-poison-system-directories \ –with-build-time-tools=/usr/local/coldfire/bin
    be sure to add a newline before the option –with-build-time-tools (to consume the \) or it will fail with “configure: invalid variable name: –with-build-time-tools”

    Or just don’t copy/paste as I did …

    Thanks anyway for this how to (hope it will finsh though, it is still in make process …)


Leave a Reply

Your email address will not be published. Required fields are marked *