MobileRead Forums
Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > iRex > iRex Developer's Corner

Welcome to the MobileRead Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community today, you will have fewer ads, access to post topics, communicate privately with other members, respond to polls, upload content and access many other special features.

If you have any problems with the registration process or your account login, please contact us.

Hint: Don't have time to visit us daily? Subscribe to our main RSS feed to receive our frontpage posts at your convenience.

Notices

iRex Developer's Corner For iRex-based development discussion and planning

Reply
 
Thread Tools Search this Thread Display Modes
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, 169 views)
__________________
Interests: God, people, computers; Iliad notes and projects;
Private site (dutch, spam, ):

Last edited by hansel; 12-11-2008 at 05:37 PM. Reason: attach sd_present
hansel is offline   Reply With Quote
 
Enthusiast
Old 12-11-2008, 07:57 PM   #2
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 933
Karma: 595
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Can't I test if sd is inserted by using shell script: "if [ -e /media/card/specific_file_onsd ]"?

Added:
I seem to understand your idea. It's really a good idea for customizing boot. With your idea, we can add customized boot script in SD for testing. If failed, just remove SD and reboot, and everything goes back to normal.

Last edited by ericshliao; 12-11-2008 at 09:03 PM.
ericshliao is offline   Reply With Quote
Old 12-11-2008, 09:52 PM   #3
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 933
Karma: 595
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Arrow

I would like to suggest a small modification:
just replace the line in /home/root/.start.sh:
Code:
/usr/bin/displayMgr -p &
with:
Code:
if [-f /media/card/mybootscript.sh ]; then
    . /media/card/mybootscript.sh
else
    /usr/bin/displayMgr -p &
fi
And put all customized boot sequence in /media/card/mybootscript.sh. xepdmgr and other non-official binaries can put in SD, too.

Last edited by ericshliao; 12-11-2008 at 10:17 PM.
ericshliao is offline   Reply With Quote
Old 12-12-2008, 01:10 AM   #4
Antartica
Evangelist
Antartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-books
 
Posts: 415
Karma: 754
Join Date: Jun 2006
Location: Madrid, Spain
Device: iliad, onhandpc, newton, zaurus
Quote:
Originally Posted by hansel View Post
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:
This is really great, Hansel . Thanks.
Antartica is offline   Reply With Quote
Old 12-12-2008, 02:15 AM   #5
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
Quote:
Originally Posted by ericshliao View Post
I would like to suggest a small modification:
just replace the line in /home/root/.start.sh:
Code:
/usr/bin/displayMgr -p &
with:
Code:
if [-f /media/card/mybootscript.sh ]; then
    . /media/card/mybootscript.sh
else
    /usr/bin/displayMgr -p &
fi
And put all customized boot sequence in /media/card/mybootscript.sh. xepdmgr and other non-official binaries can put in SD, too.
Hi Ericshliao,
= The Idea it to only make a small change to start.sh, and then leave it alone. Personally I'm experimenting with contentLister. If you change it often for different things, you'll end up by making a 'fatal' mistake as I did earlier yesterday
= The -f test will not work. The removable devices are not yet mounted at that stage. The hotplug stuff is at the *end* of start.sh. That's why I put those start scripts in the main file system...
__________________
Interests: God, people, computers; Iliad notes and projects;
Private site (dutch, spam, ):
hansel is offline   Reply With Quote
Old 12-12-2008, 02:21 AM   #6
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 933
Karma: 595
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Quote:
Originally Posted by hansel View Post
= The -f test will not work. The removable devices are not yet mounted at that stage. The hotplug stuff is at the *end* of start.sh. That's why I put those start scripts in the main file system...
So, that's why I failed to replace displayMgr. Thanx for the answer.

What if I move the following lines:
Code:
modprobe phci
modprobe usb-storage
/etc/init.d/hotplug start
modprobe mscd
forward to before displayMgr start?

Last edited by ericshliao; 12-12-2008 at 02:24 AM.
ericshliao is offline   Reply With Quote
Old 12-12-2008, 02:36 AM   #7
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 933
Karma: 595
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Ah...
I have another idea.
put xepdmgr and mybootscript.sh in /home/root. And use the following code in .start.sh:
Code:
if [ -f /home/root/mybootscript.sh ]; then
  chmod 777 /home/root/mybootscript.sh
  chmod 777 /home/root/xepdmgr
  . /home/root/mybootscript.sh
  mv /home/root/mybootscript.sh /home/root/_mybootscript.sh
else
  /usr/bin/displayMgr -p &
fi
Thus, it will be back to displayMgr in the next boot. Create a action in contentlister to execute "mv /home/root/_mybootscript.sh /home/root/mybootscript.sh" will reactivate xepdmgr in the next boot.
If xepdmgr failed, there still a chance it will back to normal in the next boot.

Last edited by ericshliao; 12-12-2008 at 02:45 AM.
ericshliao is offline   Reply With Quote
Old 12-12-2008, 03:48 AM   #8
Antartica
Evangelist
Antartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-booksAntartica has learned how to read e-books
 
Posts: 415
Karma: 754
Join Date: Jun 2006
Location: Madrid, Spain
Device: iliad, onhandpc, newton, zaurus
Quote:
Originally Posted by ericshliao View Post
. /home/root/mybootscript.sh
mv /home/root/mybootscript.sh /home/root/_mybootscript.sh
Beware of that: it's safer to move the script before sourcing (.) its contents -- a syntax error in your script, a while loop that never ends or a wrongly composited kill in mybootscript.sh that makes it commit suicide would be some scenarios that would be fatal with your current code.

AFAICT Hansel's code is safe.
Antartica is offline   Reply With Quote
Old 12-12-2008, 04:04 AM   #9
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 933
Karma: 595
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Quote:
Originally Posted by Antartica View Post
...to move the script before sourcing (.) its contents...
Yes, it's fatal if anything wrong with mybootscript.sh and that mv line might never be executed. But I don't understand your words. How to do it?

Added:
Ah... I understand your words now. Yes, I should do the mv action before do source action.

Currently, there is only one line in mybootscript.sh:
Code:
/home/root/xepdmgr &
Added:
I can replace displayMgr with xepdmgr with my mod now.

Last edited by ericshliao; 12-12-2008 at 04:10 AM.
ericshliao is offline   Reply With Quote
Old 12-12-2008, 12:28 PM   #10
jharker
Developer
jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.
 
Posts: 294
Karma: 3441
Join Date: Apr 2007
Location: Brooklyn, NY, USA
Device: iRex iLiad v1, Blackberry Tour, Kindle DX, iPad.
Hi, all!

Nice work. I did something similar a while ago; I posted it in this thread. It's pretty much the same idea, but the implementation is a little different.

Basically it's a start.sh that calls the original start.sh by default. However, if it finds a lockfile, it first deletes the lockfile and then calls testing.sh instead of the default start.sh.

This way, you can just create the lockfile (I use the command 'touch lockfile') and reboot. The iLiad will delete the lockfile and use the experimental start script. If the script fails, simply reboot and you're back to the original start script.

I like your idea of checking for an SD card, because then all your work can be done on the SD card. No need to use ssh to login or to manually create a lockfile, it's all just automatic. Nice work!
jharker is offline   Reply With Quote
Reply

Tags
development, iliad, software

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with News scripts Derry Calibre 4 08-19-2008 05:08 AM
Purchasing from jinke.com.cn. Is it safe? July HanLin eBook 12 07-23-2008 12:38 PM
Fox Searchlight scripts available in PDF jckatz Reading Recommendations 1 02-23-2008 11:39 PM
Network Control Scripts synerr iRex 3 01-13-2008 06:54 AM
Television scripts for your handheld Bob Russell Lounge 2 01-07-2006 06:22 PM


All times are GMT -4. The time now is 05:59 PM.


MobileRead.com is a privately owned, operated and funded community.