#!/bin/sh
# MTD Map
# 0 - bootloader (nor)
# 1 - kernel (nor)
# 2 - nor rootfs (nor)
# 3 - nand rootfs
echo "Running Updater ...."
# set up a few things we need like proc, dev entries
mount -t proc proc /proc
# set up device nodes
/etc/init.d/devices
# if user switch is pressed, don't lauch main system
if grep clear /proc/gpio/USER_SWITCH 1>/dev/null
then
echo "User switch pressed, booting normal init in NOR fs ..."
exec /sbin/init 5
fi
# sleep long enough for USB disk to be discovered by kernel
echo "Waiting 6 seconds for USB flash disk detection ..."
sleep 6
echo "Checking for update images on USB flash ..."
[ -e /usb ] || mkdir /usb
NAND_CHAR_DEV=/dev/mtd3
JFFS2_IMAGE=/usb/nand.jffs2
NOR_ROOTFS_IMAGE=/usb/nor_rootfs.img
NOR_KERNEL_IMAGE=/usb/nor_kernel.img
if mount /dev/sda1 /usb 2>/dev/null; then
usb_mounted=1
echo 'found disk at /dev/sda1'
fi
if [ ! $usb_mounted ]; then
if mount /dev/sda /usb 2>/dev/null; then
usb_mounted=1
echo 'found disk at /dev/sda'
fi
fi
if [ -e $NOR_ROOTFS_IMAGE ]; then
echo 'WARNING, This update mechanism is obsolete, please remove $NOR_ROOTFS_IMAGE from usb disk'
reboot_required=1
update_error=1
fi
if [ -e $NOR_KERNEL_IMAGE ]; then
echo 'WARNING, This update mechanism is obsolete, please remove $NOR_KERNEL_IMAGE from usb disk'
reboot_required=1
update_error=1
fi
# look for jffs2 image
if [ -e $JFFS2_IMAGE ]; then
echo 'WARNING, This update mechanism is obsolete, please remove $JFFS2_IMAGE from usb disk'
reboot_required=1
update_error=1
fi
if [ $update_error ]; then
echo 'Remove files from USB drive and cycle power'
sleep 9999d
fi
# look for img files (new method)
if [ -e /usb/svs_update.img ]; then
echo 'Found update image, verifying ...'
cd /tmp
if ! tar -x -f /usb/svs_update.img; then
echo 'Error extracting update image'
exec /sbin/init 5
fi
# check checksums
if ! md5sum -c svs_update.md5; then
echo 'Error checksum error in update file'
echo 'Please cycle power to restart process'
exec /sbin/init 5
fi
# see if kernel or nor flash need updated
updater
updater_ret=$?
if [ $updater_ret -eq 0 ]; then
echo 'Kernel and NOR rootfs up to date'
elif [ $updater_ret -eq 1 ]; then
echo 'critical components updated, rebooting ... '
umount /usb
shutdown -r -n -f now
sleep 9999d
else
echo 'NOR update failed'
exec /sbin/init 5
fi
echo 'updating NAND flash'
if ! flash_eraseall -j $NAND_CHAR_DEV; then
echo "ERROR: flash_eraseall failure"
exec /sbin/init 5
fi
if ! nandwrite $NAND_CHAR_DEV nand.jffs2; then
echo "ERROR: nandwrite failure"
exec /sbin/init 5
fi
echo "NAND filesystem update success!"
reboot_required=1
fi
if [ $usb_mounted ];then
umount /usb
fi
if [ $reboot_required ];then
echo "Updater v2"
echo "Update complete, remove USB device and cycle power"
sleep 9999d
fi
# if user switch is pressed, don't lauch main system
if grep clear /proc/gpio/USER_SWITCH 1>/dev/null; then
echo "User switch pressed, booting normal init in NOR fs ..."
exec /sbin/init 5
fi
echo "mounting main filesystem ..."
mkdir /jffs2
mount -t jffs2 mtd3 /jffs2
echo "booting main filesystem ..."
exec switch_root -c /dev/console /jffs2 /sbin/init 5