path: root/utils/nwztools/scripts
diff options
authorAmaury Pouly <>2016-08-17 21:26:12 +0100
committerAmaury Pouly <>2016-08-17 21:26:31 +0100
commit9d121cfd51185b21be6551be2599bf2edcc8fe40 (patch)
treeefccca6e5624261d0b1c82781d6940b8151dbea7 /utils/nwztools/scripts
parent3db0363b7870f37bc622c7fe431d8a700440d0df (diff)
nwztools: upgrade upgtools and add dumping script
Change-Id: I315d1010ce5477c0112f4a890156b360e8123e11
Diffstat (limited to 'utils/nwztools/scripts')
3 files changed, 182 insertions, 0 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 @@
+.SUFFIXES: # disable old suffix rules
+ @echo "Please select an action:"
+ @echo "- update: uses script"
+ @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz"
+ @echo "- my_update: craft an arbitrary upgrade script found in"
+ @echo "- do_fw_upgrade: send a firmware upgrade to the device in NWZ_DEV"
+ @echo "- list_targets: produce of list of available targets"
+my_update: my_update.upg
+dump_rootfs: dump_rootfs.upg
+ifndef NWZ_TARGET
+ @echo "Please set NWZ_TARGET to your target. For example:"
+ @echo "make $@ NWZ_TARGET=nwz-e463"
+ @echo "Run 'make list_targets' to get a list of all targets"
+ @echo "Target: $(NWZ_TARGET)"
+ $(upgtool) -c -m $(NWZ_TARGET) $@ $^
+ rm -rf *.UPG
+ $(upgtool) -m ?; true # upgtool returns an error in this case, ignore it
+ifdef NWZ_DEV
+ @echo "Device: $(NWZ_DEV)"
+ $(scsitool) $(NWZ_DEV) do_fw_upgrade
+ @echo "Please set NWZ_DEV to your dev. For example:"
+ @echo "make do_fw_upgrade NWZ_DEV=/dev/sdx"
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 @@
+This directory contains various scripts that can be used to help development
+process on the Sony NWZ players. The proper way to use it is to use the Makefile.
+In case of doubt, run
+ make
+to get the up-to-date documentation.
+Performing a firmware upgrade
+To perform a firmware upgrade, first copy the firmware upgrade file to the root of
+the device, and make sure its named
+Another other name WILL NOT WORK. You've been warned.
+Once once, you need to tell the device to reboot in firmware upgrade mode.
+At the moment, we only support this operation in UMS/MSC (Mass Storage) mode. So if
+your device appears as a MTP device, go to the preference settings of your device
+and make sure your device is set to UMS/MSC or Auto.
+You need to identify the linux device associated with your device. There are
+plenty of tutorials on the net on how to do that, you can use mount or dmesg.
+Assuming the linux device corresponding to your player is
+ /dev/sdx
+ make do_fw_upgrade NWZ_DEV=/dev/sdx
+If everything goes well, the device should reboot and perform the firmware upgrade.
+Building a firmware upgrade that
+dumps important stuff
+In early development stage, the most useful thing you can do is to dump important
+stuff from your device:
+- dmesg and mount output
+- FU (firmware upgrade) initrd
+- root FS (file system)
+We carefully wrote a script that does the following. First make sure that your device
+has enough free space (at least 300MB to be safe). You need to know the model of
+your device to build this firmware upgrade. Once you known it, run
+ make list_targets
+to list all available targets. For example if your targets is one of the
+NWZ-E460 series, the corresponding target is nwz-e46x.
+Once you have identified the target. Run
+ make dump_rootfs NWZ_TARGET=nwz-exyz
+(replace nwz-exyz with your target)
+This command will produce a firmware upgrade file called
+ dump_rootfs.upg
+In order to run this firmware upgrade, you need to follows the instruction
+on how to perform a firmware upgrade.
+When performing the firmware upgrade, the script will perform various operation
+and create several files. Once the "upgrade" is finish and the device has rebooted,
+you should find the files in the dump_rootfs/ directory at the root of your device.
diff --git a/utils/nwztools/scripts/ b/utils/nwztools/scripts/
new file mode 100644
index 0000000000..da20e43b41
--- /dev/null
+++ b/utils/nwztools/scripts/
@@ -0,0 +1,83 @@
+# The updater script on the NWZ has a major bug/feature:
+# it does NOT clear the update flag if the update scrit fails
+# thus causing a update/reboot loop and a bricked device
+# always clear to make sure we don't end up being screwed
+nvpflag fup 0xFFFFFFFF
+# This script dumps the root filesystem of the device and saves the resulting
+# in rootfs.tgz in the user partition.
+# 1) First we need to detect what is the user (aka contents) device. It is mounted
+# read-only at /contents during upgrade and the device is usually /dev/contents_part
+# The output of mount will look like this:
+# /dev/contents_part on /contents type ....
+CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'`
+lcdmsg -c -f /usr/local/bin/font_08x12.bmp -l 0,3 "Contents partition:\n$CONTENTS_PART"
+# 2) We need to remount the contents partition in read-write mode be able to
+# write something on it
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw"
+if ! mount -o remount,rw $CONTENTS_PART $CONTENTS
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed"
+ sleep 10
+ exit 0
+# 3) Dump various files
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,8 "Dumping various files"
+mkdir -p "$DUMP_DIR"
+mount 2>&1 >$DUMP_DIR/mount.txt
+dmesg 2>&1 >$DUMP_DIR/dmesg.txt
+mmcinfo map 2>&1 >$DUMP_DIR/mmcinfo_map.txt
+sysinfo 2>&1 >$DUMP_DIR/sysinfo.txt
+# 4) Dump / (which is the FU initrd)
+# Don't forget to exclude contents, that would be useless
+# NOTE: this code assumes that CONTENTS is always at the root: /contents
+# NOTE: also exclude /sys because it makes tar stop earlier
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,9 "Dumping FU initrd..."
+for entry in /*
+ # exclude contents
+ if [ "$entry" != "$CONTENTS" -a "$entry" != "/sys" ]
+ then
+ LIST="$LIST $entry"
+ fi
+tar -cf $DUMP_DIR/fu_initrd.tar $LIST
+find / > $DUMP_DIR/fu_initrd.list
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,10 "Done."
+# 5) Dump the root filesystem
+# Mount the root filesystem read-only and dump it
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,12 "Dumping rootfs..."
+. /install_script/constant.txt
+if ! mount -t ext2 -o ro $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,13 "ERROR: cannot mount rootfs"
+ tar -cf $DUMP_DIR/rootfs.tar $ROOTFS_TMP_DIR
+ umount $ROOTFS_TMP_DIR
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,13 "Done."
+# 4) Success screen
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 10 seconds."
+sleep 10
+exit 0