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
42 mkdir /mnt/ubifs 2> /dev/null || true
44 if [ ! -e /dev/mmcblk0p1 ]
46 # hmh what's up with the SD card?
47 log "Can't access SD card, please reinsert and press enter"
49 test -e /dev/mmcblk0p1
52 mdevs="/dev/mmcblk0p1 /dev/mmcblk0p2"
53 bootfiles="bootf.tgz bootfiles.tar.gz uimage.tar.gz"
59 mpoint="/mnt/`basename $md`"
61 mkdir $mpoint 2> /dev/null || true
62 if ! mount $md $mpoint
67 if [ -x $mpoint/initialize.sh ]
70 log "running init script.."
74 log "initialize.sh failed."
90 if [ -x $mpoint/finalize.sh ]
92 finalize_mpoint=$mpoint
96 if [ -e $mpoint/rootfs.img -a -e $mpoint/rootfs.md5 -a -z "$rootfs_file" ]
98 rootfs_file=$mpoint/rootfs.img
99 rootfs_md5=`head -n 1 $mpoint/rootfs.md5 | cut -c 1-32`
100 rootfs_mpoint=$mpoint
104 if [ "$keep_mpoint" != "yes" ]
112 size=`stat -c %s u-boot.bin`
113 nanddump --omitoob --omitbad -q -l $size -f u-boot.bin.flashed /dev/mtd1ro
114 if ! cmp u-boot.bin u-boot.bin.flashed
116 flash_eraseall /dev/mtd1
117 nandwrite -p /dev/mtd1 u-boot.bin
118 log "u-boot.bin flashed."
119 status_uboot="flashed"
121 log "u-boot.bin already flashed, skipped."
122 status_uboot="already there"
125 log "u-boot is missing, skipped."
128 nanddump --omitoob --omitbad -q -f mtd2dump /dev/mtd2ro
129 if ! cmp mtd2dump /usr/local/erasednandblk
131 flash_eraseall /dev/mtd2
132 status_uboot_env="cleared"
133 log "u-boot environment cleared."
136 # make sure ubifs boot partition is in order
139 log "formatting boot partition.."
140 umount /mnt/ubifs 2> /dev/null || true
141 ubidetach /dev/ubi_ctrl -d 0 2> /dev/null || true
142 ubiformat /dev/mtd3 -s 512 -y || return 1
143 ubiattach /dev/ubi_ctrl -m 3 || return 1
144 wait_for_file /dev/ubi0 || return 1
145 ubimkvol /dev/ubi0 -m -N boot || return 1
146 wait_for_file /dev/ubi0_0 || return 1
147 mount -t ubifs ubi0:boot /mnt/ubifs || return 1
152 kernels=`ls uImage* 2> /dev/null || true`
158 # presence of uImage* is a sign that we can wipe whole boot partition,
159 # but first get rid of potentially bad autoboot.txt
160 rm -f /mnt/ubifs/autoboot.txt
162 for kernel in $kernels
164 if ! cmp $kernel /mnt/ubifs/$kernel 2> /dev/null
166 log "flashing $kernel .."
167 cp -a $kernel /mnt/ubifs/$kernel || return 1
168 status_uimage="flashed"
171 log "$kernel already flashed, skipped."
172 status_uimage="already there"
175 if [ -e bootmenu.txt ]
177 if ! cmp bootmenu.txt /mnt/ubifs/bootmenu.txt 2> /dev/null
179 log "updating bootmenu.txt"
180 cp -a bootmenu.txt /mnt/ubifs/bootmenu.txt || return 1
185 ubiattach /dev/ubi_ctrl -m 3 || true
186 if ! mount -t ubifs ubi0:boot /mnt/ubifs 2> /dev/null
193 log "kernel flashing failed, retrying.."
199 ubidetach /dev/ubi_ctrl -d 0
201 if [ -n "$rootfs_file" ]
203 log "Calculating checksum, this might take a few minutes.."
204 real_md5=`md5sum $rootfs_file | cut -c 1-32`
205 if [ "$real_md5" = "$rootfs_md5" ]
214 # be destructive here, too hard to validate rootfs to bother
216 ubiformat /dev/mtd4 -s 512 -y
217 ubiattach /dev/ubi_ctrl -m 4
218 wait_for_file /dev/ubi0
219 ubimkvol /dev/ubi0 -m -N rootfs
220 wait_for_file /dev/ubi0_0
222 log "Writing rootfs, please wait. This may take up to 15 minutes.."
223 ubiupdatevol /dev/ubi0_0 $rootfs_file
224 ubidetach /dev/ubi_ctrl -d 0
225 status_rootfs="flashed"
228 log "root filesystem is missing, skipped."
231 log "======================="
233 log "u-boot: $status_uboot"
234 log "u-boot-env: $status_uboot_env"
235 log "kernel: $status_uimage"
236 log "rootfs: $status_rootfs $rootfs_file"
238 if [ -n "$finalize_mpoint" ]
241 log "running finalize script.."
245 log "finalize.sh failed."