Cross-developmental environment for Hitachi H8 microprocessor family
These instructions are taken from those supplied here but modified for the GCC 4.x compiler and using ELF objects.
It explains how to build a cross development environment on Linux/Cygwin. These instructions have been verified on Fedora Core 4 and Cygwin but should work on other flavours of Linux.
The Cygwin set is available h8.tar.bz2 (15Mb).
It was built using the following versions of these components
- binutils-2.16.1
- gcc-4.0.1
- newlib-1.13.0
cd /tools tar jxf h8.tar.bz2 PATH=/tools/h8/bin:$PATH
Introduction
To create an executable file for target CPUs, we need assembler, compiler, library, and linker. GNU provides powerful tool set, binutils (binary utilities) and gcc, which can generate object codes targetting diverse CPUs. GNU also presents a C library (glibc), but it is so huge and not suitable for embedding systems. So, I recommend yout to utilize newlib instead of glibc. In addition, there is a nice and sophisticated debugger, gdb, for helping software development (surprisingly, gdb simulates the H8 processor!).
Getting source codes
The lastest bundles of each of these tools can be found on the tools home page, if you want the latest and greatest source then you may follow the CVS checkout procedures for each of these components.
binutils (GNU)
- http://www.gnu.org/directory/binutils.html - binutils Homepage
- http://ftp.gnu.org/gnu/binutils/ - Downloads from here
% cd /usr/src % mkdir cvs-binutils % cd cvs-binutils % cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login {enter "anoncvs" as the password} % cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
gcc (GNU)
- http://gcc.gnu.org - GCC Homepage
- http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/gcc/ - downloads from here
% cd /usr/src % mkdir cvs-gcc % cd cvs-gcc % cvs -z 9 -d :pserver:anoncvs@gcc.gnu.org:/cvs/gcc login ( enter "anoncvs" as the password ) % cvs -z 9 -d :pserver:anoncvs@gcc.gnu.org:/cvs/gcc co gcc ( the latest source tree will be expanded in ../gcc )
newlib C library (cygnus/RedHat)
- http://sources.redhat.com/newlib/ - newlib Homepage
% cd /usr/src % mkdir newlib-cvs % cd newlib-cvs % cvs -z 9 -d :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src login ( enter "anoncvs" as the password ) % cvs -z 9 -d :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src co newlib ( the latest source tree will be expanded in ../src/newlib )
Cross-making
I expanded the source trees in /usr/src as follows
- binutils /usr/src/cvs-binutils/src/
- gcc /usr/src/cvs-gcc/gcc/
- newlib /usr/src/cvs-newlib/src/
- gdb /usr/src/gdb-5.0/src
and I created links to them for easy-typing.
/usr/src # ls -l binutils gcc newlib gdb lrwxrwxrwx 1 root root 16 Aug 14 18:36 binutils -> cvs-binutils/src lrwxrwxrwx 1 root root 11 Aug 14 18:36 gcc -> cvs-gcc/gcc lrwxrwxrwx 1 root root 10 Aug 14 18:36 gdb -> gdb-5.0/src lrwxrwxrwx 1 root root 14 Aug 14 18:36 newlib -> cvs-newlib/src
Binutils
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 automatically creates a Makefile optimised for the host environment. There are two essential configure options, –target and –prefix.
- –target
- –prefix
$ mkdir /usr/local/h8 $ cd /usr/src/h8 $ mkdir **build-binutils** $ cd build-binutils $ /usr/src/binutils/configure --target=**h8300-elf** --prefix=**/usr/local/h8** $ make **CFLAGS="-O2"** all $ su # make install $ export PATH=$PATH:/usr/local/h8/bin
GCC
Next target is gcc-4.x. There are additional configure options you should consult.
- –enable-languages
- –with-newlib
- –with-headers
- –disable-libssl
- –disable-libada
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).
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!
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”.
You may consider not bothering with the c++ compiler as its library is huge!
% cd /usr/src/h8 % mkdir build-gcc % cd build-gcc % /usr/src/configure --target=h8300-elf --prefix=/usr/local/h8 --enable-languages="c" --with-newlib --with-headers=/usr/src/newlib/newlib/libc/include --disable-libssp --disable-libada % make CFLAGS="-O2" LANGUAGES="c" % su # make LANGUAGES="c" install
Newlib
Ok, now we are ready to cross-compile newlib package. The procedure is just same as binutils.
$ cd /usr/src/h8 $ mkdir build-newlib $ cd build-newlib $ /usr/src/newlib/configure --target=h8300-elf --prefix=/usr/local/h8 $ make CFLAGS="-O2" all $ su # make install