diff options
-rw-r--r-- | utils/nwztools/scripts/Makefile | 40 | ||||
-rw-r--r-- | utils/nwztools/scripts/README | 59 | ||||
-rw-r--r-- | utils/nwztools/scripts/dump_rootfs.sh | 83 | ||||
-rw-r--r-- | utils/nwztools/upgtools/upgtool.c | 24 |
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 @@ | |||
1 | upgtool:="../upgtools/upgtool" | ||
2 | scsitool:="../scsitools/scsitool" | ||
3 | |||
4 | .SUFFIXES: # disable old suffix rules | ||
5 | |||
6 | all: | ||
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 | |||
14 | my_update: my_update.upg | ||
15 | dump_rootfs: dump_rootfs.upg | ||
16 | |||
17 | %.upg: %.sh | ||
18 | ifndef 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" | ||
22 | else | ||
23 | @echo "Target: $(NWZ_TARGET)" | ||
24 | $(upgtool) -c -m $(NWZ_TARGET) $@ $^ | ||
25 | endif | ||
26 | |||
27 | clean: | ||
28 | rm -rf *.UPG | ||
29 | |||
30 | list_targets: | ||
31 | $(upgtool) -m ?; true # upgtool returns an error in this case, ignore it | ||
32 | |||
33 | do_fw_upgrade: | ||
34 | ifdef NWZ_DEV | ||
35 | @echo "Device: $(NWZ_DEV)" | ||
36 | $(scsitool) $(NWZ_DEV) do_fw_upgrade | ||
37 | else | ||
38 | @echo "Please set NWZ_DEV to your dev. For example:" | ||
39 | @echo "make do_fw_upgrade NWZ_DEV=/dev/sdx" | ||
40 | endif | ||
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 @@ | |||
1 | This directory contains various scripts that can be used to help development | ||
2 | process on the Sony NWZ players. The proper way to use it is to use the Makefile. | ||
3 | |||
4 | In case of doubt, run | ||
5 | make | ||
6 | to get the up-to-date documentation. | ||
7 | |||
8 | ***************************** | ||
9 | Performing a firmware upgrade | ||
10 | ***************************** | ||
11 | |||
12 | To perform a firmware upgrade, first copy the firmware upgrade file to the root of | ||
13 | the device, and make sure its named | ||
14 | NW_WM_FW.UPG | ||
15 | Another other name WILL NOT WORK. You've been warned. | ||
16 | |||
17 | DO NOT FORGET TO UNMOUNT YOUR DEVICE PROPERLY BEFORE DOING WHAT FOLLOWS | ||
18 | |||
19 | Once once, you need to tell the device to reboot in firmware upgrade mode. | ||
20 | At the moment, we only support this operation in UMS/MSC (Mass Storage) mode. So if | ||
21 | your device appears as a MTP device, go to the preference settings of your device | ||
22 | and make sure your device is set to UMS/MSC or Auto. | ||
23 | You need to identify the linux device associated with your device. There are | ||
24 | plenty of tutorials on the net on how to do that, you can use mount or dmesg. | ||
25 | Assuming the linux device corresponding to your player is | ||
26 | /dev/sdx | ||
27 | run AS ROOT OR USING SUDO | ||
28 | make do_fw_upgrade NWZ_DEV=/dev/sdx | ||
29 | |||
30 | If everything goes well, the device should reboot and perform the firmware upgrade. | ||
31 | |||
32 | ******************************** | ||
33 | Building a firmware upgrade that | ||
34 | dumps important stuff | ||
35 | ******************************** | ||
36 | |||
37 | In early development stage, the most useful thing you can do is to dump important | ||
38 | stuff from your device: | ||
39 | - dmesg and mount output | ||
40 | - FU (firmware upgrade) initrd | ||
41 | - root FS (file system) | ||
42 | We carefully wrote a script that does the following. First make sure that your device | ||
43 | has enough free space (at least 300MB to be safe). You need to know the model of | ||
44 | your device to build this firmware upgrade. Once you known it, run | ||
45 | make list_targets | ||
46 | to list all available targets. For example if your targets is one of the | ||
47 | NWZ-E460 series, the corresponding target is nwz-e46x. | ||
48 | Once you have identified the target. Run | ||
49 | make dump_rootfs NWZ_TARGET=nwz-exyz | ||
50 | (replace nwz-exyz with your target) | ||
51 | This command will produce a firmware upgrade file called | ||
52 | dump_rootfs.upg | ||
53 | |||
54 | In order to run this firmware upgrade, you need to follows the instruction | ||
55 | on how to perform a firmware upgrade. | ||
56 | |||
57 | When performing the firmware upgrade, the script will perform various operation | ||
58 | and create several files. Once the "upgrade" is finish and the device has rebooted, | ||
59 | you 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 | ||
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 | ||
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 | ||
61 | static 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 | |||
79 | static void usage(void); | 61 | static void usage(void); |
80 | 62 | ||
81 | /* key and signature */ | 63 | /* key and signature */ |
@@ -118,8 +100,10 @@ struct upg_entry_t | |||
118 | 100 | ||
119 | struct nwz_model_t g_model_list[] = | 101 | struct 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 | ||