#!/bin/sh
#
# workaround SD card mount over suspend corruption
# (c)2008 OpenMoko, Inc  Author: Andy Green <andy@openmoko.com>
#
# Perform necessary insane hack/magic to 
#
#  - copy /bin and /lib to /tmp
#  - pivot_root into it
#  - drop SD card rootfs
#  - create nodes for mmcblk1 (somehow 0 is not freed)
#  - suspend
#  - on resume, remount mmcblk1p2 and pivot_root back into it
#  - bring back /proc and /sysfs
#  - OK the rootfs from SD card is back
#
# You have to close any handles to SD card filesystem before
# calling because it will forcibly umount /

rsync -a /bin /tmp 2>/dev/null ; \
rsync -a /lib /tmp 2>/dev/null ; \
mkdir /tmp/mnt ; \
pivot_root /tmp /tmp/mnt ; \
mkdir /tmp /etc /proc /sys ; \
mount -tproc proc /proc ; \
mount -tsysfs sysfs /sys ; \
mknod mmcblk1 b 179 8 ; \
mknod mmcblk1p1 b 179 9 ; \
mknod mmcblk1p2 b 179 10 ; \
umount -l /mnt ; \
echo mem >/sys/power/state ; \
bin/dropbear ; \
mount mmcblk1p2 /tmp -orw ; \
/tmp/sbin/pivot_root /tmp /tmp/tmp ; \
mount -tproc proc /proc ; \
mount -tsysfs sysfs /sys ; \
mkdir tmp; \
mv log tmp/; \
