Per compilare un'applicazione per il FreeRunner su sistema operativo OpenMoko possiamo scegliere tre strade:
Per installare la toolchain su Debian Lenny si sono seguite queste istruzioni: Openmoko application development in 5 minutes.
Si installano preventivamente i pacchetti:
apt-get install alien autoconf automake autotools-dev build-essential ccache check curl \ fakeroot gettext intltool libgconf2-dev libglib2.0-dev libtool libxrender-dev mtools uboot-mkimage
Si scarica la toolchain precompilata dal repository OpenMoko, esiste la versione i686 e amd64, il pacchetto non è rilocabile e va in /usr/local/openmoko. Invece di installare il tarball, lo si trasforma in uno pseudo pacchetto .deb facilmente (dis)installabile.
Scegliamo openmoko-i686-20090323-armv4t-linux-gnueabi-toolchain-openmoko.tar.bz2 (pacchetto per i686, per compilare codice arm su piattaforma GNU/Linux) ed eseguiamo:
bunzip2 openmoko-i686-20090323-armv4t-linux-gnueabi-toolchain-openmoko.tar.bz2 gzip openmoko-i686-20090323-armv4t-linux-gnueabi-toolchain-openmoko.tar fakeroot alien -d openmoko-i686-20090323-armv4t-linux-gnueabi-toolchain-openmoko.tar.gz
Il pacchetto .deb risultante è installabile con
sudo dpkg -i openmoko-i686_20090323-2_all.deb
Prima di compilare qualcosa si deve settare l'environment giusto (PATH, CPPFLAGS, CXXFLAGS, LDFLAGS, ecc.):
source /usr/local/openmoko/arm/environment-setup
Quindi si usa il compilatore apposito
arm-angstrom-linux-gnueabi-gcc -o test test.c
Un'ipotetico Makefile potrebbe contenere qualcosa del tipo:
export CC = arm-angstrom-linux-gnueabi-gcc
binary:
$(CC) -o test test.c
Se il programma da compilare dipende da una libreria OpenMoko, bisogna installarla nella toolchain. Prima di tutto si deve impostare i repository da cui attingere in /usr/local/openmoko/arm/arm-angstrom-linux-gnueabi/etc/opkg.conf.
L'impostazione predefinita prevede di scaricare da unstable, ecco invece come scaricare i pacchetti da 2008.12:
arch all 1 src/gz all http://downloads.openmoko.org/repository/Om2008.8/all arch armv4t 26 src/gz armv4t http://downloads.openmoko.org/repository/Om2008.8/armv4t arch om-gta02 31 src/gz om-gta02 http://downloads.openmoko.org/repository/Om2008.8/om-gta02
Ecco l'esempio di come installare un pacchetto -dev:
. /usr/local/openmoko/arm/environment-setup opkg-target update opkg-target list opkg-target install gpsd-dev
L'elenco dei pacchetti disponibili viene salvato in /usr/local/openmoko/arm/arm-angstrom-linux-gnueabi/usr/lib/opkg/lists/.
I pacchetti vengono installati sotto /usr/local/openmoko/arm/arm-angstrom-linux-gnueabi/.
Remember to improve the page Navit on FreeRunner.
How to cross-compile a large project like Navit for the OpenMoko/FreeRunner, using a GNU/Linux box and the toolchain.
First of all, edit the /usr/local/openmoko/arm/environment-setup script and add the followig line:
export OMTOOL_DIR=/usr/local/openmoko
After toolchain installation, install (with opkg-target) some OpenMoko -dev packages required to compile Navit. Depending upon permissions of /usr/local/openmoko/ directory, you may need root privileges:
. /usr/local/openmoko/arm/environment-setup opkg-target list opkg-target install gpsd-dev opkg-target install gtk+-dev opkg-target install libspeechd-dev
Now we check-out Navit sources from the SVN repository and we make an archive just in case we need the pristine sources in the future:
svn co https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit tar zcvf navit-svn-2670.tar.gz navit
Instead of running the traditional ./autogen.sh; ./configure in the navit source tree, we must run the om-conf script, which will modify the automake, autoconf and make files to run into the OpenMoko toolchain.
Because Navit on the OpenMoko FreeRunner requires some configure options, we will pass them to the script. Run om-conf from the directory containing the source tree (not inside it):
om-conf --host=arm-angstrom-linux-gnueabi --enable-avoid-unaligned --enable-avoid-float \
--enable-cache-size=20971520 --with-saxon=saxon-xslt --with-xslts=openmoko \
--enable-svg2png-scaling=16,32,48,96 --enable-svg2png-scaling-flag=32,48 \
navit
In the example above we used some ./configure options, among them:
--with-saxon=saxon-xslt
This is because we have the Debian libsaxon-java package, where the executable is called saxon-xslt instead of saxon.
--enable-svg2png-scaling=16,32,48,96
For each .svg icon, render a png image of the specified size. Images will be named icon_XX_YY.png.
--enable-svg2png-scaling-flag=32,48
Same as above, but only for country flag icons.
It's time to cross-compile:
cd navit make
The OpenMoko toolchain provides the om-make-ipkg utility. It requires the directory name where to execute the make install and the name of the control file:
. /usr/local/openmoko/arm/environment-setup om-make-ipkg navit navit-control
The control file is described here.
If you need more control files (e.g. a postinst or alike) you have to tweak with the om-make-ipkg script. Here it is the script I use, it looks for the control files into an opkg directory, so you have to pass just the directory name containing the source tree.
#!/bin/sh -e error_exit () { echo usage: $(basename ${0}) [app_dir_name] [ipkg_control_file] exit 1 } test x${OMTOOL_DIR} = x && . /usr/local/openmoko/arm/setup-env . ${OMTOOL_DIR}/arm/scripts/functions S=${1} (test x${S} = x || test ! -d ${S}) && error_exit appname=$(basename ${S}) tmpdir=/tmp/${appname}-ipkg-tmp test -e "${tmpdir}" && echo Cannot use ${tmpdir} because it already exists. && exit 1 make -C ${S} install DESTDIR="${tmpdir}" # Copy control files to destination directory. cp -pr opkg/* ${tmpdir} ipkg-build -o 0 -g 0 ${tmpdir} rm -rf ${tmpdir}
Control files and other files are arranged into the opkg directory as needed, here it is an example:
opkg/CONTROL/postinst opkg/CONTROL/control opkg/etc/rcS.d/S96overcommit_memory.sh
The ipkg tool is obsolete, OpenMoko uses the opkg instead, but documentation is scarce.
The current opkg code is in Google code, but you can try this one:
svn co http://svn.openmoko.org/trunk/src/host/opkg-utils
and use the instructions of ipkg's website but the software from this checkout. The main script is opkg-build.
WARNING: this procedure works only for the GTA01 Neo1973, it fails for the GTA02 FreeRunner.
Install the Debian packages gcc-3.4 and libsdl1.2-dev, download the qemu-neo1973 sources from the svn repository. Run the ./configure && make.
Edit the openmoko/env file and set current URLs and filenames:
# Entries for GTA01 kernel_wildcard="uImage-2.6.22.5-moko11+svnr3238-r9-neo1973.bin" rootfs_wildcard="openmoko-image-fic-gta01.jffs2" uboot_wildcard="u-boot-gta01*.bin" download_dir="http://downloads.openmoko.org/distro/obsolete-images/Om2007.11//images/neo1973/"
Run the openmoko/download.sh and openmoko/flash.sh scripts.
For the (failed) attempt to run the GTA02 FreeRunner emulator we need different Qemu parameters and different images:
qemu_relative="arm-softmmu/qemu-system-arm -M gta02fake -m 130" # Entries for GTA02, Om2008.12 kernel_wildcard="Om2008.12-om-gta02.uImage.bin" rootfs_wildcard="Om2008.12-om-gta02.rootfs.jffs2" uboot_wildcard="gta02v5_and_up-u-boot.bin" download_dir="http://downloads.openmoko.org/distro/releases/Om2008.12/"
The openmoko/Makefile should be changed so the openmoko-flash.base (the NAND image) will be 256 Mb in size:
# GTA02
$(FLASHIMG):
# Making an empty/erased flash image. Need a correct echo behavior.
$(echo) -en \\0377\\0377\\0377\\0377\\0377\\0377\\0377\\0377 > .8b
cat .8b .8b .8b .8b .8b .8b .8b .8b > .64b # OOB is 64 bytes
cat .64b .64b .64b .64b .64b .64b .64b .64b > .2048b
cat .64b .64b .64b .64b .64b .64b .64b .64b >> .2048b
cat .64b .64b .64b .64b .64b .64b .64b .64b >> .2048b
cat .64b .64b .64b .64b .64b .64b .64b .64b >> .2048b
cat .2048b .64b > .sec # A sector is 2048 bytes of data + OOB
cat .sec .sec .sec .sec .sec .sec .sec .sec > .8sec
cat .8sec .8sec .8sec .8sec .8sec .8sec .8sec .8sec > .64sec
cat .64sec .64sec .64sec .64sec .64sec .64sec .64sec .64sec > .512sec
cat .512sec .512sec .512sec .512sec > .2ksec
cat .2ksec .2ksec .2ksec .2ksec .2ksec .2ksec .2ksec .2ksec > .16ksec
# Neo GTA02 NAND is 128k sectors big
cat .16ksec .16ksec .16ksec .16ksec .16ksec .16ksec .16ksec .16ksec > $@
rm -rf .8b .64b .2048b .sec .8sec .64sec .512sec .2ksec .16ksec
The openmoko/download.sh will run, but openmoko/flash.sh fails with endless errors:
s3c_nand_read: Bad register 0x20
May be there are more instructions for the GTA02 in the wiki page.
We can manually run the emulator to get the U-Boot prompt, but here we have to partition and flash the NAND manually.
arm-softmmu/qemu-system-arm -M gta02fake -m 130 \
-mtdblock openmoko-flash.base \
-kernel u-boot.bin \
-serial stdio -nographic -usb -monitor null