View Single Post
Old 12-11-2008, 05:13 PM   #1
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Cool Safe(r) experimenting with alternative start scripts

Hi All,

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 post, but it's really quite simple. Read along...

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':
Code:
#!/bin/sh

#HANSEL: Alternative start
export MYLOG=/home/root/start.log
/usr/local/bin/sd_present aaa 2>>$MYLOG
if /usr/local/bin/sd_present
then
   . /home/root/my_start.sh
   exit 0
fi

#HANSEL: original start follows...

. /usr/bin/do_updates.sh
#/usr/bin/erregInit
#/sbin/syslogd -s 500 -b 0 -O /var/log/messages
export DISPLAY=:0
[snip]
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.

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:

Code:
#!/bin/sh
date >>$MYLOG
echo "############################" >>$MYLOG
/usr/local/bin/sd_present aaa 2>>$MYLOG
echo "=====  pwd =======================" >>$MYLOG
pwd >>$MYLOG
echo "=====  mount =======================" >>$MYLOG
mount >>$MYLOG
echo "======  ps -edalf ======================" >>$MYLOG
ps -edalf >>$MYLOG
echo "======  /usr/local  ======================" >>$MYLOG
ls -l /usr/local >>$MYLOG
echo "======  /mnt/free  ======================" >>$MYLOG
ls -l /mnt/free >>$MYLOG
echo "============================" >>$MYLOG


. /usr/bin/do_updates.sh
#/usr/bin/erregInit
#/sbin/syslogd -s 500 -b 0 -O /var/log/messages
export DISPLAY=:0
export LD_LIBRARY_PATH=/usr/lib/mozilla-minimo

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

Code:
// 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:
Code:
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

Happy hacking,
Hansel

Edit: attached binary that runs on Iliad
Attached Files
File Type: gz sd_present.gz (1.8 KB, 531 views)

Last edited by hansel; 12-11-2008 at 05:37 PM. Reason: attach sd_present
hansel is offline   Reply With Quote