Survive without ppc uartd

How to make a firmware free of ppc_uartd
The ppc_uartd daemon is an esential piece of the official firmware. Unfortunately, it doesn't seem to be Free, nor even OpenSource.

This small howto describes how to got rid of it in Gentoo beta1. I thought it might be useful for people working on a Debian firmware for instance.

Disabling the watchdog on startup
The first thing to do if you don't launch the ppc_uartd daemon is to shut down the watchdog, otherwise, your box will reboot after ~30 seconds. This must be done early enough in the startup process. In particular, it must come before the checkfs scripts.

Here is the init.d script made for Gentoo.

/etc/init.d/kuro-avr-init:

depend { # Do it ASAP, time is critical... before localmount } check_device { if [ ! -c /dev/ttyS1 ] ; then ewarn "/dev/ttyS1 missing, trying to create it..." rm -f /dev/ttyS1 mknod /dev/ttyS1 c 4 65 \ || return 1 fi      return 0 } start { ebegin "Initializing the Kurobox AVR" local status check_device \ && stty -F /dev/ttyS1 10:1:9f0d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 \ && echo -n "AAAAFFFFJJJJ>>>>VVVV>>>>ZZZZVVVVKKKK" > /dev/ttyS1 eend $? "That's not good... Your system will probably shutdown soon :/" }
 * 1) !/sbin/runscript

Monitoring power/reset buttons
Another task of the ppc_uartd is to allow shutdown from the Kurobox buttons. Here, it can be easily replaced by the free kuroevtd daemon. Once launched, this daemon will react to button events by launching some shell scripts.

Here is the startup script made for Gentoo.

/etc/init.d/kuroevtd: [ -z "${PIDFILE}" ] && PIDFILE=/var/run/kuroevtd.pid depend { need kuro-avr-init } start { ebegin "Starting Kurobox button events monitor" start-stop-daemon --start --quiet --exec /usr/sbin/kuroevtd \ || eend 1 \ || return 1 local mypid=$(pidof /usr/sbin/kuroevtd 2>/dev/null) [ -n "${mypid}" ] && echo ${mypid} > ${PIDFILE} eend 0 } stop { ebegin "Stopping Kurobox button events monitor" start-stop-daemon --stop --quiet --pidfile=${PIDFILE} local status=$? rm -f ${PIDFILE} eend $status }
 * 1) !/sbin/runscript

And here is a set of event handling scripts that produce the following behavior:


 * two short pushes on the power button (in less than 3 seconds) will reset the box with "shutdown -r now"
 * one long push one the power button (~6 seconds) do a halt the box with "shutdown -h now"
 * one long push on the small back button will reset the box in EM mode

/etc/kuroevtd.d/powerdown STATE_DIR="/var/lib/kuroevtd" debug=true current=$(date +%s) if [ -f "${STATE_DIR}/last" ] ; then read last <<<$(cat "${STATE_DIR}/last") rm -f ${STATE_DIR}/last if (( current <= (last+3) )) ; then ${debug} && echo "[kuroevtd] powerdown: will reset soon..." touch ${STATE_DIR}/reset exit 0 fi fi ${debug} && echo "[kuroevtd] powerdown: saving push date" echo ${current} > "${STATE_DIR}/last"
 * 1) !/bin/bash

/etc/kuroevtd.d/powerup STATE_DIR="/var/lib/kuroevtd" debug=true if [ -f "${STATE_DIR}/reset" ] ; then ${debug} && echo "[kuroevtd] powerup: reset now!" rm -f ${STATE_DIR}/* shutdown -r now fi
 * 1) !/bin/sh

/etc/kuroevtd.d/powerpress STATE_DIR="/var/lib/kuroevtd" debug=true ${debug} && echo "[kuroevtd] powerpress: shutdown now!" rm -f ${STATE_DIR}/* shutdown -h now
 * 1) !/bin/sh

/etc/kuroevtd.d/resetpress STATE_DIR="/var/lib/kuroevtd" debug=true ${debug} && echo "[kuroevtd] powerpress: reset in EM mode now!" if grep -q started <<<$(/etc/init.d/em-fallback status 2>/dev/null) ; then /etc/init.d/em-fallback stop fi rm -f ${STATE_DIR}/* write_ng shutdown -r now
 * 1) !/bin/bash

Getting shutdown to work
Finally, the last thing to know is that to shutdown or reboot the box, you must inform the AVR first. For Gentoo, I've made that by modifying two init.d scripts.

/etc/init.d/shutdown.sh if [ -c "/dev/ttyS1" ] ; then echo -n "EEEE" > /dev/ttyS1 else ewarn "No /dev/ttyS1 device found, your Kurobox may not halt correctly!" fi /sbin/halt -idp
 * 1) Copyright 1999-2004 Gentoo Technologies, Inc.
 * 2) Distributed under the terms of the GNU General Public License v2
 * 3) $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/shutdown.sh,v 1.10 2004/04/21 17:09:18 vapier Exp $
 * 1) kuro: tell the AVR that we are going to halt

/etc/init.d/reboot.sh if [ -c "/dev/ttyS1" ] ; then echo -n "CCCC" > /dev/ttyS1 else ewarn "No /dev/ttyS1 device found, your Kurobox may not reboot correctly!" fi /sbin/reboot -idp
 * 1) Copyright 1999-2004 Gentoo Technologies, Inc.
 * 2) Distributed under the terms of the GNU General Public License v2
 * 3) $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/reboot.sh,v 1.8 2004/04/21 17:09:18 vapier Exp $
 * 1) kuro: tell the AVR that we are going to reboot