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
Most binaries for the toolchains described below can be downloaded from
- }}}
{{{ snapshot
- }}}
This page describes how to build a scratchbox toolchain using [http://kegel.com/crosstool 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 [http://kegel.com/crosstool 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 developmentBR scratchbox-devkit-doctools - document generation toolsBR scratchbox-devkit-perl - additional Perl modules BR
Toolchains (optional):
scratchbox-toolchain-arm-gcc3.3-glibc2.3BR scratchbox-toolchain-i686-gcc3.3-glibc2.3BR scratchbox-toolchain-arm-gcc3.2-uclibc20040229BR scratchbox-toolchain-i386-gcc3.2-uclibc20040229BR
- Build armeb-toolchain-nslu2
- You can also build custom toolchain packages. See Scratchbox toolchains [5].
http://scratchbox.org/wiki/CrossToolToolchain 'armv5b-softfloat' Start Scratchbox with command:
- $ /scratchbox/login
[sbox-HOST: ~] > sb-menuBR
- Build device_tools for armeb_target
(needs to communicate/debug thru CPU_transparency with nslu2)
Device_tools: strace , sbrshd ,fakemonBR
gdbserver,gdb (DDD) Download those src files into /scratchbox/packagesBR Login scratchbox,select HOST then untar src ,select target armeb BRBR
strace
strace-4.5.11 needs to be patched for arm .BRThose patches are seen on /slug/openembedded/packages/strace/ ,when one runs the MasterMakefile ( http://www.nslu2-linux.org ).BR {{{ arm-compilation.patch arm-syscallent.patch arm-syscall.patch quota.patch
- }}}
and a "#include "asm/ptrace.h" to signal.c and syscall.cBR
root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p0 < patches/arm-syscallent.patchBR patching file strace-4.5.4/linux/arm/syscallent.hBR root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p1 < patches/quota.patchBR patching file resource.cBR root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p1 < patches/arm-syscall.patchBR patching file linux/arm/syscall.hBR patching file linux/arm/dummy.hBR root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# patch -p1 < patches/arm-compilation.patchBR patching file syscall.cBR Hunk #1 succeeded at 747 (offset 51 lines).BR root@laixa:/scratchbox/users/wangji/home/wangji/strace-4.5.11# cat patches/arm-syscall.patchBRBR
[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] > makeBR [sbox-nslu2: ~/build_strace] > file straceBR strace: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), strippedBRBRBR
Since this strace runs on the nslu2-armeb target ,copy it to TARGET/nslu2/usr/sbin BRBRBR
{{{ 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" }}} BRBR
compilation_of_sbrsh
[sbox-HOST: ~/sbrsh-7.0] > make cleanBR
rm -f sbrsh sbrshd sb-exportfs *.oBR [sbox-HOST: ~/sbrsh-7.0] > make sbrshBR [sbox-HOST: ~/sbrsh-7.0] > file sbrshBR sbrsh: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not strippedBRBR
compilation_of_daemon_sbrshd
[sbox-HOST: ~/sbrsh-7.0] > sb-conf se nslu2 BR Shell restarting...BR [sbox-nslu2: ~] >BR [sbox-nslu2: ~] > cd sbrsh-7.0/BR [sbox-nslu2: ~/sbrsh-7.0] > make cleanBR rm -f sbrsh sbrshd sb-exportfs *.oBR
[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/sbrshdBR This sbrsh will be copied to /scratchbox/device_tools/sbrsh-7.0/armv5b-gcc-3.4.4-glibc-2.3.5/sbin/BR and sbrshd.init as /scratchbox/device_tools/sbrsh-7.0/armv5b-gcc-3.4.4-glibc-2.3.5/etc/sbrshdBR Those etc and sbin containing sbrshd must be transfered by some way-serial connection,scp ..- to the rootfilesystem of target nslu2 .BR There is however a remark : let's check the lib dependencies BR [sbox-nslu2: ~/sbrsh-7.0] > ldd sbrshdBR
libutil.so.1 => /lib/libutil.so.1 (0x00000000)BR libc.so.6 => /lib/libc.so.6 (0x00000000)BR /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000)BR
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 .BR
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 !BR
[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 sbrshdBR
sbrshd: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, statically linked, not strippedBR [sbox-nslu2: ~/sbrsh-7.0] >BRBR
fakeroot-1.4.2
to build this daemon. BR
fakemon needs to be patched with BR
<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 BR
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 BR
for the rest about fakeroot,follow BR
<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> BR BRBR
- gdbserver
- Let's start a session on nslu2-armeb and try compile cross-gdb ,and armeb-gdbserver
~$ scratchboxBR
Welcome to Scratchbox, the cross-compilation toolkit!BR Use 'sb-menu' to change your compilation target.BR See /scratchbox/doc/ for documentation.BR download from the net,untargz and patchBRBR
[sbox-nslu2: ~] >wget http://ftp.gnu.org/gnu/gdb/gdb-6.3.tar.gz
[sbox-nslu2: ~] >tar xzf /scratchbox/packages/gdb-6.3.tar.gzBR [sbox-nslu2: ~] > cd gdb-6.3BR
{{{ [sbox-nslu2: ~/gdb-6.3] >patch -p1 < ../gdb_patch/uclibc.patch
- }}}
patching file bfd/config.bfdBR patching file bfd/configure.inBR patching file bfd/configureBR
[sbox-nslu2: ~/gdb-6.3] > patch -p1 < ../gdb_patch/gdbserver-cflags-last.diffBR can't find file to patch at input line 3BR Perhaps you used the wrong -p or --strip option?BR The text leading up to this was:BR
BR |--- gdb/gdbserver/Makefile.in.orig 2004-10-05 18:52:56.298419032 +0200BR |+++ gdb/gdbserver/Makefile.in 2004-10-05 18:53:10.442268840 +0200BR
[sbox-nslu2: ~/gdb-6.3] patch -p0 < ../gdb_patch/gdbserver-cflags-last.diff
BR patching file gdb/gdbserver/Makefile.inBRBR [sbox-nslu2: ~/gdb-6.3] > cd ..BR [sbox-nslu2: ~] > mkdir build_gdbarmebBR [sbox-nslu2: ~] > cd build_gdbarmeb/BR [sbox-nslu2: ~/build_gdbarmeb] >BR
[sbox-nslu2: ~/build_gdbarmeb] > ../gdb-6.3/gdb/gdbserver/configure --host=armv5b-softfloat-linux
[sbox-nslu2: ~/build_gdbarmeb] > makeBRBR
[sbox-nslu2: ~/build_gdbarmeb] > file gdbserverBR gdbserver: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not strippedBR [sbox-nslu2: ~/build_gdbarmeb] > strip gdbserverBR [sbox-nslu2: ~/build_gdbarmeb] > file gdbserverBR gdbserver: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), strippedBR [sbox-nslu2: ~/build_gdbarmeb] > ls gdb*BR gdbreplay gdbreplay.o gdbserverBR [sbox-nslu2: ~/build_gdbarmeb] > file gdbreplayBR gdbreplay: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), not strippedBR [sbox-nslu2: ~/build_gdbarmeb] > strip gdbreplay && file gdbreplayBR gdbreplay: ELF 32-bit MSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), strippedBR [sbox-nslu2: ~/build_gdbarmeb] > BRBR
These armeb-gdbserver armeb-gdbreplay have to be put on somewhere /usr/bin or /usr/sbin of the armeb-nslu2-target !BR that's it !BR
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.BR Since this a tool in sbox point of view,let switch to HOST targetBR [sbox-nslu2: ~/build_gdbarmeb] > sb-conf se HOST BR Shell restarting...BR
[sbox-HOST: ~/gdb-6.3] > patch -p1 < ../gdb_patch/sim-install.patch
[sbox-HOST: ~] > mkdir build-crossgdbarmebBR [sbox-HOST: ~] > cd build-crossgdbarmeb/BR
[sbox-HOST: ~/build-crossgdbarmeb] > ../gdb-6.3/configure --host=i386-pc-linux-gnu --target=armv5b-softfloat-linux
[sbox-HOST: ~/build-crossgdbarmeb] >makeBRBR After a while :BR [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.BR On the desktop_scratchbox side,using sb-menu to setup the target,crosscompiler and cputransparency method
- on nslu2 side sbrshd ,gdbserver,openssh
- Compiler: armv5b-gcc-3.4.5-glibc-2.3.5 Devkits: none CPU-transparency: sbrsh}}} Now 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)
- {{{ 4. install
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 BR # Little-endian MIPSBR # BR # To create a toolchain for the Linksys wrt54g, select glibc-2.2.3 BR # See http://seattlewireless.net/index.cgi/LinksysWrt54g BR # http://www.batbox.org/wrt54g-linux.html BR # Note: recent wrt54g firmware uses uclibc, which behaves like a subsetted glibc. BR # There are patches to build uclibc toolchains in the contrib directory, BR # but they're not integrated yet. However, you can still use a glibc BR # toolchain; you'll either have to BR # a) not call the missing functions, BR # b) use a stub library like http://www.xse.com/leres/tivo/downloads/libtivohack/ BR # or c) link your programs statically if you want them to run onBR # the wrt54g.BR
TARBALLS_DIR=$HOME/downloadsBR RESULT_TOP=/scratchbox/compilersBR PREFIX=$RESULT_TOP/mipsel-gcc-3.3.6-glibc-2.3.2BR export TARBALLS_DIR RESULT_TOP PREFIXBR GCC_LANGUAGES="c,c++"BR export GCC_LANGUAGESBR
unset LD_LIBRARY_PATHBR mkdir -p $RESULT_TOPBR
# Build the toolchain. Takes a couple hours and a couple gigabytes.BR
eval cat mipsel.dat gcc-3.4.4-glibc-2.3.2-hdrs-2.6.11.2.dat sh all.sh --notest
echo Done.BR
select HOST ,gcc-host with sb-menu. To build toolchain,from inside crosstool-0.38 typeBR
[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 sboxBR
[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-*.soUse sb-menu to create a target : mips_le (little endian ) with cross compiler :mipsel-gcc-3.4.4-glibc-2.3.2BR The target rootstrap will be created later in another part of this tutorial !!!BR Now,we need to build the device tools for message passing between sbox and the deviceBR
device_tools
build libfakeroot-tcp.so.0.0.1 get fakeroot-1.4.2.tar.gz fromBR
ftp://ftp.debian.org/debian/pool/main/f/fakeroot/fakeroot_1.4.2.tar.gz
patch communicate.patch from BR
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/ BR mine was svn_checkout_3246_16feb2006 BR build it in the host_pc just to verify it works (and also to get the rootfs for mipsel-uClibc-0.9.28) BR Try to build the same openwrt_tree inside scratchbox ,under HOST_host-gcc we rapidly get stopped after compiling binutils ! BR But the good new is all the unpack,patching are supplied inside the toolchain_build_mipsel directory !BR The cross toolchain openwrt just built on our host_pc is good enough to crosscompile everything,but we cannot just move it inside scratchbox.BR Most part can be just copied ,ie rootfs,but we need to compile the binutil,gcc,uClibc from the jailed sbox. BR So here is a hack :manual build it BR 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 BR 2 /scratchbox/login to sbox-HOST (host-gcc) BR 3 cd openwrt/toolchain_build_mipsel/binutils-2.16.1-build/ (empty_dir) BR 4 [sbox-HOST: ~] > ../binutils-2.16.1/configure --prefix=/scratchbox/compilers/openwrt --target=mipsel-linux-uclibc \ --with-sysroot=/scratchbox/compilers/openwrt/sysroot/ BR 5 make && make installBR check by running /scratchbox/compilers/openwrt/bin/mipsel-linux-uclibc-as -vBR add PATH=/scratchbox/compilers/openwrt/bin:/scratchbox/compilers/openwrt/mipsel-linux-uclibc/bin:$PATHBR before compiling uClibc and gcc.BR Here is specs for gcc configure:BR Reading specs from /scratchbox/compilers/openwrt/gcc.specsBR
Configured with:BR ../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/ BR "make" does compile well cpp,gcc g++,libgcc,but gets blocked at libstdc++-v3 ;BR Let's do make install even without this libstdc++-v3 (but we can copy from our rootfs_on_pc)BR Modify as needed at the compilers/openwrt rootdir gcc.specs,compiler-name,target-setup.shBR and the sbox-mipsel-linux-uclibc-* links in openwrt/bin_dir.Put the rootfs_mipsel into wrt_target as rootstrap_stuff !BR Now checking and the rest.BR compile hello-world :BR [sbox-wrt: ~] > cd hello-world/BR [sbox-wrt: ~/hello-world] > makeBR make all-amBR make[1]: Entering directory `/home/wangji/hello-world'BR 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; fiBR gcc -g -O2 -o hello main.oBR make[1]: Leaving directory `/home/wangji/hello-world'BR [sbox-wrt: ~/hello-world] > ./helloBR bash: ./hello: cannot execute binary fileBR [sbox-wrt: ~/hello-world] > file hello hello: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not strippedBR [sbox-wrt: ~/hello-world] > qemu-mipsel helloBR Hello World!BR [sbox-wrt: ~/hello-world] > BR
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 : BR #register mipsel little '\x0a' BR register mipsel little '\x08' BR then everything will be in order !!!!! BR(added by wangji thursday april 20 2006 )
BR cross-compile sbrshdBR [sbox-wrt: ~/sbrsh-7.0] > make cleanBR rm -f sbrsh sbrshd sb-exportfs *.oBR [sbox-wrt: ~/sbrsh-7.0] > make sbrshdBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o daemon.o daemon.cBR In file included from daemon.c:16:BR fakeroot.h:13:29: fakeroot/config.h: No such file or directoryBR fakeroot.h:14:30: fakeroot/message.h: No such file or directoryBR make: *** [daemon.o] Error 1BR BR in order to see where to put the fakeroot/headers ,doBR [sbox-wrt: ~/sbrsh-7.0] > cpp -vBR Reading specs from /scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/specsBR Reading specs from /scratchbox/compilers/openwrt/gcc.specsBR 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/BR Thread model: posixBR gcc version 3.4.5 (OpenWrt-2.0)BR /scratchbox/compilers/openwrt/bin/../libexec/gcc/mipsel-linux-uclibc/3.4.5/cc1 -E -quiet -vBR -iprefix /scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/ -BR ignoring nonexistent directoryBR "/scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/../../../../mipsel-linux-uclibc/include"BR ignoring nonexistent directory "/scratchbox/compilers/openwrt/sysroot//usr/local/include"BR ignoring duplicate directory "/scratchbox/compilers/openwrt//lib/gcc/mipsel-linux-uclibc/3.4.5/include"BR ignoring nonexistent directoryBR "/scratchbox/compilers/openwrt//lib/gcc/mipsel-linux-uclibc/3.4.5/../../../../mipsel-linux-uclibc/include"BR #include "..." search starts here:BR #include <...> search starts here:BR /scratchbox/compilers/openwrt/bin/../lib/gcc/mipsel-linux-uclibc/3.4.5/includeBR /scratchbox/compilers/openwrt/sysroot//usr/includeBR End of search list.BR so we copy the fakeroot/headers to the right include_dirBR [sbox-wrt: ~/sbrsh-7.0] >cp -r fakeroot /scratchbox/compilers/openwrt/sysroot/usr/includeBRBR [sbox-wrt: ~/sbrsh-7.0] > make sbrshdBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o daemon.o daemon.cBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o fakeroot.o fakeroot.cBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o ident.o ident.cBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o buffer.o buffer.cBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o common.o common.cBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o mount.o mount.cBR cc -Wall -Wmissing-prototypes -Wformat=2 -Wshadow -pipe -DREVISION=0 -O2 -fomit-frame-pointer -DNDEBUG -c -o protocol.o protocol.cBR 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 -lutilBR [sbox-wrt: ~/sbrsh-7.0] >BR the compilation is fine;let's verifyBR [sbox-wrt: ~/sbrsh-7.0] > file sbrshdBR sbrshd: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not strippedBR [sbox-wrt: ~/sbrsh-7.0] > BR 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-BR This is necessary because we don't have wrapawk from inside scratchbox !BR [sbox-wrt: ~/fakeroot-1.4.2] > ./configure \ && 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 BR [sbox-wrt: ~/gdb-6.3/gdb/gdbserver] > ./configure --host=mipsel-linux-uclibc && makeBR trying compile gdb gets into trouble at configure readline ! but we don't need gdb_mips !BR to build strace_mipsBR [sbox-wrt: ~/strace-4.5.11] > ./configure --host=mipsel-linux-uclibc --build=i386-pc-linux-gnu && makeBR now we have everything ,to fill up the device_tools directory with our mipsel-uClibc-0.9.28 !BR have fun ! wangji_acong_laixa_cham_fr feb28-2006BR
>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"}}} BR create your links to sbox for gcc_wrapper stuffsBR >ls /scratchbox/compilers/ppc-405/bin/sbox*BR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-405-linux-gnu-c++filtBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-405-linux-gnu-ccBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-addr2lineBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-arBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-asBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-cppBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-g++BR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-gccBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-gccbugBR /scratchbox/compilers/ppc-405/bin/sbox-powerpc-linux-gcovBR /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-stripBR >cat /scratchbox/compilers/ppc-405/compiler-nameBR ppc-405:/scratchbox/compilers/ppc-405:powerpc:linux:glibc:ppcBR BR >cat /scratchbox/compilers/ppc-405/target_setup.shBR {{{#!/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 }}} BR >cp /scratchbox/compilers/ppc-405/lib/gcc/powerpc-405-linux-gnu/3.4.4/specs /scratchbox/compilers/ppc-405/gcc.specsBR [sbox-HOST:~]> sb-conf se powerpcBR sb-conf shBR Compiler: ppc-405 Devkits: none CPU-transparency: qemu-ppc [sbox-powerpc: ~] >gcc -v BR Reading specs from /scratchbox/compilers/ppc-405/lib/gcc/powerpc-405-linux-gnu/3.4.4/specsBR Reading specs from /scratchbox/compilers/ppc-405/gcc.specsBR {{{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-BuildPowerpcToolchainScratchbox
[sbox-powerpc: ~] >cd hello-world && make clean && make BR
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 BR
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 helloBR /lib/ld.so.1: No such file or directory
quick hack to cheat :BR [sbox-powerpc: ~/hello-world] > cp /scratchbox/compilers/ppc-405/lib /targets/links/lib BR
[sbox-powerpc: ~/hello-world] > qemu-ppc hello BR Hello World!
buld tools for cputransparency and rootfs
sbrshd : BR
cp -r fakeroot /scratchbox/compilers/ppc-405/lib/gcc/powerpc-405-linux-gnu/3.4.4/include/ BR make sbrshdBR
file sbrshd BR
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 strippedBR copy sbrshd to TARGET/usr/sbinBR
fakeroot-1.4.2 : BR
./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 :BR
/configure --build=i686-linux --host=powerpc-linux && make copy "strace, strace-graph " to TARGET/powerpc/usr/bin
gdbserver-6.3 :BR 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 :BR
- /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$ BR
so let's try BR
busybox-1.00 :BR 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.BR
have fun wangji 03-03-2006
End of edit conflict