Creating a New Crosscompiler for WowWee RSMedia C or C++ Development

This article shows how I finially built a new compiler toolchain for RSMedia development.  It took a lot of trial and error to find a process that worked, so by documenting the results here I hope I can save someone some pain in the future!!

So these instructions maybe interesting to others wanting to build a cross compilers for other robot or embedded targets.

Background

A new compiler toolchain?  Why do we need that?

Most of RSMedia C code development/hacking is currently done using the compiler that comes with the Redhat7.3 VMware image from freescale (see here).

It works OK, but has two limitations:-

  1. The VMware image is command line only. (So you can’t run X or any nice Gui windows or editors)
  2. Using this compiler we cannot link against the shared libraries that are already embedded in the robot.

   (see Appendix A for details of the libraries and why we can’t link against them.)

But, if I could build a new crosscompiler, we could solve both these issues. 

Building a new compiler with 'Crosstool'

I looked at using Crosstool by Dan Kegel. Crosstool is a set of Unix scripts that build crosscompilers on a Linux system.

See http://kegel.com/crosstool/ for all the details.

Building crosscompilers by hand is difficult work. But Crosstool promised to take most of the hard work out - and it (mostly) lived up to this claim.

Crosstool does (at least) these tasks- download the sources needed, extract them ,patch them as necessary, build the compiler, build the required libraries, even package the resulting compiler toolchain into a distributable package.

By editing basic configuration scripts you tell Crosstool what version of compiler and libraries you want to build and most importantly what platform we want to build them for.

So I did have to try quite a few things to get it to build successfully for exactly what we needed for RSMedia.  In short I tried compiling old and new compiler versions on Ubuntu 8.04 & 8.10 Linux , but I could not get it to work.  I tried compiling old compiler versions on the Redhat 7.3 Linux , but I could not get it to work.

However, I eventually found that building a newer set of tools on the older Redhat 7.3 Linux did work. (See appendix B for more details of what didn’t work and why.)

The working set of instructions

(This created a gcc version 3.3.6 compiler on RedHat Linux 7.3.)

Crosstool requires bison, flex and patch to be installed. (I looked up the correct versions from a list of Redhat 7.3 rpms at http://cf.ccmr.cornell.edu/docs/instructions/redhat-73.html)

Then I downloaded the following packages from ftp://194.126.159.4/pub/linux/redhat/7.3/i386/RedHat/RPMS/

  • bison-1.35-1
  • flex-2.5.4a-23
  • patch-2.5.4-12

Then installed them like this:

su
rpm -ivh bison-1.35-1
rpm -ivh flex-2.5.4a-23
rpm -ivh patch-2.5.4-12
exit  

Download and install Crosstool

Get it from http://kegel.com/crosstool/crosstool-0.43.tar.gz

The full set of instructions for Crosstool are here http://kegel.com/crosstool/crosstool-0.43/doc/crosstool-howto.html

The steps I performed were

1.  Copy the crosstool-0.43.tar.gz file to to ~

cp crosstool-0.43.tar.gz ~
cd ~
tar -xzvf crosstool-0.43.tar.gz

cd crosstool-0.43 

2.  Modify the Crosstool config scripts:-

vi demo_arm_softfloat.dat

3.  Ensure that the only 'eval' line enabled is the one below (all other 'eval' lines should start with#)

eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest

vi arm-softfloat.dat
//Add these lines into the file
GCC_CORE_EXTRA_CONFIG="--with-float=soft"GLIBC_EXTRA_CC_ARGS="-msoft-float"  

su        //Goto root user

mkdir /opt/crosstool

chown $USER /opt/crosstool

exit        //Leave root user

sh demo-arm-softfloat.sh    //Starts the scripts to do it all!!

When it all completes (in a few hours!!) the new compiler toolchain is at /opt/crosstool/gcc-3.4.5-glibc-2.3.6/arm-softfloat-linux-gnu/bin

The new GCC compiler is called arm-softfloat-linux-gnu-gcc

I suggest to create a softlink to the bin directory like this:

ln -s /opt/crosstool/gcc-3.4.5-glibc-2.3.6/arm-softfloat-linux-gnu/bin /opt/crosstool/bin

Then add /opt/crosstool/bin to the $PATH environment variable.  (can be done by export PATH=$PATH:/opt/crosstool/bin)

To use the compiler, use the name arm-softfloat-linux-gnu-gcc from the command line or from a Makefile.

This compiler can now be used to compile any RSMedia programs (including linking to RSMedia shared libraries) and can also be moved/copied to other linux distributions.

The Final Versions

A new compiler version has been released in the RSMDev1.4.tgz archive at https://sourceforge.net/projects/rsmediadevkit/files/.  This version is a hardfloat version - it can be used to create RSMedia compatible programs.(But it cannot compile programs that link against RSMedia linux libraries. )  The version in RSMDev1.4.tgz comes with an install script that should install it to any linux distribution.

In the near future a 'softfloat' version of the compiler (made with the exact instructions above) shouldbe released in RSMDev1.5.tgz at https://sourceforge.net/projects/rsmediadevkit/files/

APPENDIX A

The Linux shared libraries already included in RSMedia were compiled with 'software FP'. This means that the libraries expect that the CPU they are running on does NOT support floating point arithmetic. The libraries expect that float point emulation is used. This means that floating point calculations will be done by software functions (instead of the CPU hardware).

Unfortunately the 'software FP' also means that any programs that want to also use these libraries must also support 'software FP'. 

So in summary to link to the RSMedia shared libraries we need a compiler that can compile code with 'software FP'.  The really annoying thing is that the CPU in the RSMedia robot DOES support Floating point calculations, so compiling the libraries with 'Software FP' was unnecessary.

How do you tell if a library or binary was compiled with 'Software FP' support?

Answer: Use the objdump tool (in the bin directory of the compiler) with the -x parameter to tell it to dump headers.

eg 'arm-linux-objdump -x libnano-X.so'

Look for the private flag area and it will list 'software FP' if it requires softfloat.

How do we compile a program to include softfloat?

Answer: If the compiler defaults to using hardfloat then on the GCC command line add '-msoft-float'.

eg gcc -msoft-float hello.c

But if the compiler was not setup to support softfloat it will likely ask for a libfloat library. (I never managed to find a libary that would successfully work.)

If the compiler was setup for softfloat and hardfloat then it should link OK.

If the compiler default to softfloat then you dont need to add the -msoft-float to the command line. BTW -The Crosstool softfloat compiler will default to softfloat, so you shouldn’t need to add -msoft-float to the command line.

APPENDIX B

I tried these combination of Crosstool but could not get them to work:-

               Host = Redhat 7.3

               Target = arm

               Config = arm-softfloat.dat gcc-3.2.3-glibc-2.3.2.dat

                OR arm-softfloat.dat gcc-3.3.6-glibc-2.3.2.dat

Older versions of the tool chain would compile but the libgcc versions were not softfloat.

This would cause a link error when any program was linked to an executable.

(I assumed this was due to poor support for GCC_CORE_EXTRA_CONFIG="--with-float=soft" or GLIBC_EXTRA_CC_ARGS="-msoft-float" in the early libraries).

I tried these combination of Crosstool but could not get them to work:

               Host = Ubuntu 8.04

               Target = arm

               Config = arm-softfloat.dat gcc-3.2.3-glibc-2.3.2.dat

                OR arm-softfloat.dat gcc-3.3.6-glibc-2.3.2.dat

                OR arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat

No versions worked on Ubuntu - it would crash out during the build with lots of errors. I never managed how to fix the errors.

Cheers, Helibot