Sharp Zaurus C700 Debian <=> Qtopia



First of all, many thanks to Klaus Weidner for his work at [http://www.w-m-p.com/software/pocketworkstation/].
He's the author of fbvnc code, and of the original project [Debian on Handhelds].

--NEW-- Compiled new drivers for prism2 cards.
Now it's possible to sniff in true monitor mode, & spoof the MAC address. here

WARNING:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I've tested all the below stuff on my z, and all it's working ok,
never reflashed, never a problem or instability.
But be aware, if something goes wrong, it's possible that your z. wont boot anymore,
and that you need to re-flash it.
See also this "diary" if you want more detailed info on z. boot/init process.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ok, here is the whole.

1] Download, from www.w-m-p.com/software/pocketworkstation/
fbvnc-arm-1.3.3beta.gz
zaurus-debian-big-v0.15.tgz

1a] If you have a linux box, it's higly recommended that you install the usbdnet standalone module.
i.ex. prdownloads.sourceforge.net/zaurus or www.opie.us/opie/devZone.php/usbdnet-standalone.tgz
The kernel module, on the other hand, is very unstable & kernelpanic prone.
[Of course it's possible also to do all the job via the Z keyboard]
Anyway, if you want to use the usb cradle connectivity, do something similar:

- create & chmod this on your pc [say you name it 'zaurus']:
#! /bin/bash
typeset -i num
num=`ifconfig | grep usb0 | wc -l`
if [ $num -eq 0 ] ; then
ifconfig usb0 192.168.129.1 netmask 255.255.255.255 up
route add -host 192.168.129.201 usb0
fi

- add this to your pc '/etc/hosts':
192.168.129.201 zaurus

this way, you can quickly execute 'zaurus' then 'telnet zaurus'.
[I assume that you've already modprobed usb-uhci & usbdnet]


2] Format with mke2fs your SD card.
mke2fs /dev/mmcda1


3] Cd in the SD card, and upload here the 2 tarball of 1]
[a little note: when I've dloaded the zaurus-debian-big-v0.15.tgz it was not gzipped, it was just a tar.
dunno if it's the broken brain of IE ;)]

- if you've the usb cradle inserted you can, via netcat, do something like:
nc -l -p 1234 > tarball.tar [zaurus side]
cat tarball.tar | nc zaurus 1234 [pc side]


- extract the tarball.

- edit /etc/sdcontrol:

--------BEGIN SNIP--------
FSTYPE="-t ext2"
FATOPTS="-o noatimei,quiet,umask=000,iocharset=utf8"
EXT2OPTS="-o noatime"
--------ENDOF SNIP--------

--------BEGIN SNIP--------
case "$ACTION" in
'insert')
# mount $FSTYPE $FATOPTS $DEVICE $MOUNT_POINT
mount $FSTYPE $EXT2OPTS $DEVICE $MOUNT_POINT
MOUNT_RES = `mount | grep $DEVICE`
if [ "$MOUNT_RES" = "" ]; then
mount $FSTYPE $DEVICE $MOUNT_POINT
fi
--------ENDOF SNIP--------



- edit /etc/fstab, and in '/dev/mmcda1' line, add 'noatime'

--------BEGIN LINE--------
/dev/mmcda1 /usr/mnt.rom/card ext2 rw,noatime 0 0
--------ENDOF LINE--------



- execute ./debroot/INSTALL.d/postinst.sh

[during the execution of postinst.sh, answer YES at all, but NO at these 2:
Permit unsafe VNC connections without passwords?
Run 'Fbvnc' now?
]
--- Note: you can also safely answer yes at the 1st question, because, in this installation, the Xvnc server runs only locally. ---

- gunzip the fbvnc-arm-1.3.3beta.gz and copy to /mnt/card/debroot/usr/bin/fbvnc

- add "-w c700" in the last lines of /usr/local/bin/Fbvnc this way:

--------BEGIN SNIP--------
if [ -z "$1" ]; then
fbvnc -hw c700 127.0.0.1:1
else
fbvnc -hw c700 "$@"
fi
--------ENDOF SNIP--------



- edit /etc/debroot.conf

--------BEGIN FILE--------
### /etc/debroot.conf
#
# Configuration for the Debian chroot environment startup process
#

# IMPORTANT: boolean settings (DEB_FOO=1) are true if not empty, so
# comment out the entry (put a '#' at the start of the line) if you
# want to deactivate it.

DEBROOT=/usr/mnt.rom/card

DEB_PATH=$HOME/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/games

# Disable this if you have a fixed QPE that permits VT switching
#DEB_QPE_WARNING=1

DEB_DO_MOUNTS=1

DEB_COPY_INTO_CHROOT="etc/resolv.conf"

DEB_COPY_INTO_NATIVE="etc/hosts"


#DEB_RUN_SERVICES=""
#DEB_RUN_SERVICES="inetd ssh lpd"
#DEB_RUN_SERVICES="ssh"

DEB_RUN_VNCSERVER=1

DEB_RUN_FBVNC=1

DEB_ZAPM_PROXY=1

DEB_RUN_ZAPMD=1

DEB_ROOTCMD=1
--------ENDOF FILE--------


[comments stripped out ;)]


- find in the /etc/rc.d tree the symlink to zdebian and delete it.
[Note: don't delete the file. Only delete the symlink. Here below you'll need to edit it.]

- edit /etc/rc.d/init.d/zdebian

--------BEGIN SNIP--------
#!/bin/bash

## sh [linked to ash] doesnt exec cleanly, so we set bash instead
SHELLCMD=/bin/bash

DEBCONF=/etc/debroot.conf
[ ! -f $DEBCONF ] && {
echo "Can't find $DEBCONF, aborting..."
exit 1
}

. $DEBCONF

[ "$DEBROOT" ] || exit 1
if [ ! -d "$DEBROOT" ]; then
echo "Waiting for $DEBROOT to be fscked..."
while ps ax | grep -v grep | grep e2fsck >/dev/null
do
sleep 1
done
sleep 1
if [ ! -d "$DEBROOT" ]; then
echo "Waiting for $DEBROOT to be mounted..."
sleep 10
fi
fi
cd $DEBROOT || exit 1

ROOTCMD_FIFO=$DEBROOT/dev/rootcmd
ZAPMD=/dev/zapmd

rootcmd_server_start () {
rm -f $ROOTCMD_FIFO
mkfifo -m 600 $ROOTCMD_FIFO

(
while true
do
exec <$ROOTCMD_FIFO
read TTY CMD
$SHELLCMD -c "$CMD" $DEBROOT/$TTY 2>&1
sleep 1
done
) &
echo $! >/var/run/rootcmd.pid
}
--------ENDOF SNIP--------


[the real 2 changes are the 2 /bin/bash invocations at the beginning & at line 41.
the original '/bin/sh' fails to execute cleanly the exec fifo commands. it's an 'ash' issue
(/bin/sh is linked to 'ash', NOT to 'bash').
Many thanks to my brother, Davide, for helping in pointing out this.]


- cd in /home/zaurus, create & chmod 755 these 2 files:

d.sh
--------BEGIN FILE--------
#! /bin/bash

clear
echo "zdebian stop.."
/etc/rc.d/init.d/zdebian stop
echo "kill Xvnc.."
killall Xvnc
echo "change launch.default to 'q'"
echo q > /home/sharp/etc/launch.default
echo "DONE."
exit 0
--------ENDOF FILE--------



q.sh
--------BEGIN FILE--------
#! /bin/bash

echo a > /home/sharp/etc/launch.default
killall qpe
killall qeserver
killall qtsamba
clear
/home/root/usr/bin/chvt 2
sleep 4
/home/root/usr/bin/chvt 1

exit 0
--------ENDOF FILE--------



still in /home/zaurus, do a: echo a > what.txt

note: this file (what.txt) will be your 'boot flag'.
-> if it's "a" then the next boot will be debian
-> if it's "q" then the next boot will be qtopia

IMPORTANT !!
be sure to not edit or remove this file, because it's needed in the init process [see below]
[I mean, it must be absolutely "a" or "q", or you can byebye the z. and reflash it ;)]

still in /home/zaurus, do a: ln -s /etc/rc.d/init.d/zdebian

- edit /usr/mnt.rom/card/usr/local/bin/zvncserver
[security improvement]
I've changed also the '/bin/sh' first line in '/bin/bash'
And also in Fbvnc.
--------BEGIN SNIP--------
AUTH_FILE=/etc/vncpasswd
[ -f $AUTH_FILE ] && AUTH="-rfbauth $AUTH_FILE"

[ ."$DISPLAY" = .":0" ] && rm -f /tmp/.X0-lock
[ ."$DISPLAY" = .":1" ] && rm -f /tmp/.X1-lock
[ ."$DISPLAY" = .":2" ] && rm -f /tmp/.X2-lock

## with '-localhost' we allow only connection from the same machine on which Xvnc runs
## with '-nolisten tcp' [undocumented feature, at least with this goal] we stop Xvnc from listen also on 6000+DISPLAY port
Xvnc -localhost -nolisten tcp -geometry $GEOM -depth 16 -pixelformat RGB565 $AUTH $DISPLAY &
#-fp /usr/lib/vnc/fonts/misc \
#-co /usr/lib/vnc/rgb \

sleep 5
cd $HOME
--------ENDOF SNIP--------

[Note: about the '6000+DISPLAY port' issue, I've mailed also freebsd bug repos. www.freebsd.org/cgi/query-pr.cgi?pr=45490]



- edit /etc/inetd.conf
[security improvement]

leave only this line uncommented:
--------BEGIN LINE--------
telnet stream tcp nowait root /usr/sbin.rom/tcpd /usr/sbin/in.telnetd
--------ENDOF LINE--------


after that, you must also create /etc/hosts.allow & /etc/hosts.deny, add 1 entry in /etc/hosts,
and update /usr/mnt.rom/card/etc/hosts

i.ex:

/etc/hosts:
--------BEGIN FILE--------
### Do not edit this file - it was copied
### from /usr/mnt.rom/card/etc/hosts by ./zdebian
### Edit /etc/debroot.conf to deactivate this.

127.0.0.1 localhost loopback
192.168.129.1 yourpcname

### Do not edit this file - it was copied
### from /usr/mnt.rom/card/etc/hosts by ./zdebian
### Edit /etc/debroot.conf to deactivate this.
--------ENDOF FILE--------


Update your debroot hosts file:
cp /etc/hosts /usr/mnt.rom/card/etc/hosts


Set the allow/deny rules:

/etc/hosts.deny:
--------BEGIN FILE--------
ALL: ALL
--------ENDOF FILE--------


/etc/hosts.allow:
--------BEGIN FILE--------
ALL: yourpcname
--------ENDOF FILE--------


Now, do a /etc/rc.d/init.d/inet restart

and try to connect with a new 'telnet zaurus' from your PC,
and try also a 'telnet localhost' from inside the z.
you must connect from pc, and denied from the z.


- stop useless services from auto starting:
[as I said in the intro, I assume you're not so interested in syncing with outlook and other windoze stuff :)]
in /etc/rc.d/init.d
do a
chmod 000 portmap
chmod 000 samba

edit /etc/hotplug/usbdnet.conf
--------BEGIN FILE--------
DHCPS=no
DHCPC=no
--------ENDOF FILE--------


- if you want to change the 2nd splashscreen with your own:
* create an image 480x640, bitmap format.
[this is the output of 'file':
PC bitmap data, Windows 3.x format, 480 x 640 x 24
]
* copy in /home/QtPalmtop/pics144/Startup_screen.bmp



4]

################### editing files in /dev/root ###################


before you can edit the files mounted in /dev/root, you must do an
mount -o rw,remount /dev/root /
[be aware to not make big mistakes from now.. :)]

this is my /root/etc/sysconfig/init,
don't remember if it's like the original
--------BEGIN FILE--------
SILENT=yes
BOOTUP=color
RES_COL=23
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
LOGLEVEL=1
PROMPT=yes
--------ENDOF FILE--------
>

- edit /root/etc/rc.d/rc.sysinit
[with this change, we see at least some log msgs on the screen instead of the red/white sharp splashscreen :)]
--------BEGIN SNIP--------
# Print a banner. ;)
clear
#if [ -z "$SILENT" ] ; then
echo -en $" Welcome to "
[ "$BOOTUP" != "serial" ] && echo -en $"\\033[1;31m"
echo -en $"WHATYOUWANT"
[ "$BOOTUP" != "serial" ] && echo -en $"\\033[0;39m"
echo $" Zaurus"
#fi
--------ENDOF SNIP--------
>

- edit /root/etc/rc.d/rc.rofilesys
[this is the trick for 'booting' in debian]
--------BEGIN SNIP--------
#echo $LAUNCH > /home/sharp/etc/launch.default
cat /home/zaurus/what.txt > /home/sharp/etc/launch.default
--------ENDOF SNIP--------


- edit /root/etc/inittab
[not so necessary]
--------BEGIN SNIP--------
# collie sp.
#sy::respawn:/sbin/shsync
--------ENDOF SNIP--------
>




################### USAGE ###################


Ok now finally for the fun stuff ;)


1] /home/zaurus/what.txt

is your 'bootselect' flag.

a -> debian
q -> qtopia


2] Exiting/switching from Qtopia

- open Konsole
- su as root
- in /home/zaurus execute "./q.sh"
this will give you a console log.
login, become root.

Then if you want to start Debian, do a
./zdebian start

If you want to reboot:
/sbin/reboot

If you want to halt:
/sbin/halt
[when all off, remember to switch for at least 5 secs the battery switch]


3] Exiting/switching from Debian

Menu -> Logout
press Fn+Shift+q
execute ./d.sh

If you want to start Qtopia, you must simply:
exit
exit

If you want to reboot:
/sbin/reboot
[Note: if you boot in 'Debian mode' ('what.txt' == a), you'll get a login prompt.
After logged and 'su', do './zdebian start', he.. :)]


If you want to halt:
/sbin/halt
[when all off, remember to switch for at least 5 secs the battery switch]


4] Note on screen in console mode:

just type 'clear' + Enter
if you want to clean the screen in console mode.
Take a look here for further specs..


5] Executing command in debian:

using "cru" you can execute like in the 'original' environment.
Example:
--------BEGIN SNIP--------
~# cru ls /root
bin etc samba
~# ls /root
HELP.txt debian-faq.pdf
~#
--------ENDOF SNIP--------

[see also this, for further specs, it's a little 'diary' I wrote trying the installation.. :)]


Updated drivers for prism2 cards.
How to permanently change your MAC address re-flashing the card [tested on prism2 cards]

CHANGELOG TODO

Paolo Sarpi   [c700-debian@libero.it]
Last updated: 2003/05/28