blob: 2adfe8e335d26e666483346ec957a06a324a9472 [file]
#!/bin/sh
if test -c /dev/watchdog; then
watchdog -t 1 -T 15 -F /dev/watchdog &
wdpid=$!
fi
# Unmount all of the old SPI flash mountpoints
while read -r mnt; do
umount -f "$mnt" || true
done < <(awk '{print $2}' /proc/mounts | grep '^/oldroot' | sort -r)
get_mtd() {
grep '"'"$1"'"$' /proc/mtd | sed 's,:.*,,'
}
flash_bmc() {
local rwdev
rwdev=/dev/$(get_mtd rwfs) || return
local bmcdev
bmcdev=/dev/$(get_mtd bmc) || return
# Store the old RWFS
echo '### Reading old RWFS' >&2
flasher read mtd,"$rwdev" oldrwfs || return
# This script is only invoked with an image present, so always flash it
echo '### Writing new Image' >&2
flasher auto image-bmc mtd,"$bmcdev" || true
# Write the old RWFS back
echo '### Writing old RWFS' >&2
flasher auto oldrwfs mtd,"$rwdev" || true
}
if [ -e image-bmc ]; then
flash_bmc
fi
# Drain all remaining messages to the console
test -t 1 && stty cooked 0<&1
echo '### Remaining mounts:'
cat /proc/mounts
if [ -e do_powercycle.sh ]; then
echo '### Triggering Powercycle' >&2
sh do_powercycle.sh
sleep 10
echo '### Powercycle probably failed' >&2
fi
kill $wdpid
exe=/bin/"${1-reboot}"
if test -e "$exe"; then
"$exe" -f
fi
echo "### Failed to find / execute $exe, rebooting" >&2
reboot -f