SL-C3000 Updater Script

From OESF

(Difference between revisions)
Jump to: navigation, search
Current revision (21:11, 5 April 2005) (edit) (undo)
 

Line 354:

Line 354:

#finish
#finish
rm -f $TMPPATH/*.bin > /dev/null 2>&1
rm -f $TMPPATH/*.bin > /dev/null 2>&1
-
 
-
## On error we blow the kernel away!! - just to brick the Z safely
 
if [ $RESULT = 0 ]
if [ $RESULT = 0 ]

Current revision

Here's a highly commented walkthrough of the Sharp installer script.

With modifications to make it work properly.

#!/bin/sh

## Script is called with location of files as arg[1]
DATAPATH=$1
## Define a temporary path
TMPPATH=/tmp/update
## These two file names are used by the script as storage locations
## when the original distribution files are chopped up.
## TMPDATA will end up with the actual data to be used whilst
## TMPHEAD contains a 16 byte version header stripped from the file.
TMPDATA=$TMPPATH/tmpdata.bin
TMPHEAD=$TMPPATH/tmphead.bin

## Config flags, set to 1 will inhibit processing of that file type
WFLG_KERNEL=0
WFLG_INITRD=0
WFLG_MVERSION=0
WFLG_HDD=0

## Survey the mtd partitions from the /proc file system.
RO_MTD_LINE=`cat /proc/mtd | grep "root" | tail -n 1`
if [ "$RO_MTD_LINE" = "" ]; then
    RO_MTD_LINE=`cat /proc/mtd | grep "\<NAND\>.*\<2\>" | tail -n 1`
fi
RO_MTD_NO=`echo $RO_MTD_LINE | cut -d: -f1 | cut -dd -f2`
RO_MTD_SIZE_HEX=`echo $RO_MTD_LINE | cut -d" " -f2`
RO_MTD=/dev/mtd$RO_MTD_NO
RO_MTDBLK=/dev/mtdblock$RO_MTD_NO
RO_MTD_SIZE=`dc 0x$RO_MTD_SIZE_HEX 1024 /`

RW_MTD_LINE=`cat /proc/mtd | grep "home" | tail -n 1`
if [ "$RW_MTD_LINE" = "" ]; then
    RW_MTD_LINE=`cat /proc/mtd | grep "\<NAND\>.*\<2\>" | tail -n 1`
fi
RW_MTD_NO=`echo $RW_MTD_LINE | cut -d: -f1 | cut -dd -f2`
RW_MTD_SIZE_HEX=`echo $RW_MTD_LINE | cut -d" " -f2`
RW_MTD=/dev/mtd$RW_MTD_NO
RW_MTDBLK=/dev/mtdblock$RW_MTD_NO
RW_MTD_SIZE=`dc 0x$RW_MTD_SIZE_HEX 1024 /` 

LOGOCAL_MTD=/dev/mtd1

## We exit this block with the important variables RO_MTD, RO_MTDBLK,
## RW_MTD, RW_MTDBLK and LOGOCAL_MTD

## Defines addresses for the Version and Master version blocks in
## flash.
VERBLOCK=0x48000
MVRBLOCK=0x70000

RESULT=0

Cleanup(){
	rm -f $VTMPNAME > /dev/null 2>&1
	rm -f $MTMPNAME > /dev/null 2>&1
	rm $CTRLPATH/* > /dev/null 2>&1
	rm $DATAPATH/* > /dev/null 2>&1
	exit $1
}
trap 'Cleanup 1' 1 15
trap  2 3

get_dev_pcmcia()
{
while read SOCKET CLASS DRIVER INSTANCE DEVS MAJOR MINOR;
do
    echo $DEVS
done
}
get_dev_pcmcia_slot()
{
    grep "^$1" /var/lib/pcmcia/stab | get_dev_pcmcia
}
sleep 1
IDE1=`get_dev_pcmcia_slot 1`
if [ "$IDE1" = "" ]; then
    echo "Error!! There is no HDD. Now retrying..."
    while [ "$IDE1" = "" ]; do
	IDE1=`get_dev_pcmcia_slot 1`
    done
    echo "Found HDD!!"
fi

## You should be able to work this out!
#LINUXFMT=ext2
LINUXFMT=ext3
MKE2FSOPT=
if [ "$LINUXFMT" = "ext3" ]; then
	MKE2FSOPT=-j
fi

## Actually don't know what writerominfo does but I suspect
## That it surveys some existing information.

### Check model ###
/sbin/writerominfo
MODEL=`cat /proc/deviceinfo/product`
if [ "$MODEL" != "SL-C3000" ]
then
	echo 'MODEL:'$MODEL
	echo 'ERROR:Invalid model!'
	echo 'Please reset'
	while true
	do
	done
fi 

mkdir -p $TMPPATH > /dev/null 2>&1

cd $DATAPATH/

## Main loop cycles through all files on the distribution source
## it's actually quite useful since you can omit certain files
## to omit certain operations when developing.

for TARGETFILE in zImage.bin zimage.bin ZIMAGE.BIN initrd.bin INITRD.BIN mversion.bin MVERSION.BIN
do
	if [ -e $TARGETFILE ]
	then
		rm -f $TMPPATH/*.bin > /dev/null 2>&1
		DATASIZE=`wc -c $TARGETFILE`
		DATASIZE=`echo $DATASIZE | cut -d' ' -f1` 

## DATASIZE now contains the actual file size

		#echo $TARGETFILE':'$DATASIZE'bytes'
		TARGETTYPE=Invalid

## Setting the target type allows the particular type of programming
## operation dependent upon the type of file – this bit deals with
## all the likely permutations of file name.
## Also note that this only deals with NAND type images.
## hdimage1 is handled later on!

		case "$TARGETFILE" in
		zImage.bin) TARGETTYPE=Kernel;;
		zimage.bin) TARGETTYPE=Kernel;;
		ZIMAGE.BIN) TARGETTYPE=Kernel;;
		initrd.bin) TARGETTYPE=RoFs;;
		INITRD.BIN) TARGETTYPE=RoFs;;
		mversion.bin) TARGETTYPE=MasterVer;;
		MVERSION.BIN) TARGETTYPE=MasterVer;;
		*)
			continue
			;;
		esac

		case "$TARGETTYPE" in
		Kernel)
			if [ $WFLG_KERNEL != 0 ]
			then
				continue
			fi

## OK I'll discuss the main highlights once.
## WFLG_KERNEL = 1 is set so that the script understands
## that the kernel write operation is complete in case it
## encounters another variation of the file name on another
## loop.
## ISLOGICAL = 1 means that a raw nandlogical operation is performed
## rather than a nandcp. nandlogical is used to write non-filesystem
## type blocks to the flash.
## MODULEID = 5 identifies the flash block for the main Kernel
## MODULESIZE = 0x13C000 defines the UPPER LIMIT on the size
## ADDR = `dc 0xE0000` evaluates the start address to decimal
## ISFORMATTED = 1 is used to say that the block doesn't need erasing
## DATAPOS = 0 says that the data starts right at the beginning of
## the file.
## ONESIZE = 524288 is used as a block size for programming and
## percent display during the programming portion of the script.

			WFLG_KERNEL=1
			echo 'kernel'
			ISLOGICAL=1
			MODULEID=5
			MODULESIZE=0x13C000
			ADDR=`dc 0xE0000`
			ISFORMATTED=1
			DATAPOS=0
			ONESIZE=524288

## HDTOP is set to be 16 bytes off the end of the file..

			HDTOP=`expr $DATASIZE – 16`

## The version information is chopped out of the file and stored in
## the $TMPHEAD location – 16 bytes long (-s 16).

			/sbin/bcut -a $HDTOP -s 16 -o $TMPHEAD $TARGETFILE
			;;
		RoFs)
			if [ $WFLG_INITRD != 0 ]
			then
				continue
			fi
			WFLG_INITRD=1
			echo 'RO file system'
			ISLOGICAL=0
			MODULEID=6
			MODULESIZE=0x500000
			ADDR=0
			ISFORMATTED=0
			TARGET_MTD=$RO_MTD 

## Since the data starts AFTER the version information on the
## initrd.bin file we bcut at 0 (no -a parameter)

			DATAPOS=16
			ONESIZE=1048576
			/sbin/bcut -s 16 -o $TMPHEAD $TARGETFILE
			;;
		MasterVer)

## Master version block is simple, we just do all the ops in the
## case statement. note the use of nandlogical because this is not
## a file system.
## verchg is used to manipulate the version information based upon
## the contents of the version information supplied.
## Note that the script reads the block, modifies it and then writes

			if [ $WFLG_MVERSION != 0 ]
			then
				continue
			fi
			WFLG_MVERSION=1
			echo 'Master version'
			MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp'
			/sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1
			/sbin/verchg -m $MTMPNAME $TARGETFILE 0 0 > /dev/null 2>&1
			/sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1
			rm -f $MTMPNAME > /dev/null 2>&1
			echo 'Success!' 

## Note this is important... not break but continue..
## this loops back to the beginning of the for loop.
## This is why the mversion stuff never enters the NAND
## programming loop later.

			continue
			;;
		*)
			continue
			;;
		esac

## Typically only formats file system type blocks, the Kernel block
## doesn't get this (refer back)

		#format?
		if [ $ISFORMATTED = 0 ]
		then
			echo -n 'Flash erasing...'
			/sbin/eraseall $TARGET_MTD 2> /dev/null > /dev/null
			#/sbin/eraseall $TARGET_MTD 2
			echo 'done'
			ISFORMATTED=1
		fi 

## Display % indicator and calculate the programming step

		echo 
		echo '0%                      100%'
		PROGSTEP=`expr $DATASIZE / $ONESIZE + 1`
		PROGSTEP=`expr 28 / $PROGSTEP`
		if [ $PROGSTEP = 0 ]
		then
			PROGSTEP=1
		fi

## Update the version block and master version block based upon
## the information provided in the image.

		#00 means header information
		VTMPNAME=$TMPPATH'/vtmp'`date '+%s'`'.tmp'
		MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp'
		/sbin/nandlogical $LOGOCAL_MTD READ $VERBLOCK 0x4000 $VTMPNAME > /dev/null 2>&1
		/sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1

		#echo 'found header'
		/sbin/verchg -v $VTMPNAME $TMPHEAD $MODULEID $MODULESIZE > /dev/null 2>&1
		/sbin/verchg -m $MTMPNAME $TMPHEAD $MODULEID $MODULESIZE > /dev/null 2>&1

		#loop

## Cycle through the programming loop./

		while [ $DATAPOS -lt $DATASIZE ]
		do
			#data create 

## Cut a chunk into the $TMPDATA path...

			bcut -a $DATAPOS -s $ONESIZE -o $TMPDATA $TARGETFILE 

## Get the size of the cut data

			TMPSIZE=`wc -c $TMPDATA`
			TMPSIZE=`echo $TMPSIZE | cut -d' ' -f1`

## Get the next DATAPOS for the next loop through.

			DATAPOS=`expr $DATAPOS + $TMPSIZE`

			#handle data file
			#echo 'ADDR='$ADDR
			#echo 'SIZE='$TMPSIZE

## Use nandcp for file system type images (initrd)

			if [ $ISLOGICAL = 0 ]
			then
				next_addr=`/sbin/nandcp -a $ADDR $TMPDATA $TARGET_MTD  2>/dev/null | fgrep "mtd address" | cut -d- -f2 | cut -d\( -f1`
				if [ "$next_addr" = "" ]; then
					echo "ERROR:flash write"
					rm $TMPDATA > /dev/null 2>&1
					RESULT=3
					break;
				fi
				ADDR=$next_addr
			else

## Use nandlogical for other types of operations (including Kernel)

				## Bug in Sharp bit
				## original line...
				## /sbin/nandlogical $LOGOCAL_MTD WRITE $ADDR $DATASIZE $TMPDATA > /dev/null 2>&1
				## didn't use correctly determined block size
				## cause problems for other kernels
				/sbin/nandlogical $LOGOCAL_MTD WRITE $ADDR $TMPSIZE $TMPDATA > /dev/null 2>&1
				ADDR=`expr $ADDR + $TMPSIZE`
			fi

			rm $TMPDATA > /dev/null 2>&1

## Rudimentary % display in dots

			#progress
			SPNUM=0
			while [ $SPNUM -lt $PROGSTEP ]
			do
				echo -n '.'
				SPNUM=`expr $SPNUM + 1`
			done
		done

## NAND programming loop has finished

		echo 

#finish
		rm -f $TMPPATH/*.bin > /dev/null 2>&1

		if [ $RESULT = 0 ]
		then
			/sbin/nandlogical $LOGOCAL_MTD WRITE $VERBLOCK 0x4000 $VTMPNAME > /dev/null 2>&1
			/sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1

			rm -f $VTMPNAME > /dev/null 2>&1
			rm -f $MTMPNAME > /dev/null 2>&1
			echo 'Success!'
		else
			echo 'Error!'
			exit $RESULT
		fi
	fi
done

## Now we deal with the HD image !

HDD1FILE=hdimage1.tgz
## HDD image
for TARGETFILE in hdimage1.tgz HDIMAGE1.TGZ
do
	 if [ -e $TARGETFILE ]; then
		if [ $WFLG_HDD != 0 ]
	 	then
			continue
		fi
		WFLG_HDD=1
		echo 
		echo 'HDD RO file system'

## Make doubly sure the hdd1 partition isn't mounted by checking
## for the telltale NotAvailable file which normally gets overmounted
## by the HDD.

		if [ ! -f /hdd1/NotAvailable ]; then
		    umount /hdd1
		fi

## Format....

		echo 'Now formatting...'
		mke2fs $MKE2FSOPT /dev/${IDE1}1 2> /dev/null > /dev/null
		e2fsck -p /dev/${IDE1}1 > /dev/null
		if [ "$?" != "0" ]; then
		    echo "Error!"
		    exit "$?"
		fi

## Mount...

		mount -t $LINUXFMT -o noatime /dev/${IDE1}1 /hdd1
		if [ "$?" != "0" ]; then
		    echo "Error!"
		    exit "$?"
		fi
    
		cd /
		echo 'Now extracting...'

## Expand and extract using pipe rather than the tmp location.
## we may not have much space free in /tmp.

		gzip -dc $DATAPATH/$HDD1FILE | tar xf -
		if [ "$?" != "0" ]; then
		    echo "Error!"
		    exit "$?"
		fi

## Yes, well judge your own conclusions what Sharp are doing here!

		# delete java if no java model
		if [ ! -f /root/.java ]; then
			rm -rf /hdd1/usr/QtPalmtop.rom/j2me
		fi

## Update version stuff

		## write check sum
		ORGFILE=$DATAPATH/mversion.bin
		if [ ! -f $ORGFILE ]; then
		    ORGFILE=$DATAPATH/MVERSION.BIN
		fi
		MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp'
		/sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1
		/sbin/verchg_hdd $MTMPNAME $ORGFILE 9 > /dev/null 2>&1
		/sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1
		rm -f $MTMPNAME > /dev/null 2>&1

## Remount file system prior to restart !

		echo 'Success!'
		# remount as RO
		umount /hdd1
		mount -t $LINUXFMT -o ro,noatime /dev/${IDE1}1 /hdd1
	fi
done

exit 0
Personal tools