#/bin/sh
#
# on-target updater script for Pandora
-# Copyright (c) 2010, Gražvydas Ignotas
+# Copyright (c) 2010,2012 Gražvydas Ignotas
-set -e
+set -e -x
. /etc/updater_funcs.sh
fi
}
+wait_for_file()
+{
+ for a in `seq 10`
+ do
+ if test -e "$1"
+ then
+ return 0
+ fi
+ sleep .5
+ done
+ return 1
+}
+
+
mkdir /mnt/ubifs 2> /dev/null || true
if [ ! -e /dev/mmcblk0p1 ]
log "u-boot environment cleared."
fi
-if [ -e uImage ]
-then
- # attempt to mount and check
- ubiattach /dev/ubi_ctrl -m 3 || true
- mount -t ubifs ubi0:boot /mnt/ubifs 2> /dev/null || true
- if ! cmp uImage /mnt/ubifs/uImage 2> /dev/null
+# make sure ubifs boot partition is in order
+format_boot()
+{
+ log "formatting boot partition.."
+ umount /mnt/ubifs 2> /dev/null || true
+ ubidetach /dev/ubi_ctrl -d 0 2> /dev/null || true
+ ubiformat /dev/mtd3 -s 512 -y || return 1
+ ubiattach /dev/ubi_ctrl -m 3 || return 1
+ wait_for_file /dev/ubi0 || return 1
+ ubimkvol /dev/ubi0 -m -N boot || return 1
+ wait_for_file /dev/ubi0_0 || return 1
+ mount -t ubifs ubi0:boot /mnt/ubifs || return 1
+}
+
+handle_kernels()
+{
+ kernels=`ls uImage* 2> /dev/null || true`
+ if [ -z "$kernels" ]
then
- log "flashing uImage.."
- umount /mnt/ubifs 2> /dev/null || true
- ubidetach /dev/ubi_ctrl -d 0 2> /dev/null || true
- # format just in case, should be harmless even it's formated already
- ubiformat /dev/mtd3 -s 512 -y
- ubiattach /dev/ubi_ctrl -m 3
- ubimkvol /dev/ubi0 -m -N boot
- mount -t ubifs ubi0:boot /mnt/ubifs
- cp uImage /mnt/ubifs/uImage
- status_uimage="flashed"
- log "done"
- else
- log "uImage already flashed, skipped."
- status_uimage="already there"
+ return 0
fi
- umount /mnt/ubifs
- ubidetach /dev/ubi_ctrl -d 0
-else
- log "uImage is missing, skipped."
+
+ # presence of uImage* is a sign that we can wipe whole boot partition,
+ # but first get rid of potentially bad autoboot.txt
+ rm -f /mnt/ubifs/autoboot.txt
+
+ for kernel in $kernels
+ do
+ if ! cmp $kernel /mnt/ubifs/$kernel 2> /dev/null
+ then
+ log "flashing $kernel .."
+ cp -a $kernel /mnt/ubifs/$kernel || return 1
+ status_uimage="flashed"
+ log "done"
+ else
+ log "$kernel already flashed, skipped."
+ status_uimage="already there"
+ fi
+ done
+ if [ -e bootmenu.txt ]
+ then
+ if ! cmp bootmenu.txt /mnt/ubifs/bootmenu.txt 2> /dev/null
+ then
+ log "updating bootmenu.txt"
+ cp -a bootmenu.txt /mnt/ubifs/bootmenu.txt || return 1
+ fi
+ fi
+}
+
+ubiattach /dev/ubi_ctrl -m 3 || true
+if ! mount -t ubifs ubi0:boot /mnt/ubifs 2> /dev/null
+then
+ format_boot
fi
+if ! handle_kernels
+then
+ log "kernel flashing failed, retrying.."
+ format_boot
+ handle_kernels
+fi
+
+umount /mnt/ubifs
+ubidetach /dev/ubi_ctrl -d 0
+
if [ -n "$rootfs_file" ]
then
log "Calculating checksum, this might take a few minutes.."
log "formatting.."
ubiformat /dev/mtd4 -s 512 -y
ubiattach /dev/ubi_ctrl -m 4
+ wait_for_file /dev/ubi0
ubimkvol /dev/ubi0 -m -N rootfs
+ wait_for_file /dev/ubi0_0
log "done."
log "Writing rootfs, please wait. This may take up to 15 minutes.."
ubiupdatevol /dev/ubi0_0 $rootfs_file