GNU Toolchain With Croostool on ML410

by : Hargyo Tri Nugroho

A. Introduction

The following walks the reader through a typical GNU cross toolchain build session using Dan Kegel's renowned “crosstool“ scripts. The build is customized for the target board Xilinx ML410 with PowerPC 405 processor.

As seen on the picture above, we  have a host development system running Windows XP Profession SP3. Our embedded Linux target board (Xilinx ML410) is connected to the development host via an RS-232 serial cable. We plug the target board's Ethernet interface into a local Ethernet hub or switch, to which our development host is also attached via Ethernet. The development host contains our development tools and utilities along with target filesnormally obtained from an embedded Linux distribution such as Xilinx EDK, VMWare, and crosstool.

Crosstool is a set of scripts to build and test several versions of gcc and glibc for most architectures supported by glibc. It will even download and patch the original tarballs for you. The resulting script and associated patches, and the latest version of this doc, are available at kegel.com/crosstool.

Spesification of the target board

The complete specification of he ML410 is available at http://www.xilinx.com/products/boards/ml410/docs.htm

This is the brief specification of  Xilink ML410 :

  • XC4VFX60-11FFG1152 FPGA (PowerPC 405 Process or, FPGA Fabric)
  • ATX form factor motherboard
  • 32-bit component DDR memory (64 MB) and 64-bit DDR2 DIMM (256 MB)
  • 512 MB CompactFlash (CF) card and System ACE CF controller for configuration
  • Two on-board 10/100/1000 Ethernet PHYs (MII/RGMII and SGMII) with RJ-45 connectors
  • Two PCI Express downstream connectors
  • Four 32-bit/33 MHz PCI connectors (Two 3.3V slots and two 5V slots)
  • Two USB peripheral ports and one parallel port
  • Two serial ATA connectors
  • Two UARTs with RS-232 connectors
Datasheet available here: http://www.xilinx.com/products/boards/ml410/datasheets.html

ML410 CompactFlash
This Compact Flash (CF) contains a DOS FAT16 filesystem partition and a Linux EXT3 filesystem partition. The DOS filesystem's directory structure is consistent with the requirements of Xilinx' System ACE CF controller, used to bring-up and launch applications on the ML410.

The following demonstration programs are on the CompactFlash:
    cf0 -> ace_loader.ace
    cf1 -> ml410_pci_linux.ace  (Montavista Linux 3.1 Professional , Kernel 2.4.20)
    cf2 -> ml410_bsb_vxworks.ace
    cf3 -> empty
    cf4 -> ml410_bsb_bootloop.ace
    cf5 -> ml410_bsb_vxworks_sw.ace
    cf6 -> empty
    cf7 -> empty

Booting the ML410 board

Warning! Read documentation before using 3.3V PCI slots.
 
1. Connect a Null modem cable between the ML410 COM0 RS232 port and a PC host running a terminal program such as TeraTerm or HyperTerminal set for 9600 baud, 8 bits, No parity, 1 stop bit, and no hardware flow control. (9600, 8-N-1, no HW flow control)

2. Set DIP Switch SW3 to boot the ACE-loader located in configuration 0. All switches towards ON and the DIP switch numbers.

3. Insert CF into the CF slot J22, located near the System ACE CF ASIC (U38).

4. Turn power on or press and release SW1, the SYSACE RESET pushbutton.

Free Image Hosting at www.ImageShack.us

5. The ML410 Diagnostics/ACE-loader menu similar to the one below will appear.
    Select the desired application as noted above. To use boot the board using Monta Vista Linux 3.1 press 1. Use ml410 login : root and password: 410ml to login to the system.

Free Image Hosting at www.ImageShack.us

Free Image Hosting at www.ImageShack.us

B. Crosstool Setup
We have to install crosstool on VM that is running on the host development system. In this project we are using Centos 5.2 running on VMWare Workstation.

1. Download and unpack
[slackie@laba-laba crosstool-0.43]$ wget http://kegel.com/crosstool/crosstool-0.43.tar.gz
[slackie@laba-laba crosstool-0.43]$ tar -xzvf crosstool-0.43.tar.gz
[slackie@laba-laba crosstool-0.43]$ cd crosstool-0.43

2. Edit file gcc-3.4.4-glibc-2.3.3.dat
[slackie@laba-laba crosstool-0.43]$ vi gcc-3.4.4-glibc-2.3.3.dat

Change the LINUX_DIR=linux-2.4.26 to LINUX_DIR=linux-2.4.20 since we are now using MontaVista Linux 3.1 Kernel 2.4.20.

3. Edit file demo-powerpc-405.sh
[slackie@laba-laba crosstool-0.43]$ cp demo-powerpc-405.sh yoyo-demo.sh
[slackie@laba-laba crosstool-0.43]$ vi yoyo-demo.sh
We will be using GCC version 3.4.4 because it is the same version used by the cross-compiler in Xilinx EDK 8.2i. If 3.4.4 is compatible by Xilinx standards then we will assume it should also be good enough for this development project. Also We want to use  PREFIX_DIR=/home/slackie/ppc405_juni09  as our base directory for embedded software development.

So:
Insert PREFIX_DIR=/home/slackie/ppc405_juni09
Replace: TARBALLS_DIR=$HOME/downloads with: TARBALLS_DIR=$PREFIX_DIR/downloads
Replace: eval `cat powerpc-405.dat gcc-3.4.1-glibc-2.3.3.dat` sh all.sh –notest with: eval `cat powerpc-405.dat gcc-3.4.4-glibc-2.3.3.dat` sh all.sh –notest



4. Build it with  yoyo-demo.sh
[slackie@laba-laba crosstool-0.43]$ time sh yoyo-demo.sh
+ export PREFIX_DIR=/home/slackie/ppc405_juni09
+ PREFIX_DIR=/home/slackie/ppc405_juni09
+ TARBALLS_DIR=/home/slackie/ppc405_juni09/downloads
+ RESULT_TOP=/opt/crosstool
+ export TARBALLS_DIR RESULT_TOP
+ GCC_LANGUAGES=c,c++
+ export GCC_LANGUAGES
+ mkdir -p /opt/crosstool
++ cat powerpc-405.dat gcc-3.4.4-glibc-2.3.3.dat
...
[truncated]
...
ux-gnu-g++ hello2.cc -o powerpc-405-linux-gnu-hello2
+ echo testhello: C compiler can in fact build a trivial program.
testhello: C compiler can in fact build a trivial program.
+ test '' = 1
+ test '' = 1
+ test '' = 1
+ test 1 = ''
+ echo Done.
Done.
real    84m8.491s
user    24m8.765s
sys     43m33.819s
[slackie@laba-laba crosstool-0.43]$

Yes, done!
The new cross toolchain is now installed under :
/opt/crosstool/gcc-3.4.4-glibc-2.3.3/powerpc-405-linux-gnu/

6. Testing the crosscompiler using simple 'hello world' program.
   
a. On the host system
1. type this code and save as hello.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
printf ("%s: Hello, world\n", argv[0]);
sleep(1);
printf ("%s: Goodbye, cruel world\n", argv[0]);
exit (0);
}

2. cross-compile the file "hello.c" using powerpc-405-linux-gnu-gcc

[slackie@laba-laba ppc405_juni09]$ export PATH=/opt/crosstool/gcc-3.4.4-glibc-2.3.3/powerpc-405-linux-gnu/bin/:$PATH

[slackie@laba-laba ppc405_juni09]$ powerpc-405-linux-gnu-gcc hello.c -o hello -Wall

[slackie@laba-laba ppc405_juni09]$ ls -lFh hello
-rwxrwxr-x 1 slackie slackie 11K Jun 16 23:15 hello*

3. strip the binary file "hello"

[slackie@laba-laba ppc405_juni09]$ powerpc-405-linux-gnu-strip hello

[slackie@laba-laba ppc405_juni09]$ powerpc-405-linux-gnu-readelf -a ./hello | grep -i 'shared'
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]

3. send the file  to the embedded linux target
using FTP (note: make sure that FTP service is running on the embedded linux target).
[slackie@laba-laba ppc405_juni09]$ ftp 192.168.69.129
Connected to 192.168.69.129.
220 localhost.localdomain FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.
500 'AUTH GSSAPI': command not understood.
500 'AUTH KERBEROS_V4': command not understood.
KERBEROS_V4 rejected as an authentication type
Name (192.168.69.129:slackie): linux
331 Password required for linux. (type your password)
Password:
230- Linux (none) 2.4.20_mvl31-ml300 #1 Thu Dec 29 14:44:47 MST 2005 ppc unknown
230-
230- MontaVista(R) Linux(R) Professional Edition 3.1
230-
230 User linux logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put hello
local: hello remote: hello
227 Entering Passive Mode (192,168,69,129,4,5)
150 Opening BINARY mode data connection for 'hello'.
226 Transfer complete.
4244 bytes sent in 0.0008 seconds (5.2e+03 Kbytes/s)
ftp> bye
221 Goodbye.
    b.Try it on the embedded linux target
root@ml410:/home/linux# ./hello
./hello: Hello, world
./hello: Goodbye, cruel world

root@ml410:/home/linux#
   
        It works!


C. Crosscompiling the BNC IRC Proxy

This section is a brief explanation of crosscompiling the BNC IRC Proxy as follows:
1. Donwload an unpack the bnc2.9.3.tar.gz
[slackie@localhost
slackie]$ wget
[slackie@localhost slackie]$ tar -zxvf
bnc2.9.3.tar.gz
[slackie@localhost slackie]$ cd bnc2.9.3

2. Crosscompile it. We use 'CC=' to tell './configure' to use
powerpc-405-linux-gnu-gcc as the compiler.
[slackie@localhost bnc2.9.3]$ CC=powerpc-405-linux-gnu-gcc \
> ./configure --host=powerpc-405-linux-gnu
configure: WARNING: If you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used.
checking for powerpc-405-linux-gnu-gcc... powerpc-405-linux-gnu-gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... yes
checking for suffix of executables..
...
powerpc-405-linux-gnu-gcc -o bnc bnc.o conf.o server.o cmds.o ctcp.o sbuf.o send.o -lnsl -lresolv -lcrypt
powerpc-405-linux-gnu-gcc -O3 -Wall -include config.h -o mkpasswd mkpasswd.c -lnsl -lresolv -lcrypt
[slackie@localhost bnc2.9.3]$ Make

3. Create file named 'bnc.conf' which is containing:

listento 9000  #port u are using to binding on the irc proxy
password [your password]
adminpass [your admin password]

4. Copy the file "bnc" and "bnc.conf" to USB Flashdisk

5. Mount the USB FLashdisk and run the crosscompiled BNC IRC Proxy on the embedded linux target.

root@ml410:/root# mount -t vfat /dev/sda1 /mnt/cdrom

root@ml410:/root# cd /mnt/cdroom
root@ml410:/mnt/cdrom# ls
bnc  bnc.conf

root@ml410:/mnt/cdrom# ./bnc
Irc Proxy v2.9.3 Copyright 1998-2002
Coded by James Seter (pharos@gotbnc.com)
--Using conf file ./bnc.conf
--Configuration:
    Daemon port......: 9000
    Maxusers.........: unlimited
    Default conn port: 6667
    Pid File.........: pid.bnc
    Vhost Default....: -SYSTEM DEFAULT-
    Process Id.......: 3415
Exit ./bnc{7} :Successfully went into the background.
root@ml410:/mnt/cdrom/bnc2.9.3-ppc#

5. Now, the BNC IRC proxy is running on our embedded linux target so we can connect to IRC server through that proxy as seen on the picture below:




D. Crosscompiling the Tcpdump

The crosscompilation of Tcpdump is quite harder then the previous section (BNC IRC Proxy) since we have also to crosscompile the libpcap library. We need to add more extra parameter to configure them.

1. Download and unpack the libpcap
[slackie@laba-laba slackie]$ wget http://www.tcpdump.org/release/libpcap-1.0.0.tar.gz
[slackie@laba-laba slackie]$ tar -zxvf libpcap-1.0.0.tar.gz
[slackie@laba-laba slackie]$ cd libpcap-1.0.0

2. Crosscompile the libpcap
[slackie@laba-laba libpcap-1.0.0]$ CC=powerpc-405-linux-gnu-gcc ac_cv_linux_vers=2 ac_cv_ssleay_path=/opt/crosstool/gcc-3.4.4-glibc-2.3.3/powerpc-405-linux-gnu \./configure --host=powerpc-405-linux-gnu --with-pcap=linux --prefix=/opt/crosstool/gcc-3.4.4-glibc-2.3.3/powerpc-405-linux-gnu
.....
[output truncated]
.....
[slackie@laba-laba libpcap-1.0.0]$ make
....
[output truncated]
....
3. Download and unpack the tcpdump
[slackie@laba-laba slackie]$ wget http://www.tcpdump.org/release/tcpdump-4.0.0.tar.gz
[slackie@laba-laba slackie]$ tar -zxvf tcpdump-4.0.0.tar.gz
[slackie@laba-laba slackie]$ cd tcpdump-4.0.0

4. Configure the Makefile
[slackie@laba-laba tcpdump-4.0.0]$ CC=powerpc-405-linux-gnu-gcc ac_cv_linux_vers=2 ac_cv_ssleay_path=/opt/crosstool/gcc-3.4.4-glibc-2.3.3/powerpc-405-linux-gnu \./configure --host=powerpc-405-linux-gnu --with-pcap=linux --prefix=/opt/crosstool/gcc-3.4.4-glibc-2.3.3/powerpc-405-linux-gnu

5. Edit the "Makefile" and delete all  "-I /usr/include"  (2 items) in the section "INCLS" and "DEFS" . We have to do this to avoid errors.
[slackie@laba-laba tcpdump-4.0.0]$ vi Makefile

6. Edit the file "print-enc.c" and comment the line ip6_print(p,lenth)
since it will produce error. By commenting this item we will disable the IPv6 support in the tcpdump.
[slackie@laba-laba tcpdump-4.0.0]$ vi print-enc.c
 ....
switch (hdr->af) {
        case AF_INET:
                ip_print(gndo, p, length);
                break;
        case AF_INET6:
                //ip6_print(p, length);
                break;
        }
....

7. Compile it using "make" command.

[slackie@laba-laba tcpdump-4.0.0]$ make
....
[output truncated]
....
[slackie@laba-laba tcpdump-4.0.0]$ file tcpdump
tcpdump: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped

8. Transfer the file "tcpdump" to the embedded system using FTP or USB Flashdisk


9. Run tcpdump on the target embedded linux system as follows: