Building a Motorola (ColdFire) uClinux toolchain for Mac OS X

 

UNIX logo

There is a m68k-elf-gcc toolchain available from DarwinPorts based on gcc3.4.3 but unfortunately, it doesn't contain the Coldfire patches and other goodies that are needed to work well with uClinux and surprisingly, all the available toolchains for OS X seem to be somewhat unavailable for download!

My various attempts to build this cross compiler ended up saving the day at a recent Internet Exchange Research workshop. We didn't have a compiler for our Sparc servers, they didn't have any CD-ROM drives, and the Internet connection was too slow. Fortunately, I had everything needed on my PowerBook (I'm a packrat like few others) and I was able to build a Sparc cross-compiler hosted on Darwin PPC.

That bit of success gave me a much needed shot in the arm to finish up the build of the Coldfire cross-compiler. It took almost 24 hours to build it (including the various stops and rebuilds needed to make it compile cleanly), clearly not a job for the faint hearted, or those who give up easily.

DOWNLOADS

You can get binaries of the toolchain for Mac OS X 10.4.4 (PowerPC) from (the links below don't work since I haven't uploaded the files. I'm looking for a place to host them since I have a bandwidth limit)

http://sohne.net/files/m68k-uclinux-tools-base-gcc3.4.0-20060213.sh [13M]
http://sohne.net/files/m68k-uclinux-tools-c++-gcc3.4.0-20060213.sh [25M]
http://sohne.net/files/m68k-uclinux-tools-gdb-20060213.sh [2M]

I'm looking for a better place to host these files. Ideas?

GETTING SOURCES

You'll need Bernardo Innocenti's sources.

It's probably wise to choose the most recent version of his sources, and hope for the best. Stick to the exact version of each source required (e.g. gcc 3.4.0 != gcc 3.4.3). I tried 3.4.3 but it crashed inside xgcc due to my incompetence at patching the sources.

BUILDING YOUR OWN

Your experience may differ from mine. What I do know is that building this takes quite some time and you won't enjoy doing it again and again to fix problems (unless that's your sort of fun!)

Before building, install DarwinPorts and

    sudo port install coreutils
sudo port install gsed
sudo port install gexpr

sudo ln -s /opt/local/bin/gcp /opt/local/bin/cp
sudo ln -s /opt/local/bin/gnused /opt/local/bin/sed

export PATH=/opt/local/bin:$PATH

sudo gcc_select 3.3

Start the build process by editing the build-uclinux-tools.sh script as per your needs. I used Apple gcc 3.3 with the following settings in build-uclinux-tools.sh …

    TARGET=m68k-elf
PREFIX=/usr/local/m68k-uclinux-tools
BINUTILSVERS="2.14.90.0.8"
GCCVERS="3.4.0"
GDBVERS="6.1"
BDMVERS="1.3.0"
UCLIBCVERS="0.9.26"
ELF2FLTVERS="20040326"
ROOTDIR="${BASEDIR}/uClinux-dist"
KERNEL="${ROOTDIR}/linux-2.4.x"

After setting up the build-uclinux-tools.sh script and downloading the necessary additional files and patches, you can do

    cd where-ever-your-buildroot-is
sh build-uclinux-tools build

and each time you encounter an error (and hopefully fix what's causing it) you can do

    sh build-uclinux-tools continue

BUILD ERRORS (AND SOLUTIONS)

You're going to run into various errors during the build. These steps document how I managed to get past them. There are probably mistakes in them, or at least better ways to do them. Suggestions and improvements are most welcome. It should be easy to make this into a patch. Maybe I'll do that the next time around, but it took so long to build that I wouldn't hold my breath for it.

Configuring the uClinux kernel

You'll receive a message saying

        expr: syntax error
KERNELRELEASE "2.4.32-uc0" exceeds 64 characters

You should edit linux-2.4.x/Makefile and change all occurrences of expr to gexpr …

Building elf2flt-20040326

You'll get an error saying 「elf.h not found」 (it's not present on Darwin systems)

     cp uClibc-0.9.26/include/elf.h elf2flt-20040326
cp uClibc-0.9.26/include/elf.h binutils-2.14.90.0.8/include/

Edit elf2flt-20040326/elf.h and uncomment the #include line

During linking, you'll get an error saying crt0.a not found. Edit Makefile.in, change

         LDFLAGS = @LDFLAGS@ -static
to
         LDFLAGS = @LDFLAGS@ 

And that should take care of it for you. Continue building via

    sh build-uclinux-tools continue    

Building m68k-bdm-1.3.0

This will fail because BDM hardware access hasn't been written for Darwin yet. The ioperm system call is missing, and there's no native driver, so edit build-uclinux.tools.sh and in the stageA function, replace the following lines

    --with-libiberty=${BASEDIR}/${TARGET}-binutils/libiberty/libiberty.a 
${PREFIXOPT}

with the lines below

--with-libiberty=${BASEDIR}/${TARGET}-binutils/libiberty/libiberty.a 
--disable-ioperm --disable-driver
${PREFIXOPT}
i.e. add—disable-ioperm and—disable-driver to the configure stanza.

Building m68k-bdm-1.3.0

This will fail again since its trying to build a static executable. Apparently, that's a no-no on Darwin. Edit Makefile.in and Makefile.am in the utils directory and remove the static lurking as below:

    bdmctrl_LDFLAGS = -static

should be changed to

    bdmctrl_LDFLAGS =

You should be still able to connect to a remote server that's running BDM. Since I'm running on a Powerbook, which doesn't even have a parallel port, it's not a big deal to not build the hardware interface bits of BDM. Your mileage may vary. You should be able to continue your build now.

Building gdb-6.1

You will receive an error due to an incorrect gdb.texinfo file. Edit gdb-6.1/gdb/doc/gdb.texinfo and around line 6961 (or whatever makeinfo complained about) and change

    @strong{Note:} a trace experiment and data collection may stop
automatically if any tracepoint's passcount is reached
(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.

to become

    Note: a trace experiment and data collection may stop
automatically if any tracepoint's passcount is reached
(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.

After this, you should have a successful build. All the tools will be installed on your system by Bernardo's excellent build script.


arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()