diff options
Diffstat (limited to 'utils/nwztools/scripts/dump_rootfs.sh')
-rw-r--r-- | utils/nwztools/scripts/dump_rootfs.sh | 83 |
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 | ||
7 | nvpflag 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 .... | ||
18 | CONTENTS="/contents" | ||
19 | CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'` | ||
20 | DUMP_DIR="$CONTENTS/dump_rootfs" | ||
21 | |||
22 | lcdmsg -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 | ||
26 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw" | ||
27 | if ! mount -o remount,rw $CONTENTS_PART $CONTENTS | ||
28 | then | ||
29 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed" | ||
30 | sleep 10 | ||
31 | exit 0 | ||
32 | fi | ||
33 | |||
34 | # 3) Dump various files | ||
35 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,8 "Dumping various files" | ||
36 | |||
37 | mkdir -p "$DUMP_DIR" | ||
38 | mount 2>&1 >$DUMP_DIR/mount.txt | ||
39 | dmesg 2>&1 >$DUMP_DIR/dmesg.txt | ||
40 | mmcinfo map 2>&1 >$DUMP_DIR/mmcinfo_map.txt | ||
41 | sysinfo 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 | ||
47 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,9 "Dumping FU initrd..." | ||
48 | LIST="" | ||
49 | for entry in /* | ||
50 | do | ||
51 | # exclude contents | ||
52 | if [ "$entry" != "$CONTENTS" -a "$entry" != "/sys" ] | ||
53 | then | ||
54 | LIST="$LIST $entry" | ||
55 | fi | ||
56 | done | ||
57 | tar -cf $DUMP_DIR/fu_initrd.tar $LIST | ||
58 | find / > $DUMP_DIR/fu_initrd.list | ||
59 | lcdmsg -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 | ||
63 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,12 "Dumping rootfs..." | ||
64 | ROOTFS_TMP_DIR=/tmp/rootfs | ||
65 | mkdir $ROOTFS_TMP_DIR | ||
66 | . /install_script/constant.txt | ||
67 | if ! mount -t ext2 -o ro $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
68 | then | ||
69 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,13 "ERROR: cannot mount rootfs" | ||
70 | else | ||
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." | ||
74 | fi | ||
75 | |||
76 | # 4) Success screen | ||
77 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 10 seconds." | ||
78 | |||
79 | sleep 10 | ||
80 | |||
81 | sync | ||
82 | |||
83 | exit 0 | ||