Difference between revisions of "Survive without ppc uartd"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
 
m
 
(2 intermediate revisions by 2 users not shown)
Line 163: Line 163:
 
   
 
   
 
  /sbin/reboot -idp
 
  /sbin/reboot -idp
 +
 +
{{Template:Articles|Kurobox}}

Latest revision as of 00:21, 13 July 2007

Contents

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:

#!/sbin/runscript

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 :/"
}

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:

#!/sbin/runscript

[ -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
}

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

#!/bin/bash

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"

/etc/kuroevtd.d/powerup

#!/bin/sh

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

/etc/kuroevtd.d/powerpress

#!/bin/sh

STATE_DIR="/var/lib/kuroevtd"
debug=true

${debug} && echo "[kuroevtd] powerpress: shutdown now!"
rm -f ${STATE_DIR}/*
shutdown -h now

/etc/kuroevtd.d/resetpress

#!/bin/bash

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

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

# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/shutdown.sh,v 1.10 2004/04/21 17:09:18 vapier Exp $

# kuro: tell the AVR that we are going to halt
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

/etc/init.d/reboot.sh

# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/reboot.sh,v 1.8 2004/04/21 17:09:18 vapier Exp $

# kuro: tell the AVR that we are going to reboot
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