Linux Renesas SuperH

--------------------------------------------------------------------------------
Building cross development environment
    targeting SH4 system (Hitachi SolutionEngine MS7750SSE01)
2026/03/29 Masahiro Abe <[email protected]>
(C) 2001 A&D; Co., Ltd. <http://www.aandd.co.jp/>

--------------------------------------------------------------------------------
Table of contents
1. Preface
2. Prerequisite
    2.1 Host Configuration
    2.2 Target Configuration
3. Preparation
    3.1 Directories
    3.2 Acquire Required Files
    3.3 Get Additional Patch
4. Building binutils
5. Building gcc (Part 1)
6. Building Linux Kernel
7. Make Sure It Boots
    7.1 Building ipl and lilo
    7.2 Install ipl to the target
    7.3 Install kernel
    7.4 Booting Target
8. Building glibc
    8.1 Building glibc for cross-development
    8.2 Building glibc for target
    8.3 Install Libraries to the Target
    8.4 Compiling and Installing Test Program
9. Building gcc (Part 2)
    9.1 Building additional libraries
    9.2 Installing libraries to the target
    9.3 Compiling and Installing Test Program
Appendix A: Snapshot
--------------------------------------------------------------------------------
1. Preface
    This document describes the procedure I took to build cross-development
environment on x86 machine targeting SolutionEngine evaluation board from
Hitachi.
    Please note that this is for the guy who really have to build cross-
development environment/tools by oneself, for some unavoidable reason. I won't
recommend everyone take this route, since this can be very time-consuming and
cumbersome task. Most of you should head to the pre-built rpm or deb files,
correctly assembled and ready to install. You can find rpm from following link:
<http://www.sh-linux.org/rpm/RPMS/i386/RedHat6.2/> - binutils/gcc
<http://www.sh-linux.org/rpm/RPMS/noarch/host/> - glibc/other libraries
    With these files, you can get similar binutils and gcc to the files created
by the procedure I describe below. But if you need to use C++, you must go the
hard way with this doc, since the files above don't include Standard C++
Library.
    glibc above is 2.2.1pre2, whereas this doc uses glibc 2.2.2 final. You can
make your choice here, but an application which is build with one of them can
be executed on the machine with the other version of library.
    This document is not a HOWTO-type that can cover every case of procedure,
but just a kind of case study which had successfully completed (in some sense).
I assume you have guts to concur any stumbling blocks those may be in front of
you, if you plan to apply this to another target or anything.
    At this point I would like to present my sincere appreciation to all of the
linux-sh team members who had made my work possible, and especially Mr. Kaz
Kojima, who have generously given me numerous advices, and they really helped.
Also thanks to the guys those have published patches required in this document,
they are not crafted by me, but were already on the 'net.
    I don't mention any (registered) trademarks in this doc.
    Now I must say this: any information contained herein and any published
patch files have absolutory no warranty. Take them at your own risk.
--------------------------------------------------------------------------------
2. Prerequisite
2.1 Host Configuration
    Host configuration of mine is as following:
--Handmade IBM-PC-compatible(PentiumIII 700MHz + 384MB RAM + 20GB HD)
--LASER5 Linux 6.4 (RedHat Linux 6.2 compatible)
                                     - egcs-1.1.2(gcc egcs-2.91.66) included
--Linux Kernel 2.4.2 + pcmcia-cs-3.1.24
--PC card adapter(to use PCMCIA CF card)
    You can use gcc2.95.2 as it worked here. I don't know about 2.95.3 yet.
    You shouldn't have to change kernel version but just use the one with the
dist. It was my taste to use newer kernel. If you choose to go like me, be
careful about PCMCIA configuration: pcmcia drivers came with kernel 2.4.2 didn't
work right on my configuration, so I just disabled PCMCIA support in kernel
config, and added pcmcia-cs-3.1.24 which supports kernel 2.4.x.
2.2 Target Configuration
    I chose to make target configuration like this:
--connect Compact Flash card with adapter to the PCMCIA slot
--create ext2 root filesystem on the CF card
--use Little Endian
--------------------------------------------------------------------------------
3. Preparation
3.1 Directories
    I've designed so at last there will be directory configuration like this.
/root/sh/               for working
        boot/           ipl & lilo
        tools/          Source and Build dir. for Toolchain
                binutils-010108/
                gcc-20001120/
                glibc-2.2.2/
                sh4-binutils/
                sh4-gcc2.97/
                sh4-glibc/
                sh4-glibc-target/
        temp/           for building test program
/usr/local/cross-sh4/   Installation dir for Toolchain
/sh4/                   Simulating target file system
/mnt/target/            mount target file system here
    I prepared several directories as following
1) logon as root
2) mkdir -p ~/sh/tools ~/sh/boot ~/sh/temp
3) mkdir /sh4; cd /sh4
4) mkdir -p bin boot dev etc lib sbin usr usr/lib usr/src
5) mkdir /mnt/target
    I'll let you consider how to proceed as not to be a root.
3.2 Acquire Required Files
    I've used Linux Kernel 2.4.2 final. Place compressed file in /sh4/usr/src/.
    For gcc and binutils, I downloaded:
--binutils-010108-2.src.rpm
--gcc-20001120-3.src.rpm
from <http://www.sh-linux.org/rpm/SRPMS/>.

    Install them with "rpm -i" command, and you'll get compressed files and
patches inside /usr/src/redhat/SOURCES/ dir. Move them to /root/sh/tools/ .
    I've used stock glibc-2.2.2 release. Also, linuxthread add-on. Place them in
/root/sh/tools/ dir. also.
    For ipl and lilo, I downloaded:
--sh-ipl+g-2001-01-13.tar.gz
--sh-lilo-2000-11-26.tar.gz
from <ftp://ftp.m17n.org/pub/super-h/>. Place them in /root/sh/boot/ .
3.3 Get Additional Patch
    Acquire patches for kernels and tools above. Located in the same place as
this document.
ftp://linuxsh.sourceforge.net/pub/linuxsh/abe/gcc-2.97-20010326.patch

ftp://linuxsh.sourceforge.net/pub/linuxsh/abe/glibc-2.2.2-20010319.patch

ftp://linuxsh.sourceforge.net/pub/linuxsh/abe/configparms

ftp://linuxsh.sourceforge.net/pub/linuxsh/abe/configparms-target

-->Place them in /root/sh/tools/ dir.
ftp://linuxsh.sourceforge.net/pub/linuxsh/abe/linux-sh-2.4.2-20010323.patch

ftp://linuxsh.sourceforge.net/pub/linuxsh/abe/linux-sh-2.4.2-20010320-cf.patch

-->Place them in /sh4/usr/src/ dir.
--------------------------------------------------------------------------------
4. Building binutils
    At first, build "binutils", which include assembler and linker.
# cd ~/sh/tools/
# tar xIf binutils-010108.tar.bz2
# cd binutils-010108
# cat ../binutils-010110.patch | patch -p1
# mkdir ../sh4-binutils; cd ../sh4-binutils
# ../binutils-010108/configure --prefix=/usr/local/cross-sh4 --target=sh4-linux
# make                             <---took several minutes
# make install
    It makes cross binutils for sh4 inside /usr/local/cross-sh4/ dir
    Now you must add path to the cross tools to PATH environment variable.
# export PATH=$PATH:/usr/local/cross-sh4/bin
    It's a good idea to do the same in ~/.bashrc for later use.
--------------------------------------------------------------------------------
5. Building gcc (Part 1)
    Now build C/C++ compiler.
    This time you must be careful since there are a lot of patch, those must
apply in order, to avoid unnecessary troubles later.
# cd ~/sh/tools/
# tar xzf gcc-core-20001120.tar.gz
# tar xzf gcc-g++-20001120.tar.gz
# cd gcc-20001120
# zcat ../gcc-20001120.diff.gz | patch -p1
# cat ../gcc-flow.patch | patch -p1
# cat ../gcc-asmspecs.patch | patch -p1
# cat ../gcc-specs.patch | patch -p1
# cat ../gcc-2.97-20010320.patch | patch -p1
# mkdir ../sh4-gcc2.97; cd ../sh4-gcc2.97
# ../gcc-20001120/configure --prefix=/usr/local/cross-sh4 --target=sh4-linux
# make all-gcc                             <---took several minutes
# make install-gcc
    At this point, only the compiler and fundamental library(libgcc.a) has been
created. To do that, "make all-gcc" is issued. Other elements of gcc needs glibc
and will fail to build here.
--------------------------------------------------------------------------------
6. Building Linux Kernel
    Now you've got the necessary tools to build Linux Kernel, so try it.
Building kernel is not required to build cross development tools, but you must
follow them until "make xconfig" since it is required for building glibc.
    This can be a good trial if the tools above have been correctly built.
# cd /sh4/usr/src
# tar xIf linux-2.4.2.tar.bz2
# cd linux
# cat ../linux-sh-2.4.2-20010320.patch | patch -p1
# cat ../linux-sh-2.4.2-20010320-cf.patch | patch -p1
                                                    <--Not needed if you use HDD
# make ARCH=sh xconfig(or config/menuconfig)
[configure as you like, save and exit]
# make ARCH=sh INSTALL_MOD_PATH=/sh4 dep zImage modules modules_install
                             <---took several minutes
# cp arch/sh/boot/zImage /sh4/boot/
    Now you've got kernel and module files for SolutionEngine under /sh4 dir.
--------------------------------------------------------------------------------
7. Make Sure It Boots
    You may skip this chapter if you just want to setup cross development
environment.
    Here you create ipl(Initial Program Loader) and lilo(LInux LOader), required
to boot linux kernel on the target machine, and install.
7.1 Building ipl and lilo
# cd /root/sh/boot
# tar xzf sh-ipl+g-2001-01-13.tar.gz
# tar xzf sh-lilo-2000-11-26.tar.gz
# cd sh-ipl+g
# ln -s config/config.mk-sesh4-pcmcia config.mk
# ln -s config/config.h-sesh4-pcmcia config.h
[Now append
#define CONFIG_MEMORY_SIZE      0x04000000
at the end of config/config.h-sesh4-pcmcia. Also change Makefile
CROSS_COMPILE=sh-linux-gnu-
to
CROSS_COMPILE=sh4-linux-
]
# make
# cd ../sh-lilo-2000-11-26
[Change Makefile
CROSS_COMPILE=sh-linux-gnu-
to
CROSS_COMPILE=sh4-linux-
]
# make
# cp boot.b /sh4/boot/
7.2 Install ipl to the target
    Put sh-stub.srec file int the FlashROM of target, regarding
/root/sh/boot/sh-ipl+g/README.
    I went another route like this and put it from Windows Machine:
1) transfer sh-stub.srec to the Windows machine using ftp or samba
2) connect Windows machine and target with serial cross cable
3) connect to target with HyperTerminal, put SW4-3 of target on
4) supply power to the target
5) confirm the ROM Monitor works (see the output of Hyperterminal)
6) enter "fl 80000000" to the Ready> prompt
7) select "Send Text File" of "Transfer" menu, specify sh-stub.srec file
8) shut the target down once the transfer is completed
9) put SW4-3 of target off
10) supply power to the target
11) confirm to see the banner of sh-ipl+g in Hyperterminal
12) shut the target down and close Hyperterminal
* I don't know the exact wording of Hyperterminal menu, so it may be wrong.
7.3 Install kernel
    Try to install kernel and lilo onto CF and boot.
    Here I assume that CF is recognized as /dev/hde with host machine, with
single partition and formatted as ext2 file system. Mount it here.
    Create /sh4/etc/lilo.conf file regarding /root/sh/boot/sh-lilo/README . For
my case, it is as following:
-----
linear
boot=/dev/hde
disk=/dev/hde
        bios=0x80
vga=normal
delay=30
image=/boot/zImage
        label=2.4.2
        root=/dev/hda1
        read-only
-----
    Now issue the command.
# mount -t /dev/hde1 /mnt/target
# cd /sh4
# cp -af boot/ /mnt/target/
# cp -af etc/ /mnt/target/
# cp -af /dev /mnt/target
# cd /mnt/target/dev/
# mknod ttySC0 c 204 8
# mknod ttySC1 c 204 9
# mknod ttySC2 c 204 10
# lilo -r /mnt/target
    Output "Added 2.4.2 *" means success.
    If you see "Unexpected version" kind of error at the last command (sorry,
here I can't remember the exact wording. You guess.), read the message
carefully, and identify the required version. Then, change the contents of
/root/sh/boot/sh-lilo-2000-11-26/first.S like these line:
-----
                      /* v--- Major Version */
        .word   4*256 + 21
        !    /* ^--- Minor Version*/     
-----
    if "21.3" is required, change as "3*256 + 21". Once changed, make sh-lilo,
copy boot.b to /sh4/boot/ and /mnt/target/boot/, and issue the last command
again.
    Now umount CF and remove from the host.
7.4 Booting Target
    Put CF to target, connect target to host with serial cross cable. Issue
# cu -l /dev/ttyS0 -s 115200
and you should see output "connected.". Supply power to the target and you
should see the banner message of sh-ipl+g. Hit "b" key at the prompt. You should
see the kernel boot message, and "Kernel Panic" at the end.
    It is the evidence that you have correctly configured so far.
--------------------------------------------------------------------------------
8. Building glibc
    Next, you should build C library for building userland applications.
    Here I show you the 2 steps, first for cross-development, second for target.
If you don't need libraries for target machine, just follow 8.1 and skip to the
next chapter.
8.1 Building glibc for cross-development
# cd ~/sh/tools/
# tar xIf glibc-2.2.2.tar.bz2
# cd glibc-2.2.2
# tar xIf ../glibc-linuxthreads-2.2.2.tar.bz2
# cat ../glibc-2.2.2-20010319.patch | patch -p1
# mkdir ../sh4-glibc; cd ../sh4-glibc
# cp ../configparms ./
# CC="sh4-linux-gcc -ml -m4" ../glibc-2.2.2/configure --host=sh4-linux \
> --build=`arch`-linux --disable-debug --disable-profile \
> --with-headers=/sh4/usr/src/linux/include --prefix=/usr/local/cross-sh4 \
> --enable-add-ons
# make                             <---took more than 20 minutes
# touch iconv/iconv_prog login/pt_chown
# make install_root=/usr/local/cross-sh4/sh4-linux prefix="" install
# cd /usr/local/cross-sh4/sh4-linux/include
# ln -s /sh4/usr/src/linux/include/asm asm
# ln -s /sh4/usr/src/linux/include/linux linux
    Now edit the contents of /usr/local/cross-sh4/sh4-linux/lib/libc.so as
follows:
GROUP ( /lib/libc.so.6.1 /lib/libc_nonshared.a )
to
GROUP ( libc.so.6.1 libc_nonshared.a )
8.2 Building glibc for target
    Build libraries to be installed to the target.
# cd ~/sh/tools/
# mkdir sh4-glibc-target; cd sh4-glibc-target
# cp ../configparms-target ./configparms
# CC="sh4-linux-gcc -ml -m4" ../glibc-2.2.2/configure --host=sh4-linux \
> --build=`arch`-linux --disable-debug --disable-profile \
> --with-headers=/sh4/usr/src/linux/include --prefix=/sh4/usr \
> --enable-add-ons
# make                             <---took more than 20 minutes
# make install
    Now edit the contents of /sh4/usr/lib/libc.so as follows:
GROUP ( /sh4/lib/libc.so.6.1 /sh4/usr/lib/libc_nonshared.a )
to
GROUP ( /lib/libc.so.6.1 /usr/lib/libc_nonshared.a )
8.3 Install Libraries to the Target
    Mount the root partition of CF to /mnt/target first.
# cd /sh4
# cp -af lib/ /mnt/target/
# cd usr; cp -af lib/ /mnt/target/usr/
8.4 Compiling and Installing Test Program
    Create simple C file, build it, and run on the target.
# cd ~/sh/temp/
# cat >> test.c << EOF
> #include <stdio.h>
> int main(void)
> {
>       printf("Hello, World!\n");
>       return 0;
> }
> EOF
# sh4-linux-gcc test.c -o test
    It is correctly built if you don't see any error message here.
# mkdir /mnt/target/sbin
# cp test /mnt/target/sbin/init
    Test program is copied as /sbin/init of CF. Now umount CF, put int target
machine, connect to it with cu, and boot the target.
    You should see "Hello, World!" at the end of the kernel output, followed by
"Kernel Panic". Congratulations! Your test program ran successfully here.
--------------------------------------------------------------------------------
9. Building gcc (Part 2)
9.1 Building additional libraries
    You can build additional libraries of gcc now, like libstdc++-v3.
# cd ~/sh/tools/sh4-gcc2.97/
# make all                            <---took about 30 minutes
# make install
9.2 Installing libraries to the target
    Skip this section if you just need cross-dev. environment.
    Mount the root partition of CF to /mnt/target first.
# cd /usr/local/cross-sh4/sh4-linux/lib/
# cp -d libstdc++.so.3* /sh4/lib/
# cp -d libzgcj.so.0* /sh4/lib/
# cd /sh4/usr/lib/
# ln -s ../../lib/libstdc++.so.3 libstdc++.so
# ln -s ../../lib/libzgcj.so.0 libzgcj.so
# cp -d libstdc++.so /mnt/target/usr/lib/
# cp -d libzgcj.so /mnt/target/usr/lib/
# cd /sh4/lib/
# cp -d libstdc++.so* /mnt/target/lib/
# cp -d libzgcj.so* /mnt/target/lib/
9.3 Compiling and Installing Test Program
    Create simple C++ file, build it, and run on the target.
# cd ~/sh/temp/
# cat >> testcpp.cpp << EOF
> #include <iostream>
> int main(void)
> {
>       std::cout << "Hello, World!" << std::endl;
>       return 0;
> }
> EOF
# sh4-linux-g++ testcpp.cpp -o testcpp
    It is correctly built if you don't see any error message here.
# cp testcpp /mnt/target/sbin/init
    Test program is copied as /sbin/init of CF. Now umount CF, put int target
machine, connect to it with cu, and boot the target.
    You should see "Hello, World!" at the end of the kernel output, followed by
"Kernel Panic". Congratulations! Your test C++ program ran successfully here.
--------------------------------------------------------------------------------
Appendix A: Snapshot
SH IPL+g version 0.8, Copyright (C) 2000 Free Software Foundation, Inc.
This software comes with ABSOLUTELY NO WARRANTY; for details type `w'.
This is free software, and you are welcome to redistribute it under
certain conditions; type `l' for details.
> b
LILO boot: first-image
Loading 2.4.2..........done.
Uncompressing Linux... Ok, booting the kernel.
Linux version 2.4.2 (<<<deleted>>>) (gcc version 2.97 20001120 (experimental)) #1 Wed Mar 21 11:08:10 JST 2001
On node 0 totalpages: 16384
zone(0): 16384 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: mem=64M sh_mv=SolutionEngine console=ttySC1,115200
Setting GDB trap vector to 0x80000100
CPU clock: 199.99MHz
Bus clock: 66.66MHz
Module clock: 33.33MHz
Interval = 83333
Calibrating delay loop... 199.47 BogoMIPS
Memory: 63368k/65536k available (848k kernel code, 2168k reserved, 34k data, 32k init)
Dentry-cache hash table entries: 8192 (order: 4, 65536 bytes)
Buffer-cache hash table entries: 4096 (order: 2, 16384 bytes)
Page-cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 4096 (order: 3, 32768 bytes)
CPU: SH7750
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Starting kswapd v1.8
block: queued sectors max/low 42050kB/14016kB, 128 slots per queue
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
Uniform Multi-Platform E-IDE driver Revision: 6.31
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
hda: Hitachi ATA 6.0, ATA DISK drive
ide0 at 0x1f0-0x1f7,0x3f6 on irq 7
hda: 125184 sectors (64 MB) w/1KiB Cache, CHS=978/4/32
Partition check:
 hda: hda1
JFFS version 1.0, (C) 1999, 2000  Axis Communications AB
SuperH SCI(F) driver initialized
ttySC0 at 0xffe00000 is a SCI
ttySC1 at 0xffe80000 is a SCIF
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 4096 bind 4096)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
 hda: hda1
 hda: hda1
VFS: Mounted root (ext2 filesystem) readonly.
Freeing unused kernel memory: 32k freed
Hello,World!
Kernel panic: Attempted to kill init!


printer friendly Linux is a trademark of Linus Torvalds. 
SuperH and Cool Engine are registered trademarks of Hitachi, Ltd.

Last update: 28/08/2026

This page ©2003 Masahiro Abe. Permission granted to copy and display.
$Id: prtemplate.php3,v 1.4 2026/08/28 16:30:56 lethal Exp $