3 # on-target updater script for Pandora
4 # Copyright (c) 2010, 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
28 mkdir /mnt/ubifs 2> /dev/null || true
30 if [ ! -e /dev/mmcblk0p1 ]
32 # hmh what's up with the SD card?
33 log "Can't access SD card, please reinsert and press enter"
35 test -e /dev/mmcblk0p1
38 mdevs="/dev/mmcblk0p1 /dev/mmcblk0p2"
39 bootfiles="bootf.tgz bootfiles.tar.gz uimage.tar.gz"
45 mpoint="/mnt/`basename $md`"
47 mkdir $mpoint 2> /dev/null || true
48 if ! mount $md $mpoint
53 if [ -x $mpoint/initialize.sh ]
56 log "running init script.."
60 log "initialize.sh failed."
76 if [ -x $mpoint/finalize.sh ]
78 finalize_mpoint=$mpoint
82 if [ -e $mpoint/rootfs.img -a -e $mpoint/rootfs.md5 -a -z "$rootfs_file" ]
84 rootfs_file=$mpoint/rootfs.img
85 rootfs_md5=`head -n 1 $mpoint/rootfs.md5 | cut -c 1-32`
90 if [ "$keep_mpoint" != "yes" ]
98 size=`stat -c %s u-boot.bin`
99 dd if=/dev/mtdblock1 of=u-boot.bin.flashed bs=$size count=1
100 if ! cmp u-boot.bin u-boot.bin.flashed
102 flash_eraseall /dev/mtd1
103 nandwrite -p /dev/mtd1 u-boot.bin
104 log "u-boot.bin flashed."
105 status_uboot="flashed"
107 log "u-boot.bin already flashed, skipped."
108 status_uboot="already there"
111 log "u-boot is missing, skipped."
114 if ! cmp /dev/mtdblock2 /usr/local/erasednandblk
116 flash_eraseall /dev/mtd2
117 status_uboot_env="cleared"
118 log "u-boot environment cleared."
123 # attempt to mount and check
124 ubiattach /dev/ubi_ctrl -m 3 || true
125 mount -t ubifs ubi0:boot /mnt/ubifs 2> /dev/null || true
126 if ! cmp uImage /mnt/ubifs/uImage 2> /dev/null
128 log "flashing uImage.."
129 umount /mnt/ubifs 2> /dev/null || true
130 ubidetach /dev/ubi_ctrl -d 0 2> /dev/null || true
131 # format just in case, should be harmless even it's formated already
132 ubiformat /dev/mtd3 -s 512 -y
133 ubiattach /dev/ubi_ctrl -m 3
134 ubimkvol /dev/ubi0 -m -N boot
135 mount -t ubifs ubi0:boot /mnt/ubifs
136 cp uImage /mnt/ubifs/uImage
137 status_uimage="flashed"
140 log "uImage already flashed, skipped."
141 status_uimage="already there"
144 ubidetach /dev/ubi_ctrl -d 0
146 log "uImage is missing, skipped."
149 if [ -n "$rootfs_file" ]
151 log "Calculating checksum, this might take a few minutes.."
152 real_md5=`md5sum $rootfs_file | cut -c 1-32`
153 if [ "$real_md5" = "$rootfs_md5" ]
162 # be destructive here, too hard to validate rootfs to bother
164 ubiformat /dev/mtd4 -s 512 -y
165 ubiattach /dev/ubi_ctrl -m 4
166 ubimkvol /dev/ubi0 -m -N rootfs
168 log "Writing rootfs, please wait. This may take up to 15 minutes.."
169 ubiupdatevol /dev/ubi0_0 $rootfs_file
170 ubidetach /dev/ubi_ctrl -d 0
171 status_rootfs="flashed"
174 log "root filesystem is missing, skipped."
177 log "======================="
179 log "u-boot: $status_uboot"
180 log "u-boot-env: $status_uboot_env"
181 log "kernel: $status_uimage"
182 log "rootfs: $status_rootfs $rootfs_file"
184 if [ -n "$finalize_mpoint" ]
187 log "running finalize script.."
191 log "finalize.sh failed."