3 # on-target updater script for Pandora
4 # Copyright (c) 2010,2012 GraÅžvydas Ignotas
8 . /etc/updater_funcs.sh
10 status_uboot="missing"
11 status_uboot_env="already empty"
12 status_uimage="missing"
13 status_rootfs="missing"
18 if [ -n "$finalize_mpoint" ]
20 umount $finalize_mpoint 2> /dev/null || true
22 if [ -n "$rootfs_mpoint" ]
24 umount $rootfs_mpoint 2> /dev/null || true
29 mkdir /mnt/ubifs 2> /dev/null || true
31 if [ ! -e /dev/mmcblk0p1 ]
33 # hmh what's up with the SD card?
34 log "Can't access SD card, please reinsert and press enter"
36 test -e /dev/mmcblk0p1
39 mdevs="/dev/mmcblk0p1 /dev/mmcblk0p2"
40 bootfiles="bootf.tgz bootfiles.tar.gz uimage.tar.gz"
46 mpoint="/mnt/`basename $md`"
48 mkdir $mpoint 2> /dev/null || true
49 if ! mount $md $mpoint
54 if [ -x $mpoint/initialize.sh ]
57 log "running init script.."
61 log "initialize.sh failed."
77 if [ -x $mpoint/finalize.sh ]
79 finalize_mpoint=$mpoint
83 if [ -e $mpoint/rootfs.img -a -e $mpoint/rootfs.md5 -a -z "$rootfs_file" ]
85 rootfs_file=$mpoint/rootfs.img
86 rootfs_md5=`head -n 1 $mpoint/rootfs.md5 | cut -c 1-32`
91 if [ "$keep_mpoint" != "yes" ]
99 size=`stat -c %s u-boot.bin`
100 nanddump --omitoob --omitbad -q -l $size -f u-boot.bin.flashed /dev/mtd1ro
101 if ! cmp u-boot.bin u-boot.bin.flashed
103 flash_eraseall /dev/mtd1
104 nandwrite -p /dev/mtd1 u-boot.bin
105 log "u-boot.bin flashed."
106 status_uboot="flashed"
108 log "u-boot.bin already flashed, skipped."
109 status_uboot="already there"
112 log "u-boot is missing, skipped."
115 nanddump --omitoob --omitbad -q -f mtd2dump /dev/mtd2ro
116 if ! cmp mtd2dump /usr/local/erasednandblk
118 flash_eraseall /dev/mtd2
119 status_uboot_env="cleared"
120 log "u-boot environment cleared."
123 # make sure ubifs boot partition is in order
126 log "formatting boot partition.."
127 umount /mnt/ubifs 2> /dev/null || true
128 ubidetach /dev/ubi_ctrl -d 0 2> /dev/null || true
129 ubiformat /dev/mtd3 -s 512 -y || return 1
130 ubiattach /dev/ubi_ctrl -m 3 || return 1
131 wait_for_file /dev/ubi0 || return 1
132 ubimkvol /dev/ubi0 -m -N boot || return 1
133 wait_for_file /dev/ubi0_0 || return 1
134 mount -t ubifs ubi0:boot /mnt/ubifs || return 1
139 kernels=`ls uImage* 2> /dev/null || true`
145 for kernel in $kernels
147 if ! cmp $kernel /mnt/ubifs/$kernel 2> /dev/null
149 log "flashing $kernel .."
150 cp -a $kernel /mnt/ubifs/$kernel || return 1
151 status_uimage="flashed"
154 log "$kernel already flashed, skipped."
155 status_uimage="already there"
158 if [ -e bootmenu.txt ]
160 if ! cmp bootmenu.txt /mnt/ubifs/bootmenu.txt 2> /dev/null
162 log "updating bootmenu.txt"
163 cp -a bootmenu.txt /mnt/ubifs/bootmenu.txt || return 1
166 if [ -e autoboot.txt ]
168 if ! cmp autoboot.txt /mnt/ubifs/autoboot.txt 2> /dev/null
170 log "updating autoboot.txt"
171 cp -a autoboot.txt /mnt/ubifs/autoboot.txt || return 1
174 # get rid of potentially bad autoboot.txt
175 rm -f /mnt/ubifs/autoboot.txt
179 ubiattach /dev/ubi_ctrl -m 3 || true
180 if ! mount -t ubifs ubi0:boot /mnt/ubifs 2> /dev/null
187 log "kernel flashing failed, retrying.."
193 ubidetach /dev/ubi_ctrl -d 0
195 if [ -n "$rootfs_file" ]
197 log "Calculating checksum, this might take a few minutes.."
198 real_md5=`md5sum $rootfs_file | cut -c 1-32`
199 if [ "$real_md5" = "$rootfs_md5" ]
208 # be destructive here, too hard to validate rootfs to bother
210 ubiformat /dev/mtd4 -s 512 -y
211 ubiattach /dev/ubi_ctrl -m 4
212 wait_for_file /dev/ubi0
213 ubimkvol /dev/ubi0 -m -N rootfs
214 wait_for_file /dev/ubi0_0
216 log "Writing rootfs, please wait. This may take up to 15 minutes.."
217 ubiupdatevol /dev/ubi0_0 $rootfs_file
218 ubidetach /dev/ubi_ctrl -d 0
219 status_rootfs="flashed"
222 log "root filesystem is missing, skipped."
225 log "======================="
227 log "u-boot: $status_uboot"
228 log "u-boot-env: $status_uboot_env"
229 log "kernel: $status_uimage"
230 log "rootfs: $status_rootfs $rootfs_file"
232 if [ -n "$finalize_mpoint" ]
235 log "running finalize script.."
239 log "finalize.sh failed."