main page
download
manual
FAQ
t-shirt contest
research notes
data sheets
schematics
hardware mods
mailing lists
IRC
tools
photos
daily builds
CVS
sourceforge
bug reports
feature requests
linux driver


Building the SH1 cross compiler

In this example I will assume that you are running Linux with the bash shell. We will only build the C compiler along with the assembler, linker and stuff. Note that the procedure is exactly the same if you are running cygwin on Windows.

Download the source code

You will need the following archives:

  • binutils-2.11.tar.gz (find it at your closest GNU FTP site)
  • gcc-3.0.4.tar.gz (find it at your closest GNU FTP site)
  • (optional) gdb-5.1.1.tar.gz (find it at your closest GNU FTP site)

If you want to stay out of trouble, use the versions stated above. If you want to live on the edge you can try building with the latest versions. However, if you use binutils-2.13 or later you will not be able to build Rockbox older that CVS 2002-09-08 if you don't add the .rodata.str1.4 section to the .rodata section in the linker script:

    .rodata :
    {
        *(.rodata)
        *(.rodata.str1.4)
    } > DRAM

Unpack the archives

 /home/linus> tar zxf binutils-2.11.tar.gz
 /home/linus> tar zxf gcc-3.0.4.tar.gz
 /home/linus> tar zxf gdb-5.1.1.tar.gz

Create the directory tree

 /home/linus> mkdir build
 /home/linus> cd build
 /home/linus/build> mkdir binutils
 /home/linus/build> mkdir gcc
 /home/linus/build> mkdir gdb

Choose location

Now is the time to decide where you want the tools to be installed. This is the directory where all binaries, libraries, man pages and stuff end up when you do "make install".

In this example I have chosen "/home/linus/sh1" as my installation directory, or prefix as it is called. Feel free to use any prefix, like /usr/local/sh1 for example.

Build binutils

We will start with building the binutils (the assembler, linker and stuff). This is pretty straightforward. We will be installing the whole tool chain in the /home/linus/sh1 directory.

 /home/linus> cd build/binutils
 /home/linus/build/binutils> ../../binutils-2.11/configure --target=sh-elf --prefix=/home/linus/sh1
 /home/linus/build/binutils> make
 /home/linus/build/binutils> make install

Build GCC

Now you are ready to build GCC. To do this, you must have the newly built binutils in the PATH.

 /home/linus> export PATH=/home/linus/sh1/bin:$PATH
 /home/linus> cd build/gcc
 /home/linus/gcc> ../../gcc-3.0.4/configure --target=sh-elf --prefix=/home/linus/sh1 --enable-languages=c
 /home/linus/build/gcc> make
 /home/linus/build/gcc> make install

Build GDB

If you are planning to debug your code with GDB, you have to build it as well.

 /home/linus> export PATH=/home/linus/sh1/bin:$PATH
 /home/linus> cd build/gdb
 /home/linus/gdb> ../../gdb-5.1.1/configure --target=sh-elf --prefix=/home/linus/sh1
 /home/linus/build/gdb> make
 /home/linus/build/gdb> make install

Done

If someone up there likes you, you now have a working tool chain for SH1. To compile a file with gcc:

 /home/linus> sh-elf-gcc -c main.o main.c
Good luck!

Linus


Page was last modified "Sep 8 2002" Björn Stenberg