diff options
Diffstat (limited to 'utils/nwztools/scripts')
| -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 |
3 files changed, 182 insertions, 0 deletions
diff --git a/utils/nwztools/scripts/Makefile b/utils/nwztools/scripts/Makefile new file mode 100644 index 0000000..ed6e725 --- /dev/null +++ b/utils/nwztools/scripts/Makefile @@ -0,0 +1,40 @@ +upgtool:="../upgtools/upgtool" +scsitool:="../scsitools/scsitool" + +.SUFFIXES: # disable old suffix rules + +all: + @echo "Please select an action:" + @echo "- update: uses script update.sh" + @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz" + @echo "- my_update: craft an arbitrary upgrade script found in my_update.sh" + @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 + +%.upg: %.sh +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" +else + @echo "Target: $(NWZ_TARGET)" + $(upgtool) -c -m $(NWZ_TARGET) $@ $^ +endif + +clean: + rm -rf *.UPG + +list_targets: + $(upgtool) -m ?; true # upgtool returns an error in this case, ignore it + +do_fw_upgrade: +ifdef NWZ_DEV + @echo "Device: $(NWZ_DEV)" + $(scsitool) $(NWZ_DEV) do_fw_upgrade +else + @echo "Please set NWZ_DEV to your dev. For example:" + @echo "make do_fw_upgrade NWZ_DEV=/dev/sdx" +endif diff --git a/utils/nwztools/scripts/README b/utils/nwztools/scripts/README new file mode 100644 index 0000000..e103647 --- /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 + NW_WM_FW.UPG +Another other name WILL NOT WORK. You've been warned. + +DO NOT FORGET TO UNMOUNT YOUR DEVICE PROPERLY BEFORE DOING WHAT FOLLOWS + +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 +run AS ROOT OR USING SUDO + 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/dump_rootfs.sh b/utils/nwztools/scripts/dump_rootfs.sh new file mode 100644 index 0000000..da20e43 --- /dev/null +++ b/utils/nwztools/scripts/dump_rootfs.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# 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="/contents" +CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'` +DUMP_DIR="$CONTENTS/dump_rootfs" + +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 +then + lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed" + sleep 10 + exit 0 +fi + +# 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..." +LIST="" +for entry in /* +do + # exclude contents + if [ "$entry" != "$CONTENTS" -a "$entry" != "/sys" ] + then + LIST="$LIST $entry" + fi +done +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..." +ROOTFS_TMP_DIR=/tmp/rootfs +mkdir $ROOTFS_TMP_DIR +. /install_script/constant.txt +if ! mount -t ext2 -o ro $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR +then + lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,13 "ERROR: cannot mount rootfs" +else + 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." +fi + +# 4) Success screen +lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 10 seconds." + +sleep 10 + +sync + +exit 0 |