summaryrefslogtreecommitdiff
path: root/packages/zaurus-updater/spitz/updater.sh.c3000
blob: 9ad81e36cd3e729565859cb27d4b9740a6410e74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/sh


DATAPATH=$1
TMPPATH=/tmp/update
TMPDATA=$TMPPATH/tmpdata.bin
TMPHEAD=$TMPPATH/tmphead.bin

WFLG_KERNEL=0
WFLG_INITRD=0
WFLG_MVERSION=0
WFLG_HDD=0

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

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

#LINUXFMT=ext2
LINUXFMT=ext3
MKE2FSOPT=
if [ "$LINUXFMT" = "ext3" ]; then
	MKE2FSOPT=-j
fi


### 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/

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`

		#echo $TARGETFILE':'$DATASIZE'bytes'
		TARGETTYPE=Invalid
		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
			WFLG_KERNEL=1
			echo 'kernel'
			ISLOGICAL=1
			MODULEID=5
			MODULESIZE=0x13C000
			ADDR=`dc 0xE0000`
			ISFORMATTED=1
			DATAPOS=0
			ONESIZE=524288
			HDTOP=`expr $DATASIZE - 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
			DATAPOS=16
			ONESIZE=1048576
			/sbin/bcut -s 16 -o $TMPHEAD $TARGETFILE
			;;
		MasterVer)
			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!'
			continue
			;;
		*)
			continue
			;;
		esac


		#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

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

		#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
		while [ $DATAPOS -lt $DATASIZE ]
		do
			#data create
			bcut -a $DATAPOS -s $ONESIZE -o $TMPDATA $TARGETFILE
			TMPSIZE=`wc -c $TMPDATA`
			TMPSIZE=`echo $TMPSIZE | cut -d' ' -f1`
			DATAPOS=`expr $DATAPOS + $TMPSIZE`

			#handle data file
			#echo 'ADDR='$ADDR
			#echo 'SIZE='$TMPSIZE
			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
				/sbin/nandlogical $LOGOCAL_MTD WRITE $ADDR $DATASIZE $TMPDATA > /dev/null 2>&1
				ADDR=`expr $ADDR + $TMPSIZE`
			fi

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

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

		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

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'
		if [ ! -f /hdd1/NotAvailable ]; then
		    umount /hdd1
		fi
		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 -t $LINUXFMT -o noatime /dev/${IDE1}1 /hdd1
		if [ "$?" != "0" ]; then
		    echo "Error!"
		    exit "$?"
		fi
    
		cd /
		echo 'Now extracting...'
		gzip -dc $DATAPATH/$HDD1FILE | tar xf -
		if [ "$?" != "0" ]; then
		    echo "Error!"
		    exit "$?"
		fi

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

		## 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

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

exit 0