summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-09-27 00:09:06 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:09:04 +0200
commit21fb5aff39ec63ae7c69b02d26e694f07016816f (patch)
treea7d7be7fc625f60505c867be651c1516b84748c1 /utils
parent2a2800b528010320ca504a39106806ec21f02203 (diff)
downloadrockbox-21fb5aff39ec63ae7c69b02d26e694f07016816f.tar.gz
rockbox-21fb5aff39ec63ae7c69b02d26e694f07016816f.tar.bz2
rockbox-21fb5aff39ec63ae7c69b02d26e694f07016816f.zip
nwztools: rework upg scripts
The exec_file allows to embed a script/executable and run it on target. It takes of unpacking, remounting contents rw and redirect output to exec.txt at the root of the drive. More generally, rework how the makefile works. Change-Id: Iec719227be96e80701ad8f5398d2d34389f4da9e
Diffstat (limited to 'utils')
-rw-r--r--utils/nwztools/scripts/Makefile71
-rw-r--r--utils/nwztools/scripts/README2
-rw-r--r--utils/nwztools/scripts/exec_file.sh62
3 files changed, 117 insertions, 18 deletions
diff --git a/utils/nwztools/scripts/Makefile b/utils/nwztools/scripts/Makefile
index 590fe775ba..36ccfbb496 100644
--- a/utils/nwztools/scripts/Makefile
+++ b/utils/nwztools/scripts/Makefile
@@ -5,36 +5,73 @@ scsitool:="../scsitools/scsitool"
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 "- do_fw_upgrade: put the device in NWZ_DEV in firmware upgrade mode"
+ @echo "- copy_fw_upgrade: copy firmware to a device with the right name"
+ @echo "- exec_file: craft an upgrade that executes a script/executable"
@echo "- list_targets: produce of list of available targets"
-my_update: my_update.upg
-dump_rootfs: dump_rootfs.upg
+ifndef UPG
+want_upg:
+ $(info Please set UPG to the upg filename. For example:)
+ $(info make exec_file UPG=hello_world.upg ...)
+ $(error "")
+else
+want_upg: ;
+endif
+
+ifndef EXEC
+want_exec:
+ $(info Please set EXEC to the executable filename. For example:)
+ $(info make exec_file EXEC=hello_world.sh ...)
+ $(error "")
+else
+want_exec: ;
+endif
-%.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"
+want_target:
+ $(info Please set NWZ_TARGET to your target. For example:)
+ $(info make dump_rootfs NWZ_TARGET=nwz-e463)
+ $(info Run 'make list_targets' to get a list of all targets)
+ $(error "")
else
- @echo "Target: $(NWZ_TARGET)"
- $(upgtool) -c -m $(NWZ_TARGET) $@ $^
+want_target: ;
endif
+ifndef NWZ_DEV
+want_dev:
+ $(info Please set NWZ_DEV to your dev. For example:)
+ $(info make do_fw_upgrade NWZ_DEV=/dev/sdx)
+else
+want_dev: ;
+endif
+
+ifndef NWZ_MOUNT
+want_mount:
+ $(info Please set NWZ_MOUNT to your dev mount point. For example:)
+ $(info make copy_fw_upgrade NWZ_MOUNT=/media/WALKMAN ...)
+else
+want_mount: ;
+endif
+
+UPGPACK=$(upgtool) -c -m $(NWZ_TARGET) $(UPG) $(1)
+
+exec_file: want_target want_exec want_upg
+ $(call UPGPACK, exec_file.sh $(EXEC))
+
+dump_rootfs: want_target want_upg
+ $(call UPGPACK, dump_rootfs.sh)
+
clean:
rm -rf *.upg
list_targets:
$(upgtool) -m ?; true # upgtool returns an error in this case, ignore it
-do_fw_upgrade:
-ifdef NWZ_DEV
+copy_fw_upgrade: want_upg want_mount
+ cp $(UPG) "$(NWZ_MOUNT)/NW_WM_FW.UPG"
+
+do_fw_upgrade: want_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
index e103647bd6..1744fbe9fe 100644
--- a/utils/nwztools/scripts/README
+++ b/utils/nwztools/scripts/README
@@ -46,7 +46,7 @@ your device to build this firmware upgrade. Once you known it, run
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
+ make dump_rootfs NWZ_TARGET=nwz-exyz UPG=dump_rootfs.upg
(replace nwz-exyz with your target)
This command will produce a firmware upgrade file called
dump_rootfs.upg
diff --git a/utils/nwztools/scripts/exec_file.sh b/utils/nwztools/scripts/exec_file.sh
new file mode 100644
index 0000000000..059014de2c
--- /dev/null
+++ b/utils/nwztools/scripts/exec_file.sh
@@ -0,0 +1,62 @@
+#!/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 extracts the second file from the UPG to /tmp and runs it
+#
+
+
+# go to /tmp
+cd /tmp
+
+# get content partition path
+CONTENTS="/contents"
+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
+then
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed"
+ sleep 3
+ exit 0
+fi
+
+# get update filename
+_UPDATE_FN_=`nvpstr ufn`
+
+# extract second file
+fwpchk -f /contents/$_UPDATE_FN_.UPG -c -1 exec
+if [ "$?" != 0 ]; then
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: no file to execute"
+ sleep 3
+ exit 0
+fi
+
+# make it executable
+chmod 755 exec
+if [ "$?" != 0 ]; then
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: cannot make it executable"
+ sleep 3
+ exit 0
+fi
+
+# run it and redirect all outputs to exec.txt
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..."
+/tmp/exec 2>&1 >$CONTENTS/exec.txt
+
+# 4) Success screen
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds."
+sleep 3
+sync
+
+# finish
+exit 0