summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2010-04-30 10:48:31 -0500
committerJesse Gilles <jgilles@multitech.com>2010-04-30 10:48:31 -0500
commitcd5e509fb9514c902e954392574f91ce56a4e1d0 (patch)
treec2ed0db9e44be37ffba629d52a74e0dbfe1cc098
parent55e6ac0d5ef31c06f67f4bf4007feede970b4e70 (diff)
initscripts: add CoreCDP flash on reboot support
-rw-r--r--recipes/initscripts/initscripts-1.0/corecdp/umountfs120
1 files changed, 120 insertions, 0 deletions
diff --git a/recipes/initscripts/initscripts-1.0/corecdp/umountfs b/recipes/initscripts/initscripts-1.0/corecdp/umountfs
new file mode 100644
index 0000000000..ab3d709f70
--- /dev/null
+++ b/recipes/initscripts/initscripts-1.0/corecdp/umountfs
@@ -0,0 +1,120 @@
+#! /bin/sh
+#
+# umountfs Turn off swap and unmount all local filesystems.
+#
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+umount_all() {
+ echo "Deactivating swap..."
+ swapoff -a
+
+ # We leave /proc mounted.
+ echo "Unmounting local filesystems..."
+ mount -o remount,ro /mnt/ram
+ umount -f -a -r
+
+ mount -o remount,ro /
+}
+
+flash_upgrade() {
+ if [ $# -ne 1 ]; then
+ echo "need to specify flash-root"
+ return
+ fi
+ # flash_root must be a mountpoint that is not the rootfs and be mounted rw
+ local flash_root=${1}
+
+ local flash_dir=${flash_root}/flash-upgrade
+ local uImage_file=${flash_dir}/uImage.bin
+ local rootfs_file=${flash_dir}/rootfs.jffs2
+
+ local reboot_cmd=/usr/sbin/upgrade-reboot
+ local nandwrite_cmd=/usr/bin/nandwrite.static
+ local mode=
+ local uImage_mtd=
+ local rootfs_mtd=
+
+ if [ ! -d "${flash_dir}" ]; then
+ echo "${flash_dir} not present, skipping"
+ return
+ fi
+
+ if ! mountpoint -q "${flash_root}"; then
+ echo "${flash_root} is not a mountpoint"
+ return
+ fi
+
+ mode=$(grep "${flash_root}" /proc/mounts | cut -d ' ' -f 4 | cut -d ',' -f 1)
+ if [ "${mode}" != "rw" ]; then
+ echo "${flash_root} is not mounted rw"
+ return
+ fi
+
+ if [ ! -x "${reboot_cmd}" ]; then
+ echo "${reboot_cmd} is not installed"
+ return
+ fi
+
+ if [ ! -x "${nandwrite_cmd}" ]; then
+ echo "${nandwrite_cmd} is not installed"
+ return
+ fi
+
+ uImage_mtd="/dev/$(cat /proc/mtd | grep uImage | cut -d : -f 1)"
+ if [ ! -c "${uImage_mtd}" ]; then
+ echo "No valid MTD partition is labeled uImage"
+ return
+ fi
+
+ rootfs_mtd="/dev/$(cat /proc/mtd | grep Rootfs | cut -d : -f 1)"
+ if [ ! -c "${rootfs_mtd}" ]; then
+ echo "No valid MTD partition is labeled Rootfs"
+ return
+ fi
+
+ if [ -f ${uImage_file} ]; then
+ echo "Flashing ${uImage_mtd} (uImage) with ${uImage_file}..."
+
+ flash_eraseall ${uImage_mtd}
+ nandwrite -p ${uImage_mtd} ${uImage_file}
+
+ echo "Remember to clean-up ${uImage_file} after reboot"
+ fi
+
+ if [ -f ${rootfs_file} ]; then
+ echo "Flashing ${rootfs_mtd} (rootfs) with ${rootfs_file}..."
+
+ cp ${reboot_cmd} ${flash_dir}/upgrade-reboot
+ cp ${nandwrite_cmd} ${flash_dir}/nandwrite.static
+
+ sync
+ sleep 2
+ mount -o remount,ro ${flash_root}
+
+ # flash_root is not going to be umounted
+ sed -i -e "\\|${flash_root}| d" /etc/mtab
+
+ umount_all
+
+ flash_eraseall -j ${rootfs_mtd}
+ ${flash_dir}/nandwrite.static ${rootfs_mtd} ${rootfs_file}
+
+ echo "Remember to clean-up ${flash_dir} after reboot"
+ echo ""
+ echo "Rebooting..."
+
+ ${flash_dir}/upgrade-reboot
+
+ # Should not get here normally
+ echo "upgrade-reboot failed"
+ exit 1
+ fi
+}
+
+flash_upgrade /var/volatile
+flash_upgrade /media/card
+
+umount_all
+
+: exit 0