summaryrefslogtreecommitdiff
path: root/utils/nwztools/scripts/dump_rootfs.sh
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/scripts/dump_rootfs.sh')
-rw-r--r--utils/nwztools/scripts/dump_rootfs.sh83
1 files changed, 83 insertions, 0 deletions
diff --git a/utils/nwztools/scripts/dump_rootfs.sh b/utils/nwztools/scripts/dump_rootfs.sh
new file mode 100644
index 0000000000..da20e43b41
--- /dev/null
+++ b/utils/nwztools/scripts/dump_rootfs.sh
@@ -0,0 +1,83 @@
1#!/bin/sh
2
3# The updater script on the NWZ has a major bug/feature:
4# it does NOT clear the update flag if the update scrit fails
5# thus causing a update/reboot loop and a bricked device
6# always clear to make sure we don't end up being screwed
7nvpflag fup 0xFFFFFFFF
8
9#
10# This script dumps the root filesystem of the device and saves the resulting
11# in rootfs.tgz in the user partition.
12#
13
14# 1) First we need to detect what is the user (aka contents) device. It is mounted
15# read-only at /contents during upgrade and the device is usually /dev/contents_part
16# The output of mount will look like this:
17# /dev/contents_part on /contents type ....
18CONTENTS="/contents"
19CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'`
20DUMP_DIR="$CONTENTS/dump_rootfs"
21
22lcdmsg -c -f /usr/local/bin/font_08x12.bmp -l 0,3 "Contents partition:\n$CONTENTS_PART"
23
24# 2) We need to remount the contents partition in read-write mode be able to
25# write something on it
26lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw"
27if ! mount -o remount,rw $CONTENTS_PART $CONTENTS
28then
29 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed"
30 sleep 10
31 exit 0
32fi
33
34# 3) Dump various files
35lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,8 "Dumping various files"
36
37mkdir -p "$DUMP_DIR"
38mount 2>&1 >$DUMP_DIR/mount.txt
39dmesg 2>&1 >$DUMP_DIR/dmesg.txt
40mmcinfo map 2>&1 >$DUMP_DIR/mmcinfo_map.txt
41sysinfo 2>&1 >$DUMP_DIR/sysinfo.txt
42
43# 4) Dump / (which is the FU initrd)
44# Don't forget to exclude contents, that would be useless
45# NOTE: this code assumes that CONTENTS is always at the root: /contents
46# NOTE: also exclude /sys because it makes tar stop earlier
47lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,9 "Dumping FU initrd..."
48LIST=""
49for entry in /*
50do
51 # exclude contents
52 if [ "$entry" != "$CONTENTS" -a "$entry" != "/sys" ]
53 then
54 LIST="$LIST $entry"
55 fi
56done
57tar -cf $DUMP_DIR/fu_initrd.tar $LIST
58find / > $DUMP_DIR/fu_initrd.list
59lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,10 "Done."
60
61# 5) Dump the root filesystem
62# Mount the root filesystem read-only and dump it
63lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,12 "Dumping rootfs..."
64ROOTFS_TMP_DIR=/tmp/rootfs
65mkdir $ROOTFS_TMP_DIR
66. /install_script/constant.txt
67if ! mount -t ext2 -o ro $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
68then
69 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,13 "ERROR: cannot mount rootfs"
70else
71 tar -cf $DUMP_DIR/rootfs.tar $ROOTFS_TMP_DIR
72 umount $ROOTFS_TMP_DIR
73 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,13 "Done."
74fi
75
76# 4) Success screen
77lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 10 seconds."
78
79sleep 10
80
81sync
82
83exit 0