Thursday, January 7, 2010

Enabling RTC (clock), battery charging and watchdogs on alternative OS'es on N900

Just spent a day getting RTC (clock), battery charging and watchdogs working for Mer on N900 and I thought I'd like to share how it was done for those of you wanting to run other OS'es on N900. The watchdog package in typical Debian does not by default work with two watchdogs, so we are using DSME.

This example assumes that you have made a /mnt/initfs directory on your rootfs and that you're running this from fanoush's bootmenu which will put the Maemo5 root file system in /mnt/initfs

You should as early in your boot process (after udev has been started), run the following script:


# Set up initfs environment


hwclock --hctosys

chroot /mnt/initfs mount -n -t proc proc /proc

chroot /mnt/initfs mount -n -t sysfs sysfs /sys

mount --bind /dev /mnt/initfs/dev

chroot /mnt/initfs mount -n -t tmpfs -o size=1M,noatime tmpfs /tmp

chroot /mnt/initfs mount -n -t tmpfs -o size=256k,mode=0755,nosuid,noatime tmpfs /var/run

# Check current boot state. Could be 'USER'
export BOOTSTATE=`chroot /mnt/initfs getbootstate 2>/dev/null`

touch /mnt/initfs/tmp/$BOOTSTATE

echo $BOOTSTATE > /mnt/initfs/tmp/STATE

chroot /mnt/initfs /sbin/dsme -p /usr/lib/dsme/libstartup.so &

until chroot /mnt/initfs waitfordsme; do

sleep 1

done

LOGGER='/usr/bin/logger -s -tBME'

SYSFS_VBUS_PATH=/sys/class/i2c-adapter/i2c-1/1-0048/twl4030_usb/vbus


# check dead battery pre-charge

if [ $(cat $SYSFS_VBUS_PATH) -eq 1 ]; then

chroot /mnt/initfs /usr/sbin/bme_RX-51 -b

case $? in

0)

$LOGGER -pdaemon.notice 'precharge -> ok'

;;

2)

$LOGGER -pdaemon.crit 'precharge -> power off'

exit 1

;;

*)

$LOGGER -pdaemon.crit 'precharge -> failure'

;;

esac

fi

# Start battery management entity
chroot /mnt/initfs /usr/sbin/bme_RX-51 &

# Bonus: To get hald-addon-bme working (bad bad voodoo). We need to test if toggles_w's hald-addon-bme replacement works on N900.
# dpkg-repack hald-addon-bme from rootfs and dpkg -i it
mount --bind / /mnt/initfs/mnt/new_root
chroot /mnt/initfs ln -s /mnt/new_root/tmp/bme-dbus-socket /tmp/bme-dbus-socket
ln -s /mnt/initfs/tmp/.bmesrv /tmp/.bmesrv
ln -s /mnt/initfs/tmp/dsmesock /tmp/dsmesock

No comments:

Post a Comment

Post a Comment