HOW TO BUILD A BASIC TOOL CHAIN
BUILT UP FROM GROUND
In the next few sections, we're going to set up an compiler, runtime library, assembler, linker and debugger that can be used to produce and run applications for the TX3912 development board. We'll subsequently prove that by building and testing a simple, "hello, world!"-style application on the TX39 microprocessor.
The first step in the process is to get the materials we need. The instructions will assume that you are working in one of two host environments: either a Linux or other unix-like workstation, or on a Win32 PC (preferably Windows NT) running a unix emulation environment called Cygwin. The resources section at the end of this article tells where you can find and download the Cygwin package. Use the ALL install installation setup.
If you are trying to run Cygwin on Windows 95 or 98, expect to have some difficulty completing the procedure we're about to start. These two operating systems are buggy enough that Cygwin cannot provide a solid unix-like emulation for reliably building GNU tools, so when things start to look strange you will have to reboot and try again. Once you get the tools built, however, they run fine on these machines.
Figure 1 lists the files you will need, and where to download them from. Note that there will probably be later versions of each of these packages by the time you get around to downloading them. Stick with the listed versions until you've completed the process at least once, because updates occasionally change the installation procedure.Note also that if you use Internet Explorer to download these, then you *must* right-click on the download link and select "Save Link As"--- Internet Explorer often has trouble with files in the GNU tar format, and will corrupt them if you let it. If you are using Cygwin and cannot find the downloaded files after you download them, then use Explorer to download again or move them into a directory like c:\cygwin\home\adminstrator (substitute administrator for your username, if necessary), which will put them in Cygwin's "home directory", which should be right where you can find them when you type *ls* from the Cygwin shell's command prompt.
binutils-2.12.tar.gz http://sources.redhat.com/binutils
gcc-2.95.2.tar.gz http://gcc.gnu.org
newlib-1.10.0.tar.gz http://sources.redhat.com/newlib
gdb-5.2.tar.gz http://sources.redhat.com/gdb

The binutils package includes the GNU assembler and linker, and the gcc package contains the GNU C/C++ compiler. Newlib is the C runtime library we will use to supply functions like printf(), and the gdb package contains the GNU debugger.

Setting up the build environment

The first thing to do is set up a directory structure in which to build and install the tools. Then, set up some environment variables that will save typing later, as well as make sure that the arguments used during the configuration process are consistent throughout--- a source of common errors. Figure 2 describes the commands, just type them in as they appear there (omit the leading '$', which represents the Cygwin or unix command prompt).

$ mkdir /src/binutils
$ mkdir /src/gcc
$ mkdir /src/newlib
$ mkdir /src/gdb
$ gunzip < /src/binutils-2.12.tar.gz | tar xvf -
$ gunzip < /src/gcc-2.95.2.tar.gz | tar xvf -
$ gunzip < /src/newlib-1.10.0.tar.gz | tar xvf -
$ gunzip < /src/gdb-5.2.tar.gz | tar xvf -
$ mount -f -b d:/cygwin/tmp /tmp
$ export MAKE_MODE=UNIX
Cross-making
Also we need to prepare some dirctories:
$ mkdir /tmp/build/binutils
$ mkdir /tmp/build/gcc
$ mkdir /tmp/build/newlib
$ mkdir /tmp/build/gdb

First of all, we have to build up binutils ...

Since gcc calls archiver, linker, and assembler.

All of GNU compliant tools are initially configured by "configure script" and it aytomatically creates a Makefile optimised for the host environment. There are two essential configure options, --target and --prefix.

  • --target
  • --prefix

--target specifies CPUs for output codes and --prefix tells make where the binaries, man files, headers, and libraries will be installed. The abbrebiation of Toshiba TX39 processor is "mipstx39-elf" ; GNU family currently supports many platforms). I assigned /tools2.95.2 to --prefix and executable files will be installed in /tools2.95.2/bin/.

NOTICE: There are several abbreviation for the TX39 CPU, but they have different ABI types, so make sure what kind of ABI do you need. Here we use a "mipstx39-elf" target. (Also there is a "mips-tx39-elf" target).

NOTICE: You should perform builds in a directory out of the source tree. In this case, you can create multiple binaries (H8/300H, x86, MIPS, ARM, and so on) using single source directory.

The commands to configure and install the assembler and linker are shown Figure 3. These commands do the following:

  • Run the configure script included with the binutils package, to set up the source code to build for the MIPS target.

  • Invoke the make program to actually compile the and install binutils. The output from make is captured and stored in the file make.log.

When this process finishes, you will see a number of programs in $/tools2.95.2/bin.

The assembler is mipstx39-elf-as,and the linker is mipstx39-elf-ld. mipstx39-elf-objcopy is a utility that can translate files to different formats (from ELF to S Record, for example), and mipstx39-elf-objdump is a utility that can dissect the components of a file, to show you things like symbol addresses and a disassembly of the file's object code. We'll discuss these utilities later.

Lastly, +++++ DO NOT forget to update PATH environment variable, because gcc calls cross-compiled binutils tools in next step (if you forget it, gcc complains "mipstx39-elf--ar is not found").
NOTICE: CFLAGS is defined as "-g -O2" in original Makefile, and the "-g" option force the executable files to be enlarged so much. You can ignore this option by inserting CFLAGS="-O2" in make command line. I forgot to do this in the "binutils" step. Then I got much larger files. You don't forget this!

Building a bootstrap cross compiler

Now that we have an assembler and linker, we can build and install the GNU C/C++ compiler. The first step in the procedure yields a bootstrap compiler that can only be used to build runtime libraries and header files; we will use this compiler to build the mipstx39-elf version of the newlib C runtime library. Once that's complete, we will rebuild the compiler completely, including internal libraries that need target-specific header files from newlib in order to be compiled properly.

The commands to make the boostrap compiler are shown in Figure 4. Do them now.

NOTICE: Here we used some GNU options while configuring. The "--with-gnu-as" and "--with-gnu-ld" option indicate the HOST compiler to use the NATIVE gcc assembler and linker while compiling. Otherwise, the HOST compiler will use the cross-assembler and cross-linker that we just generated to compile the cross-gcc. It will suppose that you are doing native compiling under a MIPS HOST.

There are two additional configure options you should consult.

  • --with-newlib
  • --with-headers

glibc is too huge and complex for small systems, so we have to choice another compact C library. newlib is one of the most hard-tested library, and gcc can be adopted for it by --with-newlib option. In this case, you have to specify --with-headers option. gcc itself creates libgcc.a and libiberty.a libraries, and standard include files are required for their compilation. Standard headers files for newlib are collected in its source tree (newlib/libc/include/).

NOTICE: --with-headers option is very important one for cross-making. Do not forget it!

Default Makefile produces codes for C++, JAVA, Fortran77, and Chill in addtion to ANSI C. Since almost of us do not need these optional languages, let's ignore them by using --enable-languages option (C is essential and we can not exclude it). (--Oops, I forgot this in this compilation!)

As described above, we should ignore "-g" option (CFLAGS="-O2") and limit supporting languages to C and C++ (LANGUAGES="c c++"). Be careful, please specify LANGUAGES option in both of "make" and "make install".

NOTICE: Not all the gcc version can be made through without any error. Because there are many complex libraries and include files, it's common that there maybe some omitted parameters for some special targets. For example, here we can build the whole tools chain using the gcc-2.95.2 with a "mipstx39-elf" target. But it can't work with gcc-3.1.
At this point we have a bootstrap compiler called mipstx39-elf-gcc, located in /tools2.95.2/bin/. Now we'll build newlib, then return to finish building gcc.

Building the newlib C runtime library

The procedure, shown in Figure 5, should seem pretty familiar by now.

make all install

Some hints, if you didn't export the target binary files path correctly, the following setting is necessary.

make all install \
>CC_FOR_TARGET=/tools2.95.2/bin/mipstx39-elf-gcc \
>AS_FOR_TARGET=/tools2.95.2/bin/mipstx39-elf-as \
>LD_FOR_TARGET=/tools2.95.2/bin/mipstx39-elf-ld \
>AR_FOR_TARGET=/tools2.95.2/bin/mipstx39-elf-ar \
>RANLIB_FOR_TARGET=/tools2.95.2/bin/mipstx39-elf-ranlib

Building a complete cross compiler

Now that we have MIPS header files and libraries from newlib, we can build a complete cross compiler setup for C/C++ development. The steps are shown in Figure 6.

This procedure will take longer time than the bootstrap compiler.

Building the debugger

Are we there yet? Almost. The last step in the setup process is to build and install the debugger. The procedure is shown in Figure 7.

Like most GNU programs, the GNU debugger is under constant development, and sometimes is released with minor issues that affect one or two of its many supported targets. When such problems are resolved, a patchfile is usually released that contains just the differences between the updated version and the original version; this lets you get the improvement by downloading just a few bytes of data, instead of downloading the whole package again.

The patchfile is plaintext; you can easily read it with a text editor to see the changes it contains. In fact, that's exactly what the patch program does.

If you run out of disk space

All told, you will need about 500MB of free disk space in order to build a complete GNU cross development environment. But you don't that much all at once: if space is tight, you can delete the files left at the end of each step in the procedure before you move on to the next step. For example, once you finish building the cross assembler and linker, you can delete the contents of the /tmp/build/binutils directory.

The installed tool set requires less than 100MB of disk space.

Next, we will use these tools to creat our first project...