summaryrefslogtreecommitdiffstats
path: root/meta/recipes-bsp/zaurus-updater/zaurus-updater/updater.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-bsp/zaurus-updater/zaurus-updater/updater.sh')
-rw-r--r--meta/recipes-bsp/zaurus-updater/zaurus-updater/updater.sh481
1 files changed, 481 insertions, 0 deletions
diff --git a/meta/recipes-bsp/zaurus-updater/zaurus-updater/updater.sh b/meta/recipes-bsp/zaurus-updater/zaurus-updater/updater.sh
new file mode 100644
index 0000000000..22d4b3914d
--- /dev/null
+++ b/meta/recipes-bsp/zaurus-updater/zaurus-updater/updater.sh
@@ -0,0 +1,481 @@
1#!/bin/sh
2#
3# One updater.sh to rule them all
4#
5# 2006.10.24 Marcin 'Hrw' Juszkiewicz
6# - started work on common updater.sh
7# - works on poodle, c760, spitz
8# - breaks on tosa
9#
10# 2007.10.08 Marcin 'Hrw' Juszkiewicz
11# - do not allow to flash files bigger then partition size
12# - created functions for common stuff
13#
14# 2007.11.18 Dmitry 'Lumag' Baryshkov
15# - fixes
16# - tosa unbreak
17#
18# 2007.11.19 Marcin 'Hrw' Juszkiewicz
19# - size check unbreak
20# - c760/c860 has bigger rootfs - use it
21#
22# 2007.11.23 Koen Kooi
23# - consistent error messages
24# - fix flashing from case sensitive filesystem (e.g. ext2)
25#
26# 2007.11.23 Matthias 'CoreDump' Hentges
27# - Always treat MTD_PART_SIZE as HEX when comparing sizes
28# - Thanks to ZeroChaos for debugging
29#
30# 2007.12.04 Matthias 'CoreDump' Hentges
31# - Unb0rk flashing of Akita kernels
32#
33# 2007.12.10 Marcin 'Hrw' Juszkiewicz
34# - Reformatted file - please use spaces not tabs
35# - "version check" is only on Tosa and Poodle - breaks other machines
36#
37# 2007.12.23 Matthias 'CoreDump' Hentges
38# - Fix kernel install on spitz machines
39# - Unify format of do_flashing()...
40# - Display ${PR} of zaurus-updater.bb to the user
41# - Polish HDD installer messages
42#
43# 2007.12.25 Matthias 'CoreDump' Hentges
44# -Add support for installing / updating u-boot
45
46# Set to "yes" to enable
47ENABLE_UBOOT_UPDATER="no"
48
49DATAPATH=$1
50TMPPATH=/tmp/update
51TMPDATA=$TMPPATH/tmpdata.bin
52TMPHEAD=$TMPPATH/tmphead.bin
53
54FLASHED_KERNEL=0
55FLASHED_ROOTFS=0
56UNPACKED_ROOTFS=0 # spitz only
57
58RO_MTD_LINE=`cat /proc/mtd | grep "root" | tail -n 1`
59if [ "$RO_MTD_LINE" = "" ]; then
60 RO_MTD_LINE=`cat /proc/mtd | grep "\<NAND\>.*\<2\>" | tail -n 1`
61fi
62RO_MTD_NO=`echo $RO_MTD_LINE | cut -d: -f1 | cut -dd -f2`
63RO_MTD=/dev/mtd$RO_MTD_NO
64ROOTFS_SIZE=`echo $RO_MTD_LINE | cut -d" " -f2`
65
66LOGOCAL_MTD=/dev/mtd1
67
68VERBLOCK=0x48000
69MVRBLOCK=0x70000
70
71RESULT=0
72
73Cleanup()
74{
75 rm -f $VTMPNAME > /dev/null 2>&1
76 rm -f $MTMPNAME > /dev/null 2>&1
77 exit $1
78}
79
80trap 'Cleanup 1' 1 15
81trap '' 2 3
82
83get_dev_pcmcia()
84{
85 while read SOCKET CLASS DRIVER INSTANCE DEVS MAJOR MINOR;
86 do
87 echo $DEVS
88 done
89}
90
91get_dev_pcmcia_slot()
92{
93 grep "^$1" /var/lib/pcmcia/stab | get_dev_pcmcia
94}
95
96check_for_hdd()
97{
98 IDE1=`get_dev_pcmcia_slot 1`
99 if [ "$IDE1" = "" ]; then
100 echo "Error: There is no microdrive. Retrying..."
101 while [ "$IDE1" = "" ]; do
102 IDE1=`get_dev_pcmcia_slot 1`
103 done
104 echo "Microdrive found."
105 fi
106
107 LINUXFMT=ext3
108 MKE2FSOPT=-j
109}
110
111check_for_tar()
112{
113 ### Check that we have a valid tar
114 for TARNAME in gnu-tar GNU-TAR
115 do
116 if [ -e $DATAPATH/$TARNAME ]
117 then
118 TARBIN=$DATAPATH/$TARNAME
119 fi
120 done
121
122 if [ ! -e $TARBIN ]; then
123 echo 'Error: Please place a valid copy of tar as "gnu-tar" on your card.'
124 echo 'Please reset'
125 while true
126 do
127 done
128 fi
129}
130
131do_rootfs_extraction()
132{
133 UNPACKED_ROOTFS=1
134 echo 'Installing HDD root file system'
135 if [ ! -f /hdd1/NotAvailable ]; then
136 umount /hdd1
137 fi
138 echo -n '* Now formatting...'
139 mke2fs $MKE2FSOPT /dev/${IDE1}1 > /dev/null 2>&1
140 e2fsck -p /dev/${IDE1}1 > /dev/null
141 if [ "$?" != "0" ]; then
142 echo "FAILED"
143 echo "Error: Unable to create filesystem on microdrive!"
144 exit "$?"
145 else
146 echo "Done"
147 fi
148
149 mount -t $LINUXFMT -o noatime /dev/${IDE1}1 /hdd1
150 if [ "$?" != "0" ]; then
151 echo "Error: Unable to mount microdrive!"
152 exit "$?"
153 fi
154
155 cd /hdd1
156 echo -n '* Now extracting (this can take over 5m)...'
157 gzip -dc $DATAPATH/$TARGETFILE | $TARBIN xf -
158 if [ "$?" != "0" ]; then
159 echo "FAILED"
160 echo "Error: Unable to extract root filesystem archive!"
161 exit "$?"
162 else
163 echo "Done"
164 fi
165
166 echo 'HDD Installation Finished.'
167
168 # remount as RO
169 cd /
170 umount /hdd1
171 mount -t $LINUXFMT -o ro,noatime /dev/${IDE1}1 /hdd1
172}
173
174do_flashing()
175{
176 if [ $DATASIZE -gt `printf "%d" $MTD_PART_SIZE` ]
177 then
178 echo "Error: File is too big to flash!"
179 echo "$FLASH_TYPE: [$DATASIZE] > [`printf "%d" ${MTD_PART_SIZE}`]"
180 return
181 fi
182
183 if [ "$ZAURUS" = "tosa" ] || [ "$ZAURUS" = "poodle" ]
184 then
185 #check version
186 /sbin/bcut -s 6 -o $TMPDATA $TMPHEAD
187
188 if [ `cat $TMPDATA` != "SHARP!" ] > /dev/null 2>&1
189 then
190 #no version info...
191 rm -f $TMPHEAD > /dev/null 2>&1
192 DATAPOS=0
193 fi
194 fi
195
196 if [ $ISFORMATTED = 0 ]
197 then
198 /sbin/eraseall $TARGET_MTD > /dev/null 2>&1
199 ISFORMATTED=1
200 fi
201
202 if [ -e $TMPHEAD ]
203 then
204 VTMPNAME=$TMPPATH'/vtmp'`date '+%s'`'.tmp'
205 MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp'
206 /sbin/nandlogical $LOGOCAL_MTD READ $VERBLOCK 0x4000 $VTMPNAME > /dev/null 2>&1
207 /sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1
208
209 /sbin/verchg -v $VTMPNAME $TMPHEAD $MODULEID $MTD_PART_SIZE > /dev/null 2>&1
210 /sbin/verchg -m $MTMPNAME $TMPHEAD $MODULEID $MTD_PART_SIZE > /dev/null 2>&1
211 fi
212
213 # Looks like Akita and Spitz are unique when it comes to kernel flashing
214
215 if [ "$ZAURUS" = "akita" -o "$ZAURUS" = "c3x00" ] && [ "$FLASH_TYPE" = "kernel" ]
216 then
217# echo $TARGETFILE':'$DATASIZE'bytes'
218 echo ""
219 echo -n "Installing SL-Cxx00 kernel..."
220 echo ' ' > /tmp/data
221 test "$ZAURUS" = "akita" && /sbin/nandlogical $LOGOCAL_MTD WRITE 0x60100 16 /tmp/data > /dev/null 2>&1
222 /sbin/nandlogical $LOGOCAL_MTD WRITE 0xe0000 $DATASIZE $TARGETFILE > /dev/null 2>&1
223 test "$ZAURUS" = "akita" && /sbin/nandlogical $LOGOCAL_MTD WRITE 0x21bff0 16 /tmp/data > /dev/null 2>&1
224 echo "Done"
225 else
226
227 echo ''
228 echo '0% 100%'
229 PROGSTEP=`expr $DATASIZE / $ONESIZE + 1`
230 PROGSTEP=`expr 25 / $PROGSTEP`
231
232 if [ $PROGSTEP = 0 ]
233 then
234 PROGSTEP=1
235 fi
236
237 #loop
238 while [ $DATAPOS -lt $DATASIZE ]
239 do
240 #data create
241 bcut -a $DATAPOS -s $ONESIZE -o $TMPDATA $TARGETFILE
242 TMPSIZE=`wc -c $TMPDATA`
243 TMPSIZE=`echo $TMPSIZE | cut -d' ' -f1`
244 DATAPOS=`expr $DATAPOS + $TMPSIZE`
245
246 #handle data file
247 if [ $ISLOGICAL = 0 ]
248 then
249 next_addr=`/sbin/nandcp -a $ADDR $TMPDATA $TARGET_MTD 2>/dev/null | fgrep "mtd address" | cut -d- -f2 | cut -d\( -f1`
250 if [ "$next_addr" = "" ]; then
251 echo "Error: flash write"
252 rm $TMPDATA > /dev/null 2>&1
253 RESULT=3
254 break;
255 fi
256 ADDR=$next_addr
257 else
258 /sbin/nandlogical $LOGOCAL_MTD WRITE $ADDR $DATASIZE $TMPDATA > /dev/null 2>&1
259 ADDR=`expr $ADDR + $TMPSIZE`
260 fi
261
262 rm $TMPDATA > /dev/null 2>&1
263
264 #progress
265 SPNUM=0
266 while [ $SPNUM -lt $PROGSTEP ]
267 do
268 echo -n '.'
269 SPNUM=`expr $SPNUM + 1`
270 done
271 done
272 fi
273 echo ''
274
275 #finish
276 rm -f $TMPPATH/*.bin > /dev/null 2>&1
277
278 if [ $RESULT = 0 ]
279 then
280 if [ -e $VTMPNAME ]
281 then
282 /sbin/nandlogical $LOGOCAL_MTD WRITE $VERBLOCK 0x4000 $VTMPNAME > /dev/null 2>&1
283 rm -f $VTMPNAME > /dev/null 2>&1
284 fi
285
286 if [ -e $MTMPNAME ]
287 then
288 /sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1
289 rm -f $MTMPNAME > /dev/null 2>&1
290 fi
291
292 [ "$FLASH_TYPE" != "kernel" ] && echo 'Done.'
293 else
294 echo 'Error!'
295 fi
296}
297
298update_uboot() {
299 # The flashing part of this function is based on pdaXrom's
300 # updater.sh
301
302 if test "$ENABLE_UBOOT_UPDATER" != "yes" -o -z "$1"
303 then
304 echo "u-boot updates not allowed."
305 return
306 fi
307
308 echo ""
309 echo "Installing u-boot bootloader:"
310
311 DATASIZE=`wc -c $TARGETFILE`
312 FSIZE=`echo $DATASIZE | cut -d' ' -f1`
313
314 echo -n "* Creating backup ($FSIZE Bytes)..."
315 if ( nandlogical /dev/mtd1 READ 0 $FSIZE /tmp/sharploader.bin ) > /dev/null 2>&1
316 then
317 echo "Ok"
318
319 echo -n "* Flashing u-boot..."
320 if ( nandlogical /dev/mtd1 WRITE 0 $FSIZE $1 ) > /dev/null 2>&1
321 then
322 echo "Success"
323 else
324 echo "FAILED"
325 echo "ERROR: Installation of u-boot failed!"
326
327 echo -n "* Trying to restore backup..."
328 if ( nandlogical /dev/mtd1 WRITE 0 $FSIZE /tmp/sharploader.bin ) > /dev/null 2>&1
329 then
330 echo "Success"
331 echo "Your old bootloader has been restored"
332 else
333 echo "FAILED"
334 echo "Sorry, it's NAND-Restore time for you =("
335 fi
336 fi
337 else
338 echo "FAILED"
339 echo "Could not create backup, aborting!"
340 echo "Your bootloader has not been altered in any way."
341 exit 1
342 fi
343}
344
345### Check model ###
346/sbin/writerominfo
347MODEL=`cat /proc/deviceinfo/product`
348case "$MODEL" in
349 SL-B500|SL-5600)
350 ZAURUS='poodle'
351 ;;
352 SL-6000)
353 ZAURUS='tosa'
354 ;;
355 SL-C1000)
356 ZAURUS='akita'
357 ;;
358 SL-C700|SL-C750|SL-7500|SL-C760|SL-C860)
359 ZAURUS='c7x0'
360 ;;
361 SL-C3000|SL-C3100|SL-C3200)
362 ZAURUS='c3x00'
363 check_for_hdd
364 check_for_tar
365 ;;
366 *)
367 echo 'MODEL: '$MODEL 'is unsupported'
368 echo ''
369 echo 'Please reset'
370 while true
371 do
372 done
373 ;;
374esac
375
376clear
377echo "---- Universal Zaurus Updater ZAURUS_UPDATER_VERSION ----"
378echo 'MODEL: '$MODEL' ('$ZAURUS')'
379
380mkdir -p $TMPPATH > /dev/null 2>&1
381
382cd $DATAPATH/
383
384for TARGETFILE in u-boot.bin U-BOOT.BIN zimage zImage zImage.bin zimage.bin ZIMAGE ZIMAGE.BIN initrd.bin INITRD.BIN hdimage1.tgz HDIMAGE1.TGZ
385do
386 if [ ! -e $TARGETFILE ]
387 then
388 continue
389 fi
390
391 rm -f $TMPPATH/*.bin > /dev/null 2>&1
392 DATASIZE=`wc -c $TARGETFILE`
393 DATASIZE=`echo $DATASIZE | cut -d' ' -f1`
394
395 # make TARGETFILE lowercase
396 TARGETFILE_LC=`echo $TARGETFILE|tr A-Z a-z`
397
398 case "$TARGETFILE_LC" in
399
400 zimage|zimage.bin)
401 if [ $FLASHED_KERNEL != 0 ]
402 then
403 continue
404 fi
405 FLASHED_KERNEL=1
406 ISLOGICAL=1
407 MODULEID=5
408 MTD_PART_SIZE=0x13C000
409 ADDR=`dc 0xE0000`
410 ISFORMATTED=1
411 DATAPOS=0
412 ONESIZE=524288
413 HDTOP=`expr $DATASIZE - 16`
414 /sbin/bcut -a $HDTOP -s 16 -o $TMPHEAD $TARGETFILE
415 FLASH_TYPE="kernel"
416 do_flashing
417 FLASH_TYPE=""
418 ;;
419
420 initrd.bin)
421 if [ $FLASHED_ROOTFS != 0 ]
422 then
423 continue
424 fi
425 echo 'root file system'
426 FLASHED_ROOTFS=1
427 ISLOGICAL=0
428 MODULEID=6
429 MTD_PART_SIZE="0x$ROOTFS_SIZE"
430 ADDR=0
431 ISFORMATTED=0
432 TARGET_MTD=$RO_MTD
433 DATAPOS=16
434 ONESIZE=1048576
435 /sbin/bcut -s 16 -o $TMPHEAD $TARGETFILE
436 FLASH_TYPE="rootfs"
437 do_flashing
438 FLASH_TYPE=""
439 ;;
440
441 hdimage1.tgz)
442 if [ $UNPACKED_ROOTFS = 0 ]
443 then
444 do_rootfs_extraction
445 fi
446 ;;
447
448 u-boot.bin)
449 if [ FLASHED_UBOOT != 1 ]
450 then
451 update_uboot "$TARGETFILE"
452 FLASHED_UBOOT="1"
453 fi
454 ;;
455
456 *)
457 ;;
458 esac
459done
460
461# reboot
462exit 0
463
464# bcut usage: bcut [OPTION] <input file>
465
466# -a: start position
467# -s: cut size
468# -o: output file
469
470# ModuleId informations used by verchg Sharp binary:
471#
472# 0 - master
473# 1 - Maintaince
474# 2 - Diagnostics
475# 3 - rescue kernel
476# 4 - rescue rootfs
477# 5 - normal kernel
478# 6 - normal rootfs
479# 7 - /home/
480# 8 - parameter (whatever it means)
481#