#!/bin/sh# Tell webif that we're upgradingecho "1" > /var/lock/upgrade.lockcd /tmp/upgradeecho "Verifying firmware" > message# Verify all the files with the corresponding# md5sums#/usr/bin/md5sum -c ramdisk.arm.md5# We need to get the FIS partition list out of flash, edit it a bit and put it back# This is so that we can have a huge root partition ;-)## This is the original partition list:# 0x00000000-0x00040000 0x00040000 RedBoot# 0x00040000-0x00d40000 0x00d00000 ramdisk# 0x00d40000-0x00ea0000 0x00160000 kernel# 0x00ea0000-0x00fc0000 0x00120000 user# 0x00fc0000-0x00fe0000 0x00020000 RedBoot config# 0x00fe0000-0x01000000 0x00020000 FIS directory## In the end, we want this partition list:## 0x00000000-0x00040000 0x00040000 RedBoot# 0x00040000-0x00060000 0x00020000 ramdisk# 0x00060000-0x00200000 0x001A0000 kernel# 0x00200000-0x00fc0000 0x00DC0000 rootfs# 0x00fc0000-0x00fe0000 0x00020000 RedBoot config# 0x00fe0000-0x01000000 0x00020000 FIS directory## We can't remove the "ramdisk" partition, due to the fact that RedBoot loads it during boot,# and we have to write the new firmware to the current partitions, which don't match up with# the way we want it.# Copy the FIS directory to a temporary file. We'll do all the editing on this file, and write it back# when we're finished upgradingecho "Editing partitionlist..." > messagedd if=/dev/mtdblock5 of=fisdir# First, resize the ramdisk partition from 0xd00000 to 0x020000# Then move the kernel partition from offset 0xd40000 to 0x060000, and resize to 0x1A0000# Delete the "user" partition and add a "rootfs" partition at offset 0x200000, size 0xDC0000# Now we need to write the new firmware to flash, but we don't have an updated fis partition# list until after we've rebooted, so we need to split up the new firmware into appropriately-sized# chunks, and write it to the current flash layoutecho "Writing kernel and rootfs. Please wait." > message# Fill the current "ramdisk" partition with 128kb empty, then add the kernel# The current "ramdisk" partition is 13631488 bytes large, so we'll just write everything# into that partition, unless the file gets too large for the partition ;-)MAXSIZE=136314888dd if=/dev/zero of=mtdtemp1 bs=128kb count=1cat mtdtemp1 zImage rootfs > mtdtemp2FLASHSIZE=`du mtdtemp2 |cut -d " " -f 1`CHECKSIZE=`expr $MAXSIZE - $FLASHSIZE`if [ ! $CHECKSIZE -gt 0 ]; then echo "Flash image too large" > debug echo "Flash image too large" > message exit 1fi# Actually write the blocks.# /sbin/fcp -v mtdblock1 /dev/mtd1# Write back fisdir# /sbin/fcp -v mtdblock5 /dev/mtd5# Tell the user and webinterface that we're done upgradingecho "Done!" > messageecho "Buzzer 0" > /proc/thecus_iosleep 1echo "Buzzer 1" > /proc/thecus_iorm /var/lock/upgrade.lock