Crosstool Environment in a Solaris Zone

Background
The task of building Java ME CDC-HI binaries and their associated cross development environments tends to be very linux-centric.  Utilities like Crosstool, which make this process much more tolerable, also make various linux and GNU assumptions that differ from standard Solaris.  By introducing new paths and GNU versions of applications, it is possible to mimic this environment in Solaris.   Furthermore, by creating a new zone with this environment, we can isolate these changes without affecting other Solaris system settings.

1. Create a Solaris zone called 'toolzone'

Note: This step is system specific.  For example, the hostname and IP address for 'toolzone' was predefined.  In addition, the network interface (i.e. 'set physical=iprb0') is likely to be different also.

Here's the command-line session for creating the zone:

phoenix://# mkdir /zone
phoenix://# zonecfg -z toolzone
toolzone: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:toolzone> create
zonecfg:toolzone> set zonepath=/zone/toolzone
zonecfg:toolzone> set autoboot=true
zonecfg:toolzone> add net
zonecfg:toolzone:net> set address=toolzone
zonecfg:toolzone:net> set physical=iprb0
zonecfg:toolzone:net> end
zonecfg:toolzone> info
zonepath: /zone/toolzone
autoboot: true
pool:
inherit-pkg-dir:
dir: /lib
inherit-pkg-dir:
dir: /platform
inherit-pkg-dir:
dir: /sbin
inherit-pkg-dir:
dir: /usr
net:
address: toolzone
physical: iprb0
zonecfg:toolzone> verify
zonecfg:toolzone> commit
zonecfg:toolzone> \^D

phoenix://# zoneadm list -vc
ID NAME STATUS PATH
0 global running /
- toolzone configured /zone/toolzone

phoenix://# zoneadm -z toolzone install
Preparing to install zone <toolzone>.
Creating list of files to copy from the global zone.
Copying <6666> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <945> packages on the zone.
Initialized <945> packages on zone.
Zone <toolzone> is initialized.
Installation of <2> packages was skipped.
Installation of these packages generated warnings: <SUNWcsu SUNWsogm>
The file </zone/toolzone/root/var/sadm/system/logs/install_log> contains a log of the zone installation.
2.  Configure the zone.

2a. Create a zone-specific /usr/bin directory and copy the contents of the global zone's /usr/bin to this new directory.
phoenix://# mkdir -p /zone/toolzone/usr/bin
phoenix://# cd /usr/bin
phoenix://# tar cf - . | (cd /zone/toolzone/usr/bin; tar xfp -)
2b. Create a loopback mount for toolzone to this new version of /usr/bin:
phoenix://# zonecfg -z toolzone
zonecfg:toolzone> addfs
zonecfg:toolzone:fs> set dir=/usr/bin
zonecfg:toolzone:fs> set special=/zone/toolzone/usr/bin
zonecfg:toolzone:fs> set type=lofs
zonecfg:toolzone:fs> end
zonecfg:toolzone> \^D
2c. Boot and configure the newly created zone:
phoenix://# zoneadm -z toolzone boot
phoenix://# zlogin -C toolzone
2d. Change the path of the default shell to /usr/bin/bash.  This is required for crosstool to operate correctly.
toolzone://# cd /usr/bin
toolzone:bin/# mv sh sh.ORIG
toolzone:bin/# ln -s /usr/bin/bash sh
2e. Create a new user in toolzone.  For this example, we'll use 'cdc'.  This exercise is left to the user.
toolzone://# grep cdc /etc/passwd
cdc:x:600:10:CDC-HI build user:/export/home/cdc:/usr/bin/bash
2f. Create a directoy called /opt/gnulinks and make sure the 'cdc' user owns it.  This directory will house versions and links  to GNU utilities which differ from their Solaris counterparts.
toolzone://# mkdir /opt/gnulinks
toolzone://# chown cdc:staff /opt/gnulinks
toolzone://# ls -ld /opt/gnulinks
drwxr-xr-x 2 cdc staff 512 Jun 19 13:14 /opt/gnulinks

3. As the newly created 'cdc' user, configure the zone to build both the crosstool environment and CDC-HI

3a. Login to the zone as the 'cdc' user.
phoenix://# zlogin -l cdc toolzone
[Connected to zone 'toolzone' pts/6]
Last login: Mon Jun 19 12:57:05 on pts/6
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
toolzone:~/$
3b. To get a zone-specific prompt, you might want to have an entry in ~cdc/.bash_profile like:
export PS1='\\h:\\W/\\$ '
3c.  Create links in /opt/gnulinks/bin which point to GNU versions of unix utilities.  This can be accomplised by executing the gnulinks.sh script which looks like:
#!/bin/sh
GNULINKS_DIR=/opt/gnulinks/bin
GNU_PROGS="ar as egrep grep m4 make nm objcopy objdump strings strip tar thumb"

mkdir -p ${GNULINKS_DIR}
cd ${GNULINKS_DIR}
for PROG in ${GNU_PROGS}
do
ln -s /usr/sfw/bin/g${PROG} ${PROG}
done

toolzone:~/$ sh gnulinks.sh
3d. Modify PATH of 'cdc' user by putting the following line in ~cdc/.bash_profile:
export PATH=/opt/gnulinks/bin:/usr/sfw/bin:$PATH

toolzone:~/$ which tar
/opt/gnulinks/bin/tar

3e.  Build and install GNU specific utilities required for crosstool which differ from those provided by Solaris.  They include binutils, fileutils, gawk(1), patch(1) and sed(1).  A build-gnu-bin.sh is furnished to automate this, and looks like:

#!/bin/sh
GNULINKS_DIR=/opt/gnulinks

mkdir -p ${HOME}/GNU

for PROG in $\*
do
cd ${HOME}/GNU
PREFIX=`echo ${PROG} | sed 's/-.\*//'`
wget ftp://ftp.gnu.org/gnu/${PREFIX}/${PROG}.tar.gz
tar xzf ${PROG}.tar.gz
cd ${PROG}
./configure --prefix=${GNULINKS_DIR}
make
make install
done

toolzone:~/$ sh build-gnu-bin.sh fileutils-4.1 gawk-3.1.5 patch-2.5.4 sed-4.1.4

3f. Create a native version of gcc(1).  The Solaris 10 version of gcc found in /usr/sfw/bin uses the stock Solaris linker, ld(1), found in /usr/ccs/bin.  Later versions of glibc will only accept the GNU version of ld(1).

toolzone:~/$ cd ~/GNU
toolzone:GNU/$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-3.4.3/gcc-3.4.3.tar.bz2
toolzone:GNU/$ bunzip2 gcc-3.4.3.tar.bz2
toolzone:GNU/$ tar -xf gcc-3.4.3.tar
toolzone:GNU/$ cd gcc-3.4.3
toolzone:gcc-3.4.3/$ ./configure --prefix=/opt/gnulinks
toolzone:gcc-3.4.3/$ make
toolzone:gcc-3.4.3/$ make install

3g. Build and install a GNU version of binutils using the aforementioned build-gnu-bin.sh script.

 

toolzone:~/$ sh build-gnu-bin.sh binutils-2.16

 4a.  As the 'cdc' user, build a cross development environment using crosstool.  These instructions are taken from http://www.kegel.com/crosstool/crosstool-0.43/doc/crosstool-howto.html#quick

toolzone:~/$ cd
toolzone:~/$ wget http://kegel.com/crosstool/crosstool-0.43.tar.gz
toolzone:~/$ tar -xzvf crosstool-0.43.tar.gz
toolzone:~/$ su -
toolzone://# mkdir /opt/crosstool
toolzone://# chown cdc:staff /opt/crosstool
toolzone://# exit
toolzone:~/$
4b. As an example, use these configuration files to build a crosstool for a Sharp Zaurus SL-5000D running OpenZaurus 3.5.1:
toolzone:~/$ cd ~/crosstool-0.43
toolzone:crosstool-0.43/$ cat oz-3.5.1.sh
#!/bin/sh
set -ex
TARBALLS_DIR=$HOME/downloads
RESULT_TOP=/opt/crosstool
export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c,c++"
export GCC_LANGUAGES

# Really, you should do the mkdir before running this,
# and chown /opt/crosstool to yourself so you don't need to run as root.
mkdir -p $RESULT_TOP

# Build the toolchain. Takes a couple hours and a couple gigabytes.

eval `cat arm-softfloat.dat oz-3.5.1.dat` sh all.sh --notest

echo Done.

toolzone:crosstool-0.43/$ cat oz-3.5.1.dat
BINUTILS_DIR=binutils-2.15
GCC_DIR=gcc-3.4.2
GLIBC_DIR=glibc-2.3.2
LINUX_DIR=linux-2.4.18
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.2
GDB_DIR=gdb-6.4
4c. Build the toolchain
toolzone:crosstool-0.43/$ sh oz-3.5.1.sh > OUT.oz-3.5.1 2>&1 &
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jim Connors

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today