Crosstool Toolchains on scratchbox 1.0.2
Notice: These instructions depreceated on Scratchbox Apophis and newer.
The rest of the page is also a terrible mess.. please split out to separate document if there is something worth saving.
a livecd scratchbox-multiCpu is available at
http://mirror.opf.slu.cz/scratchbox/iso/
Most binaries for the toolchains described below can be downloaded from
http://mirror.opf.slu.cz/scratchbow/tarballs/
snapshot
http://groups.yahoo.com/group/tstembed/files/scratchbox-live-dvd-under-Qemu.png
http://perso.wanadoo.fr/hoan/ScratchboxMultiCpu.png
This page describes how to build a scratchbox toolchain using
Dan Kegel's crosstool This example will take you through the building of a toolchain to target an xscale processor in big-endian mode.
Preparing scratchbox
Change the group ownership of /scratchbox/compilers to sbox. This will give your scratchbox user write access to this directory.
vesuvius@pompeii:~$ sudo chgrp sbox /scratchbox/compilers
Enter scratchbox and make sure you have scratchbox configured to use the HOST target:
vesuvius@pompeii:~$ sb-conf se HOST vesuvius@pompeii:~$ scratchbox [sbox-HOST: ~] >
Preparing crosstool
Download
crosstool
[sbox-HOST: ~] > wget http://kegel.com/crosstool/crosstool-0.38.tar.gz [sbox-HOST: ~] > tar xzf crosstool-0.38.tar.gz [sbox-HOST: ~] > cd crosstool-0.38
Crosstool 0.38 didn't have support for gcc-3.4.5 yet, but I found that my toolchain worked by copying gcc-3.4.4 patches. YMMV:
[sbox-HOST: ~/crosstool-0.38] > cd patches
[sbox-HOST: ~/crosstool-0.38/patches] > cp -a gcc-3.4.{4,5}
[sbox-HOST: ~/crosstool-0.38/patches] > cd ..
I created a gcc-3.4.5-glibc-2.3.5-hdrs-2.6.11.2.dat file:
[sbox-HOST: ~/crosstool-0.38] > cat gcc-3.4.5-glibc-2.3.5-hdrs-2.6.11.2.dat BINUTILS_DIR=binutils-2.15 GCC_DIR=gcc-3.4.5 GLIBC_DIR=glibc-2.3.5 LINUX_DIR=linux-2.6.15 LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.11.2 GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.5
And I created a demo-sbox-armv5b-softfloat.sh script:
[sbox-HOST: ~/crosstool-0.38] > cat demo-sbox-armv5b-softfloat.sh #!/bin/sh set -ex TARBALLS_DIR=$HOME/downloads RESULT_TOP=/scratchbox/compilers PREFIX=$RESULT_TOP/armv5b-gcc-3.4.5-glibc-2.3.5 export TARBALLS_DIR RESULT_TOP PREFIX GCC_LANGUAGES="c,c++" export GCC_LANGUAGES mkdir -p $RESULT_TOP unset LD_LIBRARY_PATH # Build the toolchain. Takes a couple hours and a couple gigabytes. eval `cat armv5b-softfloat.dat gcc-3.4.5-glibc-2.3.5-hdrs-2.6.11.2.dat` sh all.sh --notest echo Done.
A couple of things to note in the above script is that $RESULT_TOP must point to /scratchbox/compilers and that the $PREFIX directory must be only one more directory deep under $RESULT_TOP. By default crosstool puts $PREFIX as $RESULT_TOP/$TOOL_COMBO/$TARGET which is two directories down from $RESULT_TOP. The other thing is that crosstool doesn't like having LD_LIBRARY_PATH set during the build, so we unset it before the build starts.
Build the toolchain
Start up the script and wait a couple of hours. The script will take care of downloading needed files if they are not already in $HOME/downloads.
[sbox-HOST: ~/crosstool-0.38] > ./demo-sbox-armv5b-softfloat.sh
Scratchbox post configuration
Once the script has successfully finished, we need to create some additional files to let scratchbox know about the new toolchain.
sbox symbolic links
We need to create some symbolic link files in your compiler's bin directory that scratchbox expects:
[sbox-HOST: ~/crosstool-0.38] > cd /scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5/bin/ [sbox-HOST: /scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5/bin] > for f in `ls`; do ln -s $f sbox-$f; done
compiler-name
Create a file compiler-name in your compiler's top directory. Mine looks like this:
[sbox-HOST: /scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5] > cat compiler-name armv5b-gcc-3.4.5-glibc-2.3.5:/scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5:armv5b:softfloat-linux:glibc:armeb
This file is a : delimited file. The fields are as follows as far as I could tell:
Name of the compiler. This name must be exactly the same as the name of directory where this compiler-name file is.
Full path to the compiler directory.
Toolchain's target architecture.
Toolchain's target sub-arch.
glibc or uclibc
qemu emulation
target_setup.sh
Create a target_setup.sh script in your compiler's top directory. Mine looks like this. Replace source appropriately for your setup:
[sbox-HOST: /scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5] > cat target_setup.sh #!/bin/sh target=$1 source=/scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5/armv5b-softfloat-linux mkdir -p $target/lib mkdir -p $target/usr/lib mkdir -p $target/usr/include mkdir -p $target/usr/bin cp -af $source/lib/* $target/lib/ cp -af $source/lib/* $target/usr/lib/ cp -af $source/include/* $target/usr/include/ ln -sf /bin/cpp $target/lib/ ln -sf /bin/cc $target/usr/bin/ chmod +x $target/lib/ld-*.so
gcc.specs
We need to copy the toolchains specs file to where scratchbox expects to see it:
[sbox-HOST: /scratchbox/compilers/armv5b-gcc-3.4.5-glibc-2.3.5] > cp `find . -name specs` gcc.specs
qemu emulation
This part is only needed if scratchbox doesn't have qemu emulation for your arch already but qemu does have support for your arch available. This was the case for me since I needed qemu-armeb.
First of all you'll need write access to get temporary ownership of /scratchbox/tools. Since all directories and files under there are owned by root, it will be easy to revert the ownership back to root when we're done.
vesuvius@pompeii:~$ sudo chown -R vesuvius /scratchbox/tools
Download and build qemu for the needed emulation:
[sbox-HOST: ~] > wget http://www.qemu.com/qemu-0.8.0.tar.gz [sbox-HOST: ~] > tar xzf qemu-0.8.0.tar.gz [sbox-HOST: ~] > cd qemu-0.8.0 [sbox-HOST: ~/qemu-0.8.0] > ./configure --prefix=/scratchbox/tools --target-list=armeb-user --static [sbox-HOST: ~/qemu-0.8.0] > make [sbox-HOST: ~/qemu-0.8.0] > make install
vesuvius@pompeii:~$ sudo chown -R root /scratchbox/tools
Edit /scratchbox/etc/cputransp-methods to add qemu-armeb to the list.
Issues
One needs to build device_tools namely sbrshd and fakeroot to communicate thru CPU_Transparency with the device and gdbserver for debugging.An example of a realdevice,nslu2_ixp425 with kanotix_debian_scratchbox-1.0 is described at
0. Intro.
nslu2 cross development inside a sandbox,with full operation
(better than emulation ,such as qemu )
1. install scratchbox :core,lib ,toolchains
using:
http://scratchbox.org/debian/
http://www.scratchbox.org/documentation/user/scratchbox-1.0/html/installdoc.html Scratchbox packages
Base (required):
scratchbox-core - environment, common tools and host compiler scratchbox-libs - libraries required by core, devkits and toolchains
Development kits (optional):
scratchbox-devkit-debian - environment and tools for Debian development
scratchbox-devkit-doctools - document generation tools
scratchbox-devkit-perl - additional Perl modules
Toolchains (optional):
scratchbox-toolchain-arm-gcc3.3-glibc2.3
scratchbox-toolchain-i686-gcc3.3-glibc2.3
scratchbox-toolchain-arm-gcc3.2-uclibc20040229
scratchbox-toolchain-i386-gcc3.2-uclibc20040229
Build armeb-toolchain-nslu2
( This builds only Dan Kegel toolchain)
You can also build custom toolchain packages. See Scratchbox toolchains [5].
http://scratchbox.org/wiki/CrossToolToolchain 'armv5b-softfloat' Start Scratchbox with command:
$ /scratchbox/login
Follow these steps to create a new cross-compilation target:
Start sb-menu:
[sbox-HOST: ~] > sb-menu
Build device_tools for armeb_target
(needs to communicate/debug thru CPU_transparency with nslu2)
Device_tools: strace , sbrshd ,fakemon
gdbserver,gdb (DDD) Download those src files into /scratchbox/packages
Login scratchbox,select HOST then untar src ,select target armeb
strace
strace-4.5.11 needs to be patched for arm .
Those patches are seen on /slug/openembedded/packages/strace/ ,when one runs the MasterMakefile (
http://www.nslu2-linux.org ).
arm-compilation.patch arm-syscallent.patch arm-syscall.patch quota.patch
and a "#include "asm/ptrace.h" to signal.c and syscall.c
root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p0 < patches/arm-syscallent.patch
patching file strace-4.5.4/linux/arm/syscallent.h
root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p1 < patches/quota.patch
patching file resource.c
root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p1 < patches/arm-syscall.patch
patching file linux/arm/syscall.h
patching file linux/arm/dummy.h
root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p1 < patches/arm-compilation.patch
patching file syscall.c
Hunk #1 succeeded at 747 (offset 51 lines).
root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# cat patches/arm-syscall.patch
[sbox-nslu2: ~/build_strace] > ../strace-4.5.11/configure --build=i386-pc-linux-gnu --host=armv5b-softfloat-linux --target=armv5b-softfloat-linux
[sbox-nslu2: ~/build_strace] > make
[sbox-nslu2: ~/build_strace] > file strace
strace: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), stripped
Since this strace runs on the nslu2-armeb target ,copy it to TARGET/nslu2/usr/sbin
The CpuTransparency mechanism allow execution of target's binary under the control of hostPC via the pair of programs sbrsh and sbrshd, all that thru tcp/ip.Any order the hostPC sends to target,or received from target go thru sbrsh-running as i386 binary ; On the target,sbrshd runs as daemon acting in a similar way,but on the target side.We must compile sbrsh under HOST target , and daemon sbrshd within target ,say here "nslu2"
compilation_of_sbrsh
[sbox-HOST: ~/sbrsh-7.0] > make clean
rm -f sbrsh sbrshd sb-exportfs *.o
[sbox-HOST: ~/sbrsh-7.0] > make sbrsh
[sbox-HOST: ~/sbrsh-7.0] > file sbrsh
sbrsh: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped
compilation_of_daemon_sbrshd
[sbox-HOST: ~/sbrsh-7.0] > sb-conf se nslu2
Shell restarting...
[sbox-nslu2: ~] >
[sbox-nslu2: ~] > cd sbrsh-7.0/
[sbox-nslu2: ~/sbrsh-7.0] > make clean
rm -f sbrsh sbrshd sb-exportfs *.o
[sbox-nslu2: ~/sbrsh-7.0] > make sbrshd CPPFLAGS="-I/scratchbox/device_tools/fakeroot-1.4.2/armv5b-gcc-3.4.4-glibc-2.3.5/include/ "
[sbox-nslu2: ~/sbrsh-7.0] > file sbrshd sbrshd: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not stripped
The daemon sbrshd will be copied to /scratchbox/device_tools/sbrsh-7.0/etc/init.d/sbrshd
This sbrsh will be copied to /scratchbox/device_tools/sbrsh-7.0/armv5b-gcc-3.4.4-glibc-2.3.5/sbin/
and sbrshd.init as /scratchbox/device_tools/sbrsh-7.0/armv5b-gcc-3.4.4-glibc-2.3.5/etc/sbrshd
Those etc and sbin containing sbrshd must be transfered by some way-serial connection,scp ..- to the rootfilesystem of target nslu2 .
There is however a remark : let's check the lib dependencies
[sbox-nslu2: ~/sbrsh-7.0] > ldd sbrshd
libutil.so.1 => /lib/libutil.so.1 (0x00000000)
libc.so.6 => /lib/libc.so.6 (0x00000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000)
If it happens that our target does not have the same libraries,then we need to put on the target not only sbrshd binary,but also the libc .
Either put there /scratchbox/compilers/armv5b-gcc-3.4.4-glibc-2.3.5/lib/gcc/armv5b-softfloat-linux/3.4.4/libgcc.a ,or compile sbrshd_static !
[sbox-nslu2: ~/sbrsh-7.0] > make sbrshd CPPFLAGS="-I/scratchbox/device_tools/fakeroot-1.4.2/armv5b-gcc-3.4.4-glibc-2.3.5/include" LDFLAGS="-static"
[sbox-nslu2: ~/sbrsh-7.0] > file sbrshd
sbrshd: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, statically linked, not stripped
[sbox-nslu2: ~/sbrsh-7.0] >
fakeroot-1.4.2
to build this daemon.
fakemon needs to be patched with
<a href="
http://scratchbox.org/repos/1.2/sb-toolchains/device_tools/fakeroot/files/communication.patch"><img src="crosstooltoolchain_files/moin-www.png" alt="[WWW]" height="11" width="11">
http://scratchbox.org/repos/1.2/sb-toolchains/device_tools/fakeroot/files/communication.patch</a> and compile with
sbox-HOST>gcc -o ../lib/libfakeroot/libfakeroot-tcp.so.0.0.1 libfakeroot.c \
communicate.c -fPIC -DPIC -shared -lpthread -ldl -Wl,-soname -Wl,libfakeroot-tcp.so.0
for the rest about fakeroot,follow
<a href="
http://scratchbox.org/documentation/docbook/fakeroot.html"><img src="crosstooltoolchain_files/moin-www.png" alt="[WWW]" height="11" width="11">
http://scratchbox.org/documentation/docbook/fakeroot.html</a>
gdbserver
Let's start a session on nslu2-armeb and try compile cross-gdb ,and armeb-gdbserver
~$ scratchbox
Welcome to Scratchbox, the cross-compilation toolkit!
Use 'sb-menu' to change your compilation target.
See /scratchbox/doc/ for documentation.
download from the net,untargz and patch
[sbox-nslu2: ~] >wget
http://ftp.gnu.org/gnu/gdb/gdb-6.3.tar.gz
[sbox-nslu2: ~] >tar xzf /scratchbox/packages/gdb-6.3.tar.gz
[sbox-nslu2: ~] > cd gdb-6.3
[sbox-nslu2: ~/gdb-6.3] >patch -p1 < ../gdb_patch/uclibc.patch
patching file bfd/config.bfd
patching file bfd/configure.in
patching file bfd/configure
[sbox-nslu2: ~/gdb-6.3] > patch -p1 < ../gdb_patch/gdbserver-cflags-last.diff
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
|--- gdb/gdbserver/Makefile.in.orig 2004-10-05 18:52:56.298419032 +0200
|+++ gdb/gdbserver/Makefile.in 2004-10-05 18:53:10.442268840 +0200
File to patch:
-
[sbox-nslu2: ~/gdb-6.3] patch -p0 < ../gdb_patch/gdbserver-cflags-last.diff
patching file gdb/gdbserver/Makefile.in
[sbox-nslu2: ~/gdb-6.3] > cd ..
[sbox-nslu2: ~] > mkdir build_gdbarmeb
[sbox-nslu2: ~] > cd build_gdbarmeb/
[sbox-nslu2: ~/build_gdbarmeb] >
[sbox-nslu2: ~/build_gdbarmeb] > ../gdb-6.3/gdb/gdbserver/configure --host=armv5b-softfloat-linux
[sbox-nslu2: ~/build_gdbarmeb] > make
[sbox-nslu2: ~/build_gdbarmeb] > file gdbserver
gdbserver: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not stripped
[sbox-nslu2: ~/build_gdbarmeb] > strip gdbserver
[sbox-nslu2: ~/build_gdbarmeb] > file gdbserver
gdbserver: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), stripped
[sbox-nslu2: ~/build_gdbarmeb] > ls gdb*
gdbreplay gdbreplay.o gdbserver
[sbox-nslu2: ~/build_gdbarmeb] > file gdbreplay
gdbreplay: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not stripped
[sbox-nslu2: ~/build_gdbarmeb] > strip gdbreplay && file gdbreplay
gdbreplay: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), stripped
[sbox-nslu2: ~/build_gdbarmeb] >
These armeb-gdbserver armeb-gdbreplay have to be put on somewhere /usr/bin or /usr/sbin of the armeb-nslu2-target !
that's it !
cross gdb
After building armeb-gdbserver (patches done) let's build our cross-gdb running on host-i386 aiming at target armeb-nslu2 for ex.
Since this a tool in sbox point of view,let switch to HOST target
[sbox-nslu2: ~/build_gdbarmeb] > sb-conf se HOST
Shell restarting...
[sbox-HOST: ~/gdb-6.3] > patch -p1 < ../gdb_patch/sim-install.patch
[sbox-HOST: ~] > mkdir build-crossgdbarmeb
[sbox-HOST: ~] > cd build-crossgdbarmeb/
[sbox-HOST: ~/build-crossgdbarmeb] > ../gdb-6.3/configure --host=i386-pc-linux-gnu --target=armv5b-softfloat-linux
[sbox-HOST: ~/build-crossgdbarmeb] >make
After a while :
[sbox-HOST: ~/build-crossgdbarmeb] > file gdb/gdb gdb/gdb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped
Since this tool is compiler dependent ,here on armeb-compiler,one has to copy gdb binary to /scratchbox/compilers/armv5b-gcc-3.4.4-glibc-2.3.5/arch_tools/bin/ Each time you select a target ,sbox makes the /target/links/arch_tools link to the right place !
that's it !
4. install on nslu2 side sbrshd ,gdbserver,openssh on PC side ssh,nfs,..Check carefully with
http://scratchbox.org/documentation/user/scratchbox-1.0/html/installdoc.html Let's play with the box.
get the openslug_rootfs.tar.gz ,or direct copy your nslu2_root_partition to populate the devel_target at
/scratchbox/users/$USER/targets/armeb/ in order to experiment the cpu_transparency method. When you power up nslu2,the /etc/init.d/sbrshd starts up the daemon /usr/sbin/sbrshd using the config_file /etc/sbrshd.conf to set user@address the daemon will be looking for.
On the desktop_scratchbox side,using sb-menu to setup the target,crosscompiler and cputransparency method
Control the setting with the command "sb-conf sh" ,it will show : Compiler: armv5b-gcc-3.4.5-glibc-2.3.5 Devkits: none CPU-transparency: sbrshNow from scratchbox you can nfsmount the sbox_target_dir on a device_mountpoint namely at
/var/sbrshd/<user@nfsserver>/<target>
by executing the command :
sb-armeb> sbrsh mount armeb The resulting mount operation can be seen on the device_serial_console or a ssh_session_console as : laixa:/scratchbox/users/wangji/targets/armeb on /var/sbrshd/wangji@192.168.1.5/armeb type nfs \ (rw,sync,v3,rsize=32768,wsize=32768,acregmin=0,acregmax=0,acdirmin=0,acdirmax=0,hard,udp,noac,nolock,addr=laixa) ramfs on /var/sbrshd/wangji@192.168.1.5/armeb/dev type ramfs (rw) devpts on /var/sbrshd/wangji@192.168.1.5/armeb/dev/pts type devpts (rw) laixa:/scratchbox/users/wangji/home on /var/sbrshd/wangji@192.168.1.5/armeb/home type nfs (rw,sync,v3,rsize=32768,wsize=32768,acregmin=0,acregmax=0,acdirmin=0,acdirmax=0,hard,udp,noac,nolock,addr=laixa) proc on /var/sbrshd/wangji@192.168.1.5/armeb/proc type proc (rw,nodiratime) tmpfs on /var/sbrshd/wangji@192.168.1.5/armeb/tmp type tmpfs (rw)
Instead of mounting,you can login the devel_target_partition with sb-armeb> sh /login_target.sh ;this results in a login to a virtual_nslu2 with a true IXP425_cpu operating on the devel_target_dir as root_fs (nfsmount).Although jailed here,you can ssh to outside world so that a cross compile in an env_HOST could be tested immediately by tranfering with scp to the jailed_target.
You obtain a beautiful scratchbox-armeb connected with nslu2 to play
.(this nslu2 part edited by nnhoan_acong_yahoo_cham_com)
mipsel-toolchain: sbox-demo-mipsel.sh
#!/bin/sh set -ex
# Little-endian MIPS
#
# To create a toolchain for the Linksys wrt54g, select glibc-2.2.3
# See
http://seattlewireless.net/index.cgi/LinksysWrt54g
#
http://www.batbox.org/wrt54g-linux.html
# Note: recent wrt54g firmware uses uclibc, which behaves like a subsetted glibc.
# There are patches to build uclibc toolchains in the contrib directory,
# but they're not integrated yet. However, you can still use a glibc
# toolchain; you'll either have to
# a) not call the missing functions,
# b) use a stub library like
http://www.xse.com/leres/tivo/downloads/libtivohack/
# or c) link your programs statically if you want them to run on
# the wrt54g.
TARBALLS_DIR=$HOME/downloads
RESULT_TOP=/scratchbox/compilers
PREFIX=$RESULT_TOP/mipsel-gcc-3.3.6-glibc-2.3.2
export TARBALLS_DIR RESULT_TOP PREFIX
GCC_LANGUAGES="c,c++"
export GCC_LANGUAGES
unset LD_LIBRARY_PATH
mkdir -p $RESULT_TOP
# Build the toolchain. Takes a couple hours and a couple gigabytes.
eval cat mipsel.dat gcc-3.4.4-glibc-2.3.2-hdrs-2.6.11.2.dat sh all.sh --notest
echo Done.
select HOST ,gcc-host with sb-menu. To build toolchain,from inside crosstool-0.38 type
[sbox-HOST:~/crosstool-0.38] > sh sbox-demo-mipsel.sh
Once the toolchain is built,finish up the symlinks at two places
[sbox-HOST:/scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/bin]> for f in `ls`; do ln -s $f sbox-$f; done
and in
[sbox-HOST:/scratchbox/compilers/bin/] modify the file wrapper_links to reflect this: PREFICES="host- arm-linux- i386-linux- i686-linux- powerpc-linux- mips-linux- armv5b-softfloat-linux- armeb-linux- mipsel-unknown-linux-gnu-"
then do
[sbox-HOST:/scratchbox/compilers/bin/] > ./wrapper_links create
Create three following files,to render the toolchain readable by sbox
[sbox-HOST:/scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/[compiler-name gcc.specs target_setup.sh ]
compiler-name: mipsel-gcc-3.4.4-glibc-2.3.2:/scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2:mipsel:unknown-linux-gnu:glibc:mipsel
gcc.specs: *cross_compile: 0 %rename cpp old_cpp *cpp: -isystem /usr/local/include -isystem /usr/include %(old_cpp)
target_setup.sh :
#!/bin/sh
target=$1
mkdir -p $target/lib
mkdir -p $target/usr/lib
mkdir -p $target/usr/include
mkdir -p $target/usr/bin
cp -af /scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/lib/* $target/lib/
cp -af /scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/mipsel-unknown-linux-gnu/lib/* $target/lib/
cp -af /scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/mipsel-unknown-linux-gnu/lib/libstdc++* $target/usr/lib/
find /scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/usr/ -mindepth 1 -maxdepth 1 -not -name libexec -exec cp -af {} $target/usr/ \;
cp -af /scratchbox/compilers/mipsel-gcc-3.4.4-glibc-2.3.2/include/* $target/usr/include/
ln -sf /bin/cpp $target/lib/
ln -sf /bin/cc $target/usr/bin/
chmod +x $target/lib/ld-*.so
Use sb-menu to create a target : mips_le (little endian ) with cross compiler :mipsel-gcc-3.4.4-glibc-2.3.2
The target rootstrap will be created later in another part of this tutorial !!!
Now,we need to build the device tools for message passing between sbox and the device
device_tools
build libfakeroot-tcp.so.0.0.1 get fakeroot-1.4.2.tar.gz from
ftp://ftp.debian.org/debian/pool/main/f/fakeroot/fakeroot_1.4.2.tar.gz
patch communicate.patch from
http://scratchbox.org/repos/1.2/sb-toolchains/device_tools/fakeroot/files/communication.patch
install -d $(WORKDIR)/lib/libfakeroot
cd $(WORKSRC) && awk -f wrapawk < wrapfunc.inp cd $(WORKSRC) &&
$(CC) -o ../lib/libfakeroot/libfakeroot-tcp.so.0.0.1 libfakeroot.c communicate.c -fPIC -DPIC -shared -lpthread -ldl -Wl,-soname -Wl,libfakeroot-tcp.so.0
ln -s libfakeroot-tcp.so.0.0.1 $(WORKDIR)/lib/libfakeroot/libfakeroot-tcp.so.0
Copy libfakeroot-tcp.so.0.0.1 to /scratchbox/device_tools/fakeroot-1.4.2/mipsel-gcc-3.4.4-glibc-2.3.2/lib/libfakeroot/libfakeroot-tcp.so.0.0.1 and symlink libfakeroot-tcp.so.0 to it Copy /scratchbox/device_tools/fakeroot-1.4.2/mipsel-gcc-3.4.4-glibc-2.3.2/lib/libfakeroot/[config.h message.h] to $target/usr/include/libfakeroot/ This is necessary to compile the daemon sbrshd for communication with our device (wgt634u,mipsel)
http://www.scratchbox.org/download/files/sbox-releases/1.0/src/sbrsh-7.0.tar.gz
To build it ,type
[sbox-mips_le:~/sbrsh-7.0] > make sbrshd
Copy then sbrshd to
/scratchbox/device_tools/sbrsh-7.0/mipsel-gcc-3.4.4-glibc-2.3.2/sbin/sbrshd
and to the target board and setup the /etc/sbrshd.conf file.
Just play with sb-menu and your wgt634u ! (1st edited by wangji_nnhoan_acong_yahoo_cham_com)
HowtoBuildMipseluClibcToolchainScratchbox
get the src_tree_openwrt: svn co -r 3246 https://svn.openwrt.org/openwrt/branches/whiterussian/openwrt/
mine was svn_checkout_3246_16feb2006
build it in the host_pc just to verify it works (and also to get the rootfs for mipsel-uClibc-0.9.28)
Try to build the same openwrt_tree inside scratchbox ,under HOST_host-gcc we rapidly get stopped after compiling binutils !
But the good new is all the unpack,patching are supplied inside the toolchain_build_mipsel directory !
The cross toolchain openwrt just built on our host_pc is good enough to crosscompile everything,but we cannot just move it inside scratchbox.
Most part can be just copied ,ie rootfs,but we need to compile the binutil,gcc,uClibc from the jailed sbox.
So here is a hack :manual build it
Create /scratchbox/compilers/openwrt/[include,sysroot,sysroot/usr/include] ;Copy the include from the rootfs_mipsel-uClibc-0.9.28 built at the beginning !!!!so as to have the right include files
1 copy openwrt_tree to /scratchbox/users/$USER/home/$USER/openwrt
2 /scratchbox/login to sbox-HOST (host-gcc)
3 cd openwrt/toolchain_build_mipsel/binutils-2.16.1-build/ (empty_dir)
4 [sbox-HOST: ~] > ../binutils-2.16.1/configure --prefix=/scratchbox/compilers/openwrt --target=mipsel-linux-uclibc \ --with-sysroot=/scratchbox/compilers/openwrt/sysroot/
5 make && make install
check by running /scratchbox/compilers/openwrt/bin/mipsel-linux-uclibc-as -v
add PATH=/scratchbox/compilers/openwrt/bin:/scratchbox/compilers/openwrt/mipsel-linux-uclibc/bin:$PATH
before compiling uClibc and gcc.
Here is specs for gcc configure:
Reading specs from /scratchbox/compilers/openwrt/gcc.specs
Configured with:
../gcc-3.4.5/configure --prefix=/scratchbox/compilers/openwrt/ --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=mipsel-linux-uclibc --enable-languages=c,c++ --enable-shared --enable-target-optspace --disable-nls --disable-__cxa_atexit --with-sysroot=/scratchbox/compilers/openwrt/sysroot/
"make" does compile well cpp,gcc g++,libgcc,but gets blocked at libstdc++-v3 ;
Let's do make install even without this libstdc++-v3 (but we can copy from our rootfs_on_pc)
Modify as needed at the compilers/openwrt rootdir gcc.specs,compiler-name,target-setup.sh
and the sbox-mipsel-linux-uclibc-* links in openwrt/bin_dir.Put the rootfs_mipsel into wrt_target as rootstrap_stuff !
Now checking and the rest.
compile hello-world :
[sbox-wrt: ~] > cd hello-world/
[sbox-wrt: ~/hello-world] > make
make all-am
make[1]: Entering directory `/home/wangji/hello-world'
if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o main.c; \ then mv -f ".deps/main.Tpo" ".deps/main.Po"; else rm -f ".deps/main.Tpo"; exit 1; fi
gcc -g -O2 -o hello main.o
make[1]: Leaving directory `/home/wangji/hello-world'
[sbox-wrt: ~/hello-world] > ./hello
bash: ./hello: cannot execute binary file
[sbox-wrt: ~/hello-world] > file hello hello: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[sbox-wrt: ~/hello-world] > qemu-mipsel hello
Hello World!
[sbox-wrt: ~/hello-world] >
Note
The reason why ./hello did not run is due to a typo in register_misc_runner of scratchbox-base_1.0.2.deb package.One has to correct the /scratchbox/sbin/register_misc_runner with the foolowing :
#register mipsel little '\x0a'
register mipsel little '\x08'
then everything will be in order !!!!!
(added by wangji thursday april 20 2006 )
cross-compile sbrshd
[sbox-wrt: ~/sbrsh-7.0] > make clean
rm -f sbrsh sbrshd sb-exportfs *.o
[sbox-wrt: ~/sbrsh-7.0] > make sbrshd
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o daemon.o daemon.c
In file included from daemon.c:16:
fakeroot.h:13:29: fakeroot/config.h: No such file or directory
fakeroot.h:14:30: fakeroot/message.h: No such file or directory
make: *** [daemon.o] Error 1
in order to see where to put the fakeroot/headers ,do
[sbox-wrt: ~/sbrsh-7.0] > cpp -v
Reading specs from /scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/specs
Reading specs from /scratchbox/compilers/openwrt/gcc.specs
Configured with: ../gcc-3.4.5/configure --prefix=/scratchbox/compilers/openwrt/ --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=mipsel-linux-uclibc --enable-languages=c,c++ --enable-shared --enable-target-optspace --disable-nls --disable-cxa_atexit --with-sysroot=/scratchbox/compilers/openwrt/sysroot/
Thread model: posix
gcc version 3.4.5 (OpenWrt-2.0)
/scratchbox/compilers/openwrt/bin/../libexec/gcc/mipsel-linux-uclibc/3.4.5/cc1 -E -quiet -v
-iprefix /scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/ -
ignoring nonexistent directory
"/scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/../../../../mipsel-linux-uclibc/include"
ignoring nonexistent directory "/scratchbox/compilers/openwrt/sysroot//usr/local/include"
ignoring duplicate directory "/scratchbox/compilers/openwrt//lib/gcc/mipsel-linux-uclibc/3.4.5/include"
ignoring nonexistent directory
"/scratchbox/compilers/openwrt//lib/gcc/mipsel-linux-uclibc/3.4.5/../../../../mipsel-linux-uclibc/include"
#include "..." search starts here:
#include <...> search starts here:
/scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/include
/scratchbox/compilers/openwrt/sysroot//usr/include
End of search list.
so we copy the fakeroot/headers to the right include_dir
[sbox-wrt: ~/sbrsh-7.0] >cp -r fakeroot /scratchbox/compilers/openwrt/sysroot/usr/include
[sbox-wrt: ~/sbrsh-7.0] > make sbrshd
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o daemon.o daemon.c
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o fakeroot.o fakeroot.c
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o ident.o ident.c
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o buffer.o buffer.c
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o common.o common.c
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o mount.o mount.c
cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o protocol.o protocol.c
cc -o sbrshd daemon.o fakeroot.o ident.o buffer.o common.o mount.o protocol.o -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -lutil
[sbox-wrt: ~/sbrsh-7.0] >
the compilation is fine;let's verify
[sbox-wrt: ~/sbrsh-7.0] > file sbrshd
sbrshd: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[sbox-wrt: ~/sbrsh-7.0] >
to build libfakeroot-tcp.so.0.0.1 and put in doc_directory.Compile fakeroot in host_pc first,then copy [wrap*.h ] into our fakeroot_topdir-remember to patch with communicate.c-
This is necessary because we don't have wrapawk from inside scratchbox !
[sbox-wrt: ~/fakeroot-1.4.2] > ./configure \
--prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib/libfakeroot \ --program-suffix=-tcp --with-ipc=tcp --with-dbformat=path --build=i386-pc-linux-gnu --host=mipsel-linux-uclibc \
&& make &&make install
[sbox-wrt: ~/fakeroot-1.4.2/fake] > ./configure --prefix=/usr --mandir=/usr/share/man --program-suffix=-tcp --host=mipsel-linux-uclibc --build=i686-pc-none &&make && make install
to compile gdbserver_mips
[sbox-wrt: ~/gdb-6.3/gdb/gdbserver] > ./configure --host=mipsel-linux-uclibc && make
trying compile gdb gets into trouble at configure readline ! but we don't need gdb_mips !
to build strace_mips
[sbox-wrt: ~/strace-4.5.11] > ./configure --host=mipsel-linux-uclibc --build=i386-pc-linux-gnu && make
now we have everything ,to fill up the device_tools directory with our mipsel-uClibc-0.9.28 !
have fun ! wangji_acong_laixa_cham_fr feb28-2006
BuildPowerpcToolchainScratchbox
>sb-conf sh Compiler: host-gcc Devkits: none CPU-transparency: none
make sure you choose this gcc-glibc configuration
demo-ppc405.sh : eval `cat powerpc-405.dat gcc-3.4.4-glibc-2.3.5-hdrs-2.6.11.2.dat` sh all.sh --notest create /scratchbox/compilers/ppc-405 then execute "sh demo-ppc405.sh"
create your links to sbox for gcc_wrapper stuffs
>ls /scratchbox/compilers/ppc-405/bin/sbox*
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-405-linux-gnu-c++filt
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-405-linux-gnu-cc
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-addr2line
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-ar
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-as
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-cpp
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-g++
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-gcc
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-gccbug
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-gcov
/scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-ld /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-nm /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-objcopy /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-objdump /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-ranlib /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-readelf /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-size /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-strings /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-strip
>cat /scratchbox/compilers/ppc-405/compiler-name
ppc-405:/scratchbox/compilers/ppc-405:powerpc:linux:glibc:ppc
>cat /scratchbox/compilers/ppc-405/target_setup.sh
#!/bin/sh (-)
target=$1
mkdir -p $target/lib
mkdir -p $target/usr/lib
mkdir -p $target/usr/include
mkdir -p $target/usr/bin
cp -af /scratchbox/compilers/ppc-405/lib/* $target/lib/
cp -af /scratchbox/compilers/ppc-405/powerpc-405-linux-gnu/lib/* $target/lib/
cp -af /scratchbox/compilers/ppc-405/powerpc-405-linux-gnu/lib/libstdc++* $target/usr/lib/
find /scratchbox/compilers/ppc-405/usr/ -mindepth 1 -maxdepth 1 -not -name libexec -exec cp -af {} $target/usr/ \;
cp -af /scratchbox/compilers/ppc-405/include/* $target/usr/include/
ln -sf /bin/cpp $target/lib/
ln -sf /bin/cc $target/usr/bin/
chmod +x $target/lib/ld-*.so
>cp /scratchbox/compilers/ppc-405/lib/gcc/powerpc-405-linux-gnu/3.4.4/specs /scratchbox/compilers/ppc-405/gcc.specs
[sbox-
~]> sb-conf se powerpc
sb-conf sh
Compiler: ppc-405 Devkits: none CPU-transparency: qemu-ppc
[sbox-powerpc: ~] >gcc -v
Reading specs from /scratchbox/compilers/ppc-405/lib/gcc/powerpc-405-linux-gnu/3.4.4/specs
Reading specs from /scratchbox/compilers/ppc-405/gcc.specs
Configured with: /home/wangji/crosstool-0.38/build/powerpc-405-linux-gnu/gcc-3.4.4-glibc-2.3.5/gcc-3.4.4/configure --target=powerpc-405-linux-gnu --host=i386-host_pc-linux-gnu --prefix=/scratchbox/compilers/ppc-405 --with-cpu=405 --enable-cxx-flags=-mcpu=405 --with-headers=/scratchbox/compilers/ppc-405/powerpc-405-linux-gnu/include --with-local-prefix=/scratchbox/compilers/ppc-405/powerpc-405-linux-gnu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long Thread model: posix gcc version 3.4.4
[sbox-powerpc: ~] >cd hello-world && make clean && make
make all-am make[1]: Entering directory `/home/wangji/hello-world' if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o main.c; \ then mv -f ".deps/main.Tpo" ".deps/main.Po"; else rm -f ".deps/main.Tpo"; exit 1; fi gcc -g -O2 -o hello main.o make[1]: Leaving directory `/home/wangji/hello-world'
[sbox-powerpc: ~/hello-world]>file hello
hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not stripped
[sbox-powerpc: ~/hello-world]>qemu-ppc hello
/lib/ld.so.1: No such file or directory
quick hack to cheat :
[sbox-powerpc: ~/hello-world] > cp /scratchbox/compilers/ppc-405/lib /targets/links/lib
[sbox-powerpc: ~/hello-world] > qemu-ppc hello
Hello World!
buld tools for cputransparency and rootfs
sbrshd :
cp -r fakeroot /scratchbox/compilers/ppc-405/lib/gcc/powerpc-405-linux-gnu/3.4.4/include/
make sbrshd
file sbrshd
sbrshd: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not stripped
copy sbrshd to TARGET/usr/sbin
fakeroot-1.4.2 :
./configure --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib/libfakeroot --program-suffix=-tcp --with-ipc=tcp --with-dbformat=path --build=i686-linux &&make install ../configure --prefix=/usr --mandir=/usr/share/man --program-suffix=-tcp cd fake && ../configure --prefix=/usr --mandir=/usr/share/man --program-suffix=-tcp --build=i686-linux && make install
strace-4.5.11 :
./configure --build=i686-linux --host=powerpc-linux && make copy "strace, strace-graph " to TARGET/powerpc/usr/bin
gdbserver-6.3 :
cd gdb-6.3/gdb/gdbserver ./configure --build=i686-linux --host=powerpc-linux && make
copy "gdbserver gdbreplay" to TARGET/powerpc/usr/sbin
busybox-1.01 :
/scratchbox/users/wangji/home/wangji/busybox-1.01/archival/libipkg/args.c: In function `args_init':
/scratchbox/users/wangji/home/wangji/busybox-1.01/archival/libipkg/args.c:63: warning: passing arg 1 of `bb_xasprintf' from incompatible pointer type /scratchbox/users/wangji/home/wangji/busybox-1.01/archival/libipkg/args.c:63: error: void value not ignored as it ought to be make: *** [/scratchbox/users/wangji/home/wangji/busybox-1.01/archival/libipkg/args.o] Erreur 1 wangji@laixa:/scratchbox/users/wangji/home/wangji/busybox-1.01$
so let's try
busybox-1.00 :
do make menuconfig outside scratchbox (this is due to builtin /busybox-1.00/scripts/config/conf x86_binary ) then do make from inside sbox-powerpc> make PREFIX=/usr install to finish creating links. think to setuid root busybox file.
have fun wangji 03-03-2006
End of edit conflict