Thursday, January 31, 2008

USB in ITOS 2008

Initially posting this via Maemo Blogger on osgiliath.

One of the most useful improvements in ITOS 2008 is the proper support for USB Host mode. Unlike previous versions where one had to jump through hoops to even get USB devices recognized, Host mode is now as simple as sending a value over to the appropriate /sys entry.

Here's a quick-and-dirty script which I simply call usb (compiled from various sources) that not only allows you to select between Host and On-The-Go (OTG) modes, it even allows for USB networking.


if [ "$MODE" == "net" ]; then
LOADED=`lsmod | grep g_ether | grep -v grep`
if [ "$LOADED" == "" ]; then
insmod /mnt/initfs/lib/modules/2.6.21-omap1/g_ether.ko
ifup usb0
IP=`getip usb0 2>/dev/null`
echo "IP is $IP"

elif [ "$MODE" == "file" ]; then
ifdown usb0
rmmod g_ether

elif [ "$MODE" == "host" -o "$MODE" == "otg" ]; then
if [ "$MODE" == "otg" ]; then
echo peripheral > /sys/devices/platform/musb_hdrc/mode
echo $MODE > /sys/devices/platform/musb_hdrc/mode
echo USB mode set to $MODE

echo "Specify 'host', 'otg', 'net', or 'file'"
IP=`getip usb0 2>/dev/null`
if [ "$IP" == "" ]; then
CUR=`cat /sys/devices/platform/musb_hdrc/mode`
echo "Current mode is $CUR."
echo "Current mode is net, IP $IP"
The helper script getip is just

if [ "$DEV" == "" ]; then
IP=`ifconfig $DEV |head -2 |tail -1 |awk '{print $2}' |cut -d: -f2`
echo -n $IP

Basically, you just call it as usb host or usb otg; or as usb net or usb file. I haven't fully tested these scripts, but they work for me. YMMV.

Here's a shot of an N800 xterm showing my 12GB Devant HD, and the 2GB SD from my camera in a card reader. The df command was typed from a USB keyboard connected to the same powered hub. I used a cheap CA408 AF/AF USB adaptor from CDR King to connect the hub.