Sunday, September 27, 2009

Emulating and Compiling for zubuntu

Emulating Zaurus
Since compiling natively on the Zaurus was slow, I decide looking for other options. Cross-compilation seems to complicated for me to setup (though probably it's not) - for that Poky seemed the easiest way. A compromise I found was to setup an arm system under Qemu. I found some of the solution on this post in the OmegaMoon blog.
First I needed the arm flavour of Qemu, Next, I used the Qemu Manager to setup the virtual machine (it can also create virtual disks).
Qemu needs a kernel to boot, I use this one.
Then I created two empty image disks (one for the operating system and one for swap). The tricky part is to setup the virtual disks. I did it on a linux machine (I use VMware to run a linux machine).
Format the disks,

mke2fs -F -m 0 -b 1024 virtual.disk

then mount it 

sudo mount -t ext2 -o loop virtual.disk mount_point
then extract the Zubuntu rootfs to this virtual disk (this is exactly the same process as setting up zubuntu for the Zaurus). I guess this can be done using one of the prepared virtual machines.
Now I put everything in the Qemu folder and use the following script to start the virutial machine,
qemu-system-arm -kernel zImage-versatile-2.6.24-rc7.armv5tel -append "console=ttyS0,115200n8 console=tty1 noinitrd fbcon=rotate:1 dyntick=enable debug psplash=false root=/dev/sda ip=bootp" -boot c -m 256 -hda virtual.disk -hdb swap.disk -net nic,vlan=0 -net user,vlan=0 -usbdevice tablet -localtime -M versatilepb
Alternatively, I use this virtual machine in the Qemu Manager.
The last is to create the swap partition, after Qemu boot into zubuntu,
mkswap /dev/sdb
and  enable it,
swapon /dev/sdb
For zubuntu to automatically start swap when booting, add to /etc/fstab,
/dev/sdb/        /none       swap       sw       0   0

Now this virtual machine can be used to compile "natively" for the zaurus. From the few tests I made compiling here is about twice as fast as compiling on the zaurus.


OpenTTD

OpenTTD is similar to simutrans, it is less sofisticated, but the performance here is much better than in simutrans (see this post).


OpenTTD with CargDist running on my Zaurus

To compile latest OpenTTD including the CargoDist patch (wikipage, forum thread), I did the following,
First install the prerequisites,
apt-get install git-core
For CargoDest libboost-graph-dev was also required (not sure if it is required by Cargodist)
then, to get the source code,
git clone http://fickzoo.com/fonsinchen/openttd.git
git checkout origin/cargodist

configure,
./configure --enable-debug=0 --prefix-dir=/usr

That (supposedly) disables debug, the prefix dir will set the installation dir to match that of the debian package (binaries under /usr/games and data under /usr/share/games/openttd).
Now compile
make
And with a little luck OpenTTD is compiled. To configure it follow the instruction in OpenTTD's wikipage.

2 comments:

  1. I have put together a fairly comprehensivce guide to setup a successful cross-compile environment for the Zaurus. Once I figured out the steps it wasn't too complicate, but it did take a while to sort out. This will probably be a much faster way to develop than a Qemu virtual Arm machine.

    Link to my article is http://kcd.sytes.net/articles/zaurus_development.php

    Let me know if you find it useful.

    ReplyDelete
  2. Hi Charles,
    Thanks for the link, it is comprehensive and well written guide. Actually in the past I used the same (or at least similar) method to compile for qpe under OpenZaurus. And it worked well. The problem started when I advanced to Zubuntu and Angstrom, this method didn't work anymore... The "proper" solution is apparently to use OpenEmbedded or Poky for crosscompiling. But as you also pointed this is far from straight forward solution.

    ReplyDelete