summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:02:41 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:09:04 +0200
commit13d892eef1c78d14314b7d3a2cb9035e9ba1420c (patch)
treefdd330f4f0d5a1d317b63ac2faca1255c1c6e8b5
parenteaa1cb3469c1abef0433c1a23102b53d59e47814 (diff)
downloadrockbox-13d892e.tar.gz
rockbox-13d892e.zip
nwztools: update makefile and add script
The new script allows the upgrade to execute a file found on the user partition. Change-Id: I564941d01bcdbae050002e77cb119f3d95ecdc21
-rw-r--r--utils/nwztools/scripts/Makefile22
-rw-r--r--utils/nwztools/scripts/exec_file.sh2
-rw-r--r--utils/nwztools/scripts/exec_file_extern.sh.in54
3 files changed, 76 insertions, 2 deletions
diff --git a/utils/nwztools/scripts/Makefile b/utils/nwztools/scripts/Makefile
index 36ccfbb496..207534a006 100644
--- a/utils/nwztools/scripts/Makefile
+++ b/utils/nwztools/scripts/Makefile
@@ -8,7 +8,8 @@ all:
@echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz"
@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 "- exec_file: craft an upgrade that embeds and execute a file"
+ @echo "- exec_file_extern: craft an upgrade that execute a file on the user partition"
@echo "- list_targets: produce of list of available targets"
ifndef UPG
@@ -43,6 +44,7 @@ ifndef NWZ_DEV
want_dev:
$(info Please set NWZ_DEV to your dev. For example:)
$(info make do_fw_upgrade NWZ_DEV=/dev/sdx)
+ $(error "")
else
want_dev: ;
endif
@@ -51,15 +53,33 @@ 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 ...)
+ $(error "")
else
want_mount: ;
endif
+ifndef LOG
+want_log:
+ $(info Please set LOG to the log filename. For example:)
+ $(info make exec_file_extern LOG=exec.log ...)
+ $(error "")
+else
+want_log: ;
+endif
+
UPGPACK=$(upgtool) -c -m $(NWZ_TARGET) $(UPG) $(1)
exec_file: want_target want_exec want_upg
$(call UPGPACK, exec_file.sh $(EXEC))
+exec_file_extern.tmp: want_exec want_upg want_log
+ cat exec_file_extern.sh.in | sed "s|NWZ_EXEC_THIS|$(EXEC)|" |\
+ sed "s|NWZ_LOG_THIS|$(LOG)|" > $@
+.INTERMEDIATE: exec_file_extern.tmp
+
+exec_file_extern: want_target want_exec want_upg want_log exec_file_extern.tmp
+ $(call UPGPACK, exec_file_extern.tmp)
+
dump_rootfs: want_target want_upg
$(call UPGPACK, dump_rootfs.sh)
diff --git a/utils/nwztools/scripts/exec_file.sh b/utils/nwztools/scripts/exec_file.sh
index 059014de2c..368909123f 100644
--- a/utils/nwztools/scripts/exec_file.sh
+++ b/utils/nwztools/scripts/exec_file.sh
@@ -51,7 +51,7 @@ 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
+/tmp/exec >$CONTENTS/exec.txt 2>&1
# 4) Success screen
lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds."
diff --git a/utils/nwztools/scripts/exec_file_extern.sh.in b/utils/nwztools/scripts/exec_file_extern.sh.in
new file mode 100644
index 0000000000..c4413baae4
--- /dev/null
+++ b/utils/nwztools/scripts/exec_file_extern.sh.in
@@ -0,0 +1,54 @@
+#!/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 remounts the user (aka contents) partition read-write-exec and
+# runs the file given and redirects its output and error to a file.
+# To use this file, you need to replace NWZ_EXEC_THIS by the file you want to
+# execute and NWZ_LOG_THIS by the name of the file you want to log to. You may
+# use sed as follows for this purpose:
+# cat exec_file_extern.sh.in | sed 's|NWZ_EXEC_THIS|myfile.elf|' | \
+# sed 's|NWZ_LOG_THIS|exec.log|' > my_exec_file.sh
+#
+# NOTE 1: technically, NWZ_EXEC_THIS can be any command, not just a file
+# NOTE 2: this script will export the variable NWZ_CONTENTS that is the path to
+# the user partition, so that if NWZ_EXEC_THIS is a bash script, it can
+# easily use 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 and exec"
+if ! mount -o remount,rw,umask=000 $CONTENTS_PART $CONTENTS
+then
+ lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed"
+ sleep 3
+ exit 0
+fi
+
+# run file and redirect all outputs
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..."
+export NWZ_CONTENTS="$CONTENTS"
+$CONTENTS/NWZ_EXEC_THIS >$CONTENTS/NWZ_LOG_THIS 2>&1
+
+# 4) Success screen
+lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds."
+sleep 3
+sync
+
+# finish
+exit 0