summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-08-17 21:26:12 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2016-08-17 21:26:31 +0100
commit9d121cfd51185b21be6551be2599bf2edcc8fe40 (patch)
treeefccca6e5624261d0b1c82781d6940b8151dbea7 /utils
parent3db0363b7870f37bc622c7fe431d8a700440d0df (diff)
downloadrockbox-9d121cfd51185b21be6551be2599bf2edcc8fe40.tar.gz
rockbox-9d121cfd51185b21be6551be2599bf2edcc8fe40.zip
nwztools: upgrade upgtools and add dumping script
Change-Id: I315d1010ce5477c0112f4a890156b360e8123e11
Diffstat (limited to 'utils')
-rw-r--r--utils/nwztools/scripts/Makefile40
-rw-r--r--utils/nwztools/scripts/README59
-rw-r--r--utils/nwztools/scripts/dump_rootfs.sh83
-rw-r--r--utils/nwztools/upgtools/upgtool.c24
4 files changed, 186 insertions, 20 deletions
diff --git a/utils/nwztools/scripts/Makefile b/utils/nwztools/scripts/Makefile
new file mode 100644
index 0000000000..ed6e725291
--- /dev/null
+++ b/utils/nwztools/scripts/Makefile
@@ -0,0 +1,40 @@
1upgtool:="../upgtools/upgtool"
2scsitool:="../scsitools/scsitool"
3
4.SUFFIXES: # disable old suffix rules
5
6all:
7 @echo "Please select an action:"
8 @echo "- update: uses script update.sh"
9 @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz"
10 @echo "- my_update: craft an arbitrary upgrade script found in my_update.sh"
11 @echo "- do_fw_upgrade: send a firmware upgrade to the device in NWZ_DEV"
12 @echo "- list_targets: produce of list of available targets"
13
14my_update: my_update.upg
15dump_rootfs: dump_rootfs.upg
16
17%.upg: %.sh
18ifndef NWZ_TARGET
19 @echo "Please set NWZ_TARGET to your target. For example:"
20 @echo "make $@ NWZ_TARGET=nwz-e463"
21 @echo "Run 'make list_targets' to get a list of all targets"
22else
23 @echo "Target: $(NWZ_TARGET)"
24 $(upgtool) -c -m $(NWZ_TARGET) $@ $^
25endif
26
27clean:
28 rm -rf *.UPG
29
30list_targets:
31 $(upgtool) -m ?; true # upgtool returns an error in this case, ignore it
32
33do_fw_upgrade:
34ifdef NWZ_DEV
35 @echo "Device: $(NWZ_DEV)"
36 $(scsitool) $(NWZ_DEV) do_fw_upgrade
37else
38 @echo "Please set NWZ_DEV to your dev. For example:"
39 @echo "make do_fw_upgrade NWZ_DEV=/dev/sdx"
40endif
diff --git a/utils/nwztools/scripts/README b/utils/nwztools/scripts/README
new file mode 100644
index 0000000000..e103647bd6
--- /dev/null
+++ b/utils/nwztools/scripts/README
@@ -0,0 +1,59 @@
1This directory contains various scripts that can be used to help development
2process on the Sony NWZ players. The proper way to use it is to use the Makefile.
3
4In case of doubt, run
5 make
6to get the up-to-date documentation.
7
8*****************************
9Performing a firmware upgrade
10*****************************
11
12To perform a firmware upgrade, first copy the firmware upgrade file to the root of
13the device, and make sure its named
14 NW_WM_FW.UPG
15Another other name WILL NOT WORK. You've been warned.
16
17DO NOT FORGET TO UNMOUNT YOUR DEVICE PROPERLY BEFORE DOING WHAT FOLLOWS
18
19Once once, you need to tell the device to reboot in firmware upgrade mode.
20At the moment, we only support this operation in UMS/MSC (Mass Storage) mode. So if
21your device appears as a MTP device, go to the preference settings of your device
22and make sure your device is set to UMS/MSC or Auto.
23You need to identify the linux device associated with your device. There are
24plenty of tutorials on the net on how to do that, you can use mount or dmesg.
25Assuming the linux device corresponding to your player is
26 /dev/sdx
27run AS ROOT OR USING SUDO
28 make do_fw_upgrade NWZ_DEV=/dev/sdx
29
30If everything goes well, the device should reboot and perform the firmware upgrade.
31
32********************************
33Building a firmware upgrade that
34dumps important stuff
35********************************
36
37In early development stage, the most useful thing you can do is to dump important
38stuff from your device:
39- dmesg and mount output
40- FU (firmware upgrade) initrd
41- root FS (file system)
42We carefully wrote a script that does the following. First make sure that your device
43has enough free space (at least 300MB to be safe). You need to know the model of
44your device to build this firmware upgrade. Once you known it, run
45 make list_targets
46to list all available targets. For example if your targets is one of the
47NWZ-E460 series, the corresponding target is nwz-e46x.
48Once you have identified the target. Run
49 make dump_rootfs NWZ_TARGET=nwz-exyz
50(replace nwz-exyz with your target)
51This command will produce a firmware upgrade file called
52 dump_rootfs.upg
53
54In order to run this firmware upgrade, you need to follows the instruction
55on how to perform a firmware upgrade.
56
57When performing the firmware upgrade, the script will perform various operation
58and create several files. Once the "upgrade" is finish and the device has rebooted,
59you should find the files in the dump_rootfs/ directory at the root of your device.
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
diff --git a/utils/nwztools/upgtools/upgtool.c b/utils/nwztools/upgtools/upgtool.c
index 54bbbf3270..4f8cddad82 100644
--- a/utils/nwztools/upgtools/upgtool.c
+++ b/utils/nwztools/upgtools/upgtool.c
@@ -58,24 +58,6 @@ enum keysig_search_method_t g_keysig_search = KEYSIG_SEARCH_NONE;
58 { cprintf(RED, str_bad); let_the_force_flow(__LINE__); } \ 58 { cprintf(RED, str_bad); let_the_force_flow(__LINE__); } \
59 else { cprintf(RED, str_ok); } 59 else { cprintf(RED, str_ok); }
60 60
61static void print_hex(void *p, int size, int unit)
62{
63 uint8_t *p8 = p;
64 uint16_t *p16 = p;
65 uint32_t *p32 = p;
66 for(int i = 0; i < size; i += unit, p8++, p16++, p32++)
67 {
68 if(i != 0 && (i % 16) == 0)
69 printf("\n");
70 if(unit == 1)
71 printf(" %02x", *p8);
72 else if(unit == 2)
73 printf(" %04x", *p16);
74 else
75 printf(" %08x", *p32);
76 }
77}
78
79static void usage(void); 61static void usage(void);
80 62
81/* key and signature */ 63/* key and signature */
@@ -118,8 +100,10 @@ struct upg_entry_t
118 100
119struct nwz_model_t g_model_list[] = 101struct nwz_model_t g_model_list[] =
120{ 102{
121 { "nwz-e463", HAS_KAS | HAS_KEY | HAS_SIG | CONFIRMED, {"89d813f8f966efdebd9c9e0ea98156d2"}, "eb4431eb", "4f1d9cac" }, 103 { "nwz-e46x", HAS_KAS | HAS_KEY | HAS_SIG | CONFIRMED, {"89d813f8f966efdebd9c9e0ea98156d2"}, "eb4431eb", "4f1d9cac" },
122 { "nwz-a86x", HAS_KEY | HAS_SIG, {""}, "c824e4e2", "7c262bb0" }, 104 { "nwz-a86x", HAS_KAS | HAS_KEY | HAS_SIG | CONFIRMED, {"a7c4af6c28b8900a783f307c1ba538c5"}, "c824e4e2", "7c262bb0" },
105 /* The following keys were obtained by brute forcing firmware upgrades,
106 * someone with a device needs to confirm that they work */
123 { "nw-a82x", HAS_KEY | HAS_SIG, {""}, "4df06482", "07fa0b6e" }, 107 { "nw-a82x", HAS_KEY | HAS_SIG, {""}, "4df06482", "07fa0b6e" },
124}; 108};
125 109