Building cross development environment targeting SH4 system (Hitachi SolutionEngine MS7750SSE01)

2004/04/12 Masahiro Abe <m-abe at aandd.co.jp>
(C) 2001-2004 A&D Co., Ltd. <http://www.aandd.co.jp/>
[Japanese]

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. Install tools
5. Building Linux Kernel
6. Prepare ipl and lilo
6.1 Build ipl
6.2 Build lilo
6.3 Install ipl to the target
7. Try to boot
7.1 Setup contents of CompactFlash
7.2 Booting target
8. Setup contents of CF
8.1 Uncompress base files
8.2 Setup run-time libraries
8.3 Build ncurses
8.4 Build busybox
8.5 Build tinylogin
8.6 Setup additional rpm files
8.7 Copy script files
8.8 Check build status
8.9 Build tcp_wrappers
8.10 Build netkit-ftp
8.11 Build netkit-telnet
8.12 Build linux-ftpd
8.13 Final check


1. Preface

This document describes the procedure I took to build cross-development environment on x86 machine targeting SolutionEngine evaluation board from Hitachi.

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.

I don't mention any (registered) trademarks in this doc.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. Author assumes no responsibility to the contents of this document. Anyone can display and/or copy the document for any purpose.


2. Prerequisite

2.1 Host Configuration

Host configuration of mine is as following:
I've done following process with logging in as "root".

2.2 Target Configuration

I chose to make target configuration like this:

3. Preparation

3.1 Directories

Prepare directory as following:
/root/sh/               for working
        basket/         for storing downloaded files
                        create {target host} directory inside
        dest/           Simulating target file system
                        create {boot} directory inside
        temp/           for building test program
/root/cvsroot/m17n      for checking out sources of sh-ipl+g and sh-lilo
/mnt/target/            mount target file system here

3.2 Acquire required files

I've used 2.4.18 vanila kernel from kernel.org. Get "linux-2.4.18.tar.bz2" and store it into /root/sh/basket.

Download prebuilt cross-compiler and tools from <http://www.sh-linux.org/>.

rpm-2003/RPMS/noarch/host/:             --> into /root/sh/basket/host/
rpm-2003/RPMS/i386/:                    --> into /root/sh/basket/host/
rpm-2003/RPMS/sh4/:                     --> into /root/sh/basket/target/
Acquire ipl and lilo source from m17n.org CVS server like this:

# mkdir -p /root/cvsroot/m17n
# cd /root/cvsroot/m17n
# cvs -d:pserver:anonymous@cvs.m17n.org:/cvs/superh login
CVS Password:<just return>
# cvs -d:pserver:anonymous@cvs.m17n.org:/cvs/superh co ipl+g
# cvs -d:pserver:anonymous@cvs.m17n.org:/cvs/superh co lilo


Source files are checked out into ipl+g and lilo directory inside /root/cvsroot/m17n/.

Download busybox from <http://www.busybox.net> or mirror into /root/sh/basket/target/. Use ver.1.00-pre8 as it is current.

Download tinylogin from <http://tinylogin.busybox.net> or mirror into /root/sh/basket/target/. Use ver.1.4 as it is current.

3.3 Get Additional Patch

Acquire patches for kernels and tools above. Located in the same place as this document. Put into /root/sh/basket/.

4. Install tools

Install cross-build tools into host PC.
# cd ~/sh/basket/host
# rpm -Uvh binutils-sh-linux-xxx.i386.rpm
# rpm -Uvh glibc-sh-linux-xxx.i386.rpm
# rpm -Uvh glibc-sh4-linux-xxx.i386.rpm
# rpm -Uvh zlib-sh-linux-xxx.i386.rpm
# rpm -Uvh zlib-sh4-linux-xxx.i386.rpm
# rpm -Uvh gcc-sh-linux-xxx.i386.rpm

5. Building Linux Kernel

Now you've got the necessary tools to build Linux Kernel, so try it.

Prepare kernel source first.

# cd ~/sh/basket
# tar xjf linux-2.4.18.tar.bz2
# cd linux
# bzcat ../patch-2.4.18-sh-xxx.diff.bz2 | patch -p1
# cd ..
# mv linux /usr/src/linux-sh-2.4.18
# cd /usr/src
# ln -s linux-sh-2.4.18 linux-sh-2.4
# cd /usr/src/linux-sh-2.4.18

Now kernel sources are inside /usr/src/linux-sh-2.4.18 and there is a link file to there as /usr/src/linux-sh-2.4. This link is needed because cross-tools are configured as kernel sources are under /usr/src/linux-sh-2.4.

Next, kernel configuration. There is a default config file inside, so use it as a start.

# cp arch/sh/configs/defconfig-se7750 .config
# make ARCH=sh CROSS_COMPILE=sh4-linux- menuconfig
[configure as you like, then save and exit]


Build kernel now.

# make ARCH=sh CROSS_COMPILE=sh4-linux- INSTALL_MOD_PATH=~/sh/dest clean dep zImage modules modules_install
# cp arch/sh/boot/zImage ~/sh/dest/boot/


We've got kernel and module files in appropriate places under ~/sh/dest/ directory.

Finally, create link files to setup include directory, to be used for building application.

# cd /usr/sh-linux/include
# ln -s /usr/src/linux-sh-2.4/include/asm asm
# ln -s /usr/src/linux-sh-2.4/include/linux linux

6. Prepare ipl and lilo

Here you create ipl(Initial Program Loader) and lilo(LInux LOader), required to boot linux kernel on the target machine, and install.

6.1 Build ipl

Apply following patch to the source first.

Index: ide.c
===================================================================
RCS file: /cvs/superh/ipl+g/ide.c,v
retrieving revision 1.16
diff -u -r1.16 ide.c
--- ide.c    26 Jun 2001 07:34:55 -0000    1.16
+++ ide.c    5 Apr 2004 05:23:20 -0000
@@ -302,8 +302,10 @@
 
   if (i == TIMEOUT)
     return -1;
-  else if (ide_inb (IDE_ERROR) != 1)
-    return -1;
+  else if (status & IDE_ERR){
+    if (ide_inb (IDE_ERROR) != 1)
+      return -1;
+  }
   return 0;
 }
 


Then build ipl.

# cd /root/cvsroot/m17n/ipl+g
# ln -s config/config.mk-sesh4-pcmcia config.mk
# ln -s config/config.h-sesh4-pcmcia config.h
# make CROSS_COMPILE=sh4-linux-

6.2 Build lilo

Apply following patch to the source first.

Index: first.S
===================================================================
RCS file: /cvs/superh/lilo/first.S,v
retrieving revision 1.17
diff -u -r1.17 first.S
--- first.S    25 Dec 2000 04:58:51 -0000    1.17
+++ first.S    7 Apr 2004 04:15:57 -0000
@@ -44,7 +44,7 @@
     !
     .ascii    "LILO"
     .word    1
-#if 1
+#if 0
     /* EDIT HERE ! */
             ! Depends LILO's version
     .word    20
Index: partition.c
===================================================================
RCS file: /cvs/superh/lilo/partition.c,v
retrieving revision 1.1
diff -u -r1.1 partition.c
--- partition.c    25 Dec 2000 04:58:51 -0000    1.1
+++ partition.c    7 Apr 2004 04:15:57 -0000
@@ -23,7 +23,7 @@
 
 
 /* For older kernels ... */
-
+#if 0
 #ifndef DOS_EXTENDED_PARTITION
 #define DOS_EXTENDED_PARTITION EXTENDED_PARTITION
 #endif
@@ -31,7 +31,7 @@
 #ifndef LINUX_EXTENDED_PARTITION
 #define LINUX_EXTENDED_PARTITION EXTENDED_PARTITION
 #endif
-
+#endif
 
 void part_verify(int dev_nr,int type)
 {

Then build lilo.

# cd /root/cvsroot/m17n/lilo
# make CROSS_COMPILE=sh4-linux-
# cp boot.b ~/sh/dest/boot/

6.3 Install ipl to the target

Put sh-stub.srec file into the FlashROM of target, regarding /root/cvsroot/m17n/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. Try to boot

Try to install kernel and lilo onto CF and boot.

Here I assume that CF in CompactFlash Reader/Writer is recognized as /dev/sda with host machine.

7.1 Setup contents of CompactFlash

Create several files/directories under /root/sh/dest.

# cd /root/sh/dest
# mkdir -p bin boot dev etc home lib proc root sbin tmp usr var dev/pts usr/bin usr/lib usr/sbin lib/modules var/log
# cd /dev
# cp -a console hda hda? kmem mem null rtc sda sda? tty tty? urandom ptyp? ttyp?
/root/sh/dest/dev/
# cd /root/sh/dest/dev
# ln -s ../proc/self/fd/0 ./stdin
# ln -s ../proc/self/fd/1 ./stdout
# ln -s ../proc/self/fd/2 ./stderr
# mknod ttySC0 c 204 8
# mknod ttySC1 c 204 9


Create /root/sh/dest/etc/lilo-se.conf file regarding /root/cvsroot/m17n/lilo/README. For my case, it is as following:

linear
boot=/dev/sda
disk=/dev/sda
        bios=0x80
vga=normal
delay=30
image=/boot/zImage
        label=linux
        root=/dev/hda1
        append="mem=64M sh_mv=SolutionEngine console=ttySC1,115200"
        read-only


Connect CF R/W to USB connector of the host, then attach CompactFlash to CF R/W.

Initialize CompactFlash like this:

# modprobe usb-storage
# fdisk /dev/sda
[create single partition]
# mke2fs -j /dev/sda1
# mount /dev/sda1 /mnt/target


Partition of CompactFlash is mounted at /mnt/target.

Now issue the command.

# cd /root/sh/dest
# cp -auf * /mnt/target/
# lilo -r /mnt/target -C /etc/lilo-se.conf


Output "Added linux *" 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/cvsroot/m17n/lilo/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 /root/sh/dest/boot/ and /mnt/target/boot/, and issue the last command again.

Now umount CF and remove from the host.

# umount /mnt/target
# modprobe -r usb-storage

7.2 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. Setup contents of CF

Setup contents of CF so that it can be used as base distribution.

8.1 Uncompress base files

Uncompress previously downloaded file which is for building applications to be put into CF.

# cd /root/sh/basket/target
# tar xjf ../make_rootfs-xxx.tar.bz2


There should be /root/sh/basket/target/make_rootfs directory.

8.2 Setup run-time libraries

Install run-time library rpm files under /root/sh/dest.

Setup rpm database first.

# mkdir -p /root/sh/dest/var/lib/rpm
# rpm --root /root/sh/dest --initdb


Then install rpm.

# cd /root/sh/basket/target
# rpm --root /root/sh/dest -ivh --ignorearch --noscripts --nodeps glibc-xxxxx.sh4.rpm
# rpm --root /root/sh/dest -ivh --ignorearch --noscripts --nodeps libstdc++-xxxxx.sh4.rpm
# rpm --root /root/sh/dest -ivh --ignorearch --noscripts --nodeps libtermcap-xxxxx.sh4.rpm

8.3 Build ncurses

Build like this:

# cd /root/sh/target/make_rootfs/ncurses
# tar xzf ncurses-5.2.tar.gz
# cd ncurses-5.2
# cat ../ncurses-sh-5.2-20010724.diff | patch -p1
# cd ..
# mkdir sh4-ncurses
# cd sh4-ncurses
# BUILD_CC=gcc BUILD_CFLAGS="-O2 -Wall" CC=sh4-linux-gcc CFLAGS="-O2 -Wall" LD=sh4-linux-ld AR=sh4-linux-ar RANLIB=sh4-linux-ranlib ../ncurses-5.2/configure --prefix=/usr --host=sh4-linux --build=`arch`-linux --with-install-prefix=`pwd`/_install --with-shared --without-debug --disable-profile --without-cxx --without-ada
# make
# make install


Install library and header into host system.

# cd _install/usr
# cp include/ /usr/sh-linux/include/ncurses -a
# cp lib/* /usr/sh-linux/lib/ -a
# cd /usr/sh-linux/include
# ln -s ncurses/curses.h ./
# ln -s ncurses/eti.h ./
# ln -s ncurses/form.h ./
# ln -s ncurses/menu.h ./
# ln -s ncurses/ncurses.h ./
# ln -s ncurses/panel.h ./
# ln -s ncurses/term.h ./
# ln -s ncurses/termcap.h ./
# ln -s ncurses/unctrl.h ./


Copy library into /root/sh/dest.

# cd /root/sh/basket/target/make_rootfs/ncurses/sh4-ncurses/_install/usr
# cp -a lib/*.so* /root/sh/dest/usr/lib/


Setup dependency of library files.

# ldconfig -vr /root/sh/dest

8.4 Build busybox

Uncompress previously downloaded file.

# cd /root/sh/basket/target/make_rootfs/busybox/
# tar xjf ../../busybox-1.00-pre8.tar.bz2
# cd busybox-1.00-pre8
# cp ../defconfig .config


Build like this:

# make menuconfig
[change options is you want to]
# make
# make install


Copy files into /root/sh/dest.

# cp -a _install/* /root/sh/dest/

8.5 Build tinylogin

Uncompress previously downloaded file.

# cd /root/sh/basket/target/make_rootfs/tinylogin/
# tar xjf ../../tinylogin-1.4.tar.bz2
# cd tinylogin-1.4


Build like this:

# make CROSS=sh4-linux-
# make CROSS=sh4-linux- install


Change access right of tinylogin file.

# chmod +s _install/bin/tinylogin

Copy files into /root/sh/dest.

# cp -af _install/* /root/sh/dest/

8.6 Setup additional rpm files

Install several packages prepared in rpm form.

# cd /root/sh/basket/target
# rpm --root /root/sh/dest -ivh --ignorearch --noscripts --nodeps e2fsprogs-xxxxx.sh4.rpm
# rpm --root /root/sh/dest -ivh --ignorearch --noscripts --nodeps bash-xxxxx.sh4.rpm

# rpm --root /root/sh/dest -ivh --ignorearch --noscripts --nodeps modutils-xxxxx.sh4.rpm

8.7 Copy script files

Copy all files inside /root/sh/basket/target/make_rootfs/scripts into /root/sh/dest.

# cp -af /root/sh/basket/target/make_rootfs/scripts/* /root/sh/dest/

8.8 Check build status

Now we should have enough files to boot target with CF, so try it.

Attach CF to USB-CFRW and issue these commands.

# modprobe usb-storage
# mount /dev/sda1 /mnt/target
# cd /root/sh/dest
# cp -auf * /mnt/target/
# lilo -r /mnt/target -C /etc/lilo-se.conf
# umount /mnt/target
# modprobe -r usb-storage


Remove CF from CFRW and attach to the target machine. Connect target to host with serial cross cable. Supply power to the target. You should be able to login to the target as "root" with password "pass".

At first, configure kernel module dependency with following command.

# depmod -a

Now you may check the system by issuing some commands.

Shutdown the target with "halt" command, and power it off.

8.9 Build tcp_wrappers

Build like this:

# cd /root/sh/basket/target/make_rootfs/tcp_wrappers
# tar xzf tcp_wrappers_7.6.tar.gz
# cd tcp_wrappers_7.6
# cat ../tcpw7.2-config.patch | patch -p1
# cat ../tcpw7.2-setenv.patch | patch -p1
# cat ../tcpw7.6-netgroup.patch | patch -p1
# cat ../tcpw-barterly-yp.patch | patch -p1
# cat ../tcp_wrappers-sh-linux.patch | patch -p1
# make linux CC=sh4-linux-gcc AR=sh4-linux-ar RANLIB=sh4-linux-ranlib


Install library and header into host system.

# cp tcpd.h /usr/sh-linux/include/
# cp libwrap.a /usr/sh-linux/lib/


Copy files into /root/sh/dest.

# cp tcpd /root/sh/dest/usr/sbin/

8.10 Build netkit-ftp

Build like this:

# cd /root/sh/basket/target/make_rootfs/netkit-ftp
# tar xzf netkit-ftp-0.17.tar.gz
# cd netkit-ftp-0.17
# cat ../netkit-ftp-sh-linux.patch | patch -p1
# CC=sh4-linux-gcc ./configure
# make


Copy files into /root/sh/dest.

# cp ftp/ftp /root/sh/dest/usr/bin/

8.11 Build netkit-telnet

Build like this:

# cd /root/sh/basket/target/make_rootfs/netkit-telnet
# tar xzf netkit-telnet-0.17.tar.gz
# cd netkit-telnet-0.17
# cat ../netkit-telnet-sh-linux.patch | patch -p1
# CC=sh4-linux-gcc CXX=sh4-linux-g++ ./configure
# make -C telnetd


Copy files into /root/sh/dest.

# cp telnetd/telnetd /root/sh/dest/usr/sbin/in.telnetd

8.12 Build linux-ftpd

Build like this:

# cd /root/sh/basket/target/make_rootfs/linux-ftpd
# tar xzf linux-ftpd-0.17.tar.gz
# cd linux-ftpd-0.17
# cat ../linux-ftpd-sh-linux.patch | patch -p1
# CC=sh4-linux-gcc ./configure
# make


Copy files into /root/sh/dest.

# cp ftpd/ftpd /root/sh/dest/usr/sbin/in.ftpd

8.13 Final check

Put all files into CF and boot target with it, to check the process above went ok or not.

Attach CF to USB-CFRW and issue these commands.

# modprobe usb-storage
# mount /dev/sda1 /mnt/target
# cd /root/sh/dest
# cp -auf * /mnt/target
# lilo -r /mnt/target -C /etc/lilo-se.conf
# umount /mnt/target
# modprobe -r usb-storage


Remove CF from CFRW and attach to the target machine. Connect target to host with serial cross cable. Supply power to the target. You should be able to login to the target as "root" with password "pass".

You may connect to the target with ftp/telnet, as "shuser" with password "pass".

Shutdown the target with "halt" command, and power it off.