A safe startup script for the Iliad

When experimenting with essential Iliad programs, a small mistake can be fatal: unbootable device, re-flash required.

I solved this with the following set-up:

  • A small and simple program without bugs checks if a sd-card is inserted
  • The startup script (/home/root/start.sh) checks if the sd-card is inserted
  • If so: 'jump' to my_start.sh
  • If not: proceed normal start

This is a long article, but it's really quite simple ;-)

The modified script

When experimenting you can just modify 'my_start.sh', and let this do whatever you want. If the iliad doesn't start properly: remove the sd-card (it works even with the dummy plastic one), reboot, and try again. :)

Here is the modification at the start of the official 'start.sh':

#HANSEL: Alternative start
export MYLOG=/home/root/start.log
/usr/local/bin/sd_present aaa 2>>$MYLOG
if /usr/local/bin/sd_present
   . /home/root/my_start.sh
   exit 0
#HANSEL: original start follows...
. /usr/bin/do_updates.sh
#/sbin/syslogd -s 500 -b 0 -O /var/log/messages
export DISPLAY=:0

Be careful when moving the original start.sh around. It must be present, correct an executable (chmod +x) before rebooting! The big advantage is that you have to modify it only once.

Your own script

It's a good idea to start my_start.sh (/home/root/my_script.sh) as a copy of start.sh, and modify it in small steps. The following script is my first experiment:

echo "############################" >>$MYLOG
date >>$MYLOG
/usr/local/bin/sd_present aaa 2>>$MYLOG
echo "======  Running processes ======================" >>$MYLOG
ps -edalf >>$MYLOG
echo "============================" >>$MYLOG
. /usr/bin/do_updates.sh
#/sbin/syslogd -s 500 -b 0 -O /var/log/messages
export DISPLAY=:0
export LD_LIBRARY_PATH=/usr/lib/mozilla-minimo
[snip: relevant parts of original script]

Is the sd-card present?

The program to check the presence of the sd-card is quite simple:

// This progam return 0 (= success) when sd-card is present
// free-ware without purpose, hansel<AT>hpelbers<DOT>org, 12-12-2008
// To test: run it with any parameter: it will print if the card is inserted or not
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define BUTTON_IOCTL_BASE               'b'
#define BUTTON_IOCTL_GET_STATUS         _IOR( BUTTON_IOCTL_BASE,7,unsigned int)
int main(int argc, char *argv[]) {
    int stat;
    int dev;
    if ((dev = open("/dev/buttons", O_RDWR)) < 0) {
        fprintf(stderr,"ERROR opening failed\n");
        return 10;      // error
    else if (ioctl(dev, BUTTON_IOCTL_GET_STATUS, &stat)) {
        fprintf(stderr, "ERROR: BUTTON_IOCTL_GET_STATUS failed\n");
        return 11;      // error
    else {
        if(argc>1) fprintf(stderr, "OK: sd_present=%d\n", (stat&0x800) != 0);
        return (stat&0x800) ? 0 : 1;

It can be compiled with the cross-compiler as:

arm-linux-gcc sd_present.c -o sd_present

As you can see in the start.sh, I have installed it in /usr/local/bin. The experimental start script is installed as /home/root/my_start.sh

Attached: binary that runs on Iliad

Note: I published and discussed this article on mobileread.com

Last modified: 2009/08/03 20:54 Mijn Fijne Site hosting en design