Earlier in the day, I wrote:
So yes, my laptop can now be turned into a phone charger with networking, DNS and apt cache services. I shall look into hooking that script into dbus to have it run automatically when the phone is plugged and unplugged.
It's not dbus, it's udev, and I've managed to do it.
It's an udev rule:
# cat /etc/udev/rules.d/z60_openmoko_net.rules
ACTION=="add", SUBSYSTEM=="net", ATTRS{idVendor}=="1457", ATTRS{idProduct}=="5122", RUN+="/root/bin/share-openmoko"
ACTION=="remove", SUBSYSTEM=="net", INTERFACE="usb0", RUN+="/root/bin/share-openmoko"
And a script:
# cat bin/share-openmoko
#!/bin/sh
if [ "$ACTION" == "add" ]
then
ACTION=start
fi
if [ "$ACTION" == "remove" ]
then
ACTION=stop
fi
INTERFACE=${INTERFACE:-"usb0"}
ACTION=${ACTION:-"$1"}
case "$ACTION" in
start)
logger -t openmoko "Connected, setting up network"
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE -s 192.168.0.200/29
ifconfig usb0 192.168.0.200 netmask 255.255.255.248
/etc/init.d/dnsmasq start
echo 1 > /proc/sys/net/ipv4/ip_forward
;;
stop)
logger -t openmoko "Disconnected, bringing down network"
echo 0 > /proc/sys/net/ipv4/ip_forward
/etc/init.d/dnsmasq stop
iptables -t nat -F POSTROUTING
ifconfig usb0 down
;;
esac
The script has extra cruft that makes it double as a udev script and as a init.d style script, just because I didn't feel like abandoning the init.d style interface. However, udev handles it perfectly, so there's probably no use at all for the start/stop part.
This means that the interface and all supporting services will be brought up and down when the phone is connected/disconnected, and also when the phone is suspended/resumed. Of course, more fancy things can be plugged into the script, like syncing PIM info, file systems, turning on applets in panels, mounting phone file systems and whatnot.
I got myself a FreeRunner. Here are some notes from the first few days:
The FreeRunner comes with the Om 2007.2 distribution: it works for basic phone things, and it has an opkg package manager that you can use to install all sort of extra software. Only issue: the SMS application was rather unstable with my SIM card.
I then tried Om 2008.8, which is a major new redesign, partly based on Qtopia. It's definitely more advanced on how it looks, with smooth animations all around, but I did not manage to get the GSM part to work, because I did not manage to get it to ask for a PIN.
I then tried plain Qtopia and I got what looks and feels like a properly working mobile phone. The only issue that it has is that I did not manage to make it suspend, so battery life is much shorter than it could be. Apparently, this should improve as kernel 2.6.26 reaches the phone. I kept Qtopia installed in the phone flash as a "stable" phone system.
And finally, Debian. Debian is based on the freesmartphone.org software stack, which is an attempt to create a UI agnostic DBUS frontend to the hardware that supports multiple applications running on top of it. It is a young project, but it can already drive a mobile phone in a useful way. It has a demo interface that is basically a showcase of what is implemented in the DBUS frontend, but does most of the basic things you need from a mobile phone, including taking and making phone calls. And then it has Debian behind, all of it. I need to buy a bigger microsd card.
apt-get install dfu-utildfu-util -l shows you a list of devices it can
access. If you see more than once, you need to specify in all
dfu-util commands which one you want, using -d
USBID. In my case, I have to always use dfu-util -d
0x1d50:0x5119dfu-util -a kernel -R -D
/path/to/uImagedfu-util -a rootfs -R -D
rootfs_filename.jffs2dfu-util -a u-boot -R -D
uboot_filename.bindfu-util -a u-boot_env -D env.newYou can also download all of these things from the FreeRunner by
using -U instead of -D.
All of the distributions I tried, by default configure the USB
as a gadget with
ethernet over usb. You can form a lan with it using the
cdc_ether module, and you will find your phone
preconfigured as 192.168.0.202 expecting to find a
gateway at 192.168.0.200.
I made myself this script to start and stop networking with the phone:
#!/bin/sh
case "$1" in
start)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE -s 192.168.0.200/29
ifconfig usb0 192.168.0.200 netmask 255.255.255.248
/etc/init.d/dnsmasq start
echo 1 > /proc/sys/net/ipv4/ip_forward
;;
stop)
echo 0 > /proc/sys/net/ipv4/ip_forward
/etc/init.d/dnsmasq stop
iptables -t nat -F POSTROUTING
ifconfig usb0 down
;;
esac
Besides doing masquerading, it also brings up dnsmasq so that the phone can always find a DNS together with the router.
Another useful trick is to configure the phone to share the approx cache with the laptop:
deb http://192.168.0.200:9999/debian unstable main
deb http://192.168.0.200:9999/debian experimental main
deb http://pkg-fso.alioth.debian.org/debian unstable main
So yes, my laptop can now be turned into a phone charger with networking, DNS and apt cache services. I shall look into hooking that script into dbus to have it run automatically when the phone is plugged and unplugged.
In case you don't like the default ringtone, this is how to change it:
vi
/usr/share/python-support/fso-frameworkd/framework/subsystems/oeventd/receiver.pydef _play( self ):decoder =
gst.element_factory_make, if needed. The list
of available plugins is on the gstreamer website.filesrc.set_property/etc/init.d/fso-frameworkd restart and maybe
/etc/init.d/zhone-session restartYes, the ringtone is currently hardcoded, but it does say it's a
prototype after all. Or, if you prefer, it's fully configurable and
the configuration can be found in
/usr/share/python-support/fso-frameworkd.
You can connect to the u-boot bootloader via a serial
terminal on /dev/ttyACM0. Type help and
you will find that it can do a lot of things. The OpenMoko wiki has
pages on the
bootloader itself, its
commands and the
environment.
The environment is the configuration of the bootloader, similar
somehow to /boot/grub/menu.lst. Unlike grub, you can
edit the environment from within the bootloader and then save it
using the saveenv command.
What I did:
setenv menu_3 Boot from microSD (FAT+ext2):
setenv bootargs \${bootargs_base} rootfstype=ext2
root=/dev/mmcblk0p2 rootdelay=5 \${mtdparts} ro\; mmcinit\; fatload
mmc 1 0x32000000 \${sd_image_name}\; bootm 0x32000000setenv bootdelay -1setenv
boot_menu_timeout 99999setenv stop_in_menu
yessaveenvSo now my phone dual boots, and I can choose if I want a more reliable phone now (Qtopia) or if I want to play with my future phone (Debian).
Minor issue, but annoying: since both QTopia and Debian show up
on 192.168.0.202, ssh will complain about changed host keys. Here
is how to configure ssh to avoid the problem (in
~/.ssh/config):
Host debian
HostName 192.168.0.202
User root
HostKeyAlias debian
Host qtopia
HostName 192.168.0.202
User root
HostKeyAlias qtopia