summaryrefslogtreecommitdiff
path: root/utils/nwztools/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/scripts')
-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:
8 @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz" 8 @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz"
9 @echo "- do_fw_upgrade: put the device in NWZ_DEV in firmware upgrade mode" 9 @echo "- do_fw_upgrade: put the device in NWZ_DEV in firmware upgrade mode"
10 @echo "- copy_fw_upgrade: copy firmware to a device with the right name" 10 @echo "- copy_fw_upgrade: copy firmware to a device with the right name"
11 @echo "- exec_file: craft an upgrade that executes a script/executable" 11 @echo "- exec_file: craft an upgrade that embeds and execute a file"
12 @echo "- exec_file_extern: craft an upgrade that execute a file on the user partition"
12 @echo "- list_targets: produce of list of available targets" 13 @echo "- list_targets: produce of list of available targets"
13 14
14ifndef UPG 15ifndef UPG
@@ -43,6 +44,7 @@ ifndef NWZ_DEV
43want_dev: 44want_dev:
44 $(info Please set NWZ_DEV to your dev. For example:) 45 $(info Please set NWZ_DEV to your dev. For example:)
45 $(info make do_fw_upgrade NWZ_DEV=/dev/sdx) 46 $(info make do_fw_upgrade NWZ_DEV=/dev/sdx)
47 $(error "")
46else 48else
47want_dev: ; 49want_dev: ;
48endif 50endif
@@ -51,15 +53,33 @@ ifndef NWZ_MOUNT
51want_mount: 53want_mount:
52 $(info Please set NWZ_MOUNT to your dev mount point. For example:) 54 $(info Please set NWZ_MOUNT to your dev mount point. For example:)
53 $(info make copy_fw_upgrade NWZ_MOUNT=/media/WALKMAN ...) 55 $(info make copy_fw_upgrade NWZ_MOUNT=/media/WALKMAN ...)
56 $(error "")
54else 57else
55want_mount: ; 58want_mount: ;
56endif 59endif
57 60
61ifndef LOG
62want_log:
63 $(info Please set LOG to the log filename. For example:)
64 $(info make exec_file_extern LOG=exec.log ...)
65 $(error "")
66else
67want_log: ;
68endif
69
58UPGPACK=$(upgtool) -c -m $(NWZ_TARGET) $(UPG) $(1) 70UPGPACK=$(upgtool) -c -m $(NWZ_TARGET) $(UPG) $(1)
59 71
60exec_file: want_target want_exec want_upg 72exec_file: want_target want_exec want_upg
61 $(call UPGPACK, exec_file.sh $(EXEC)) 73 $(call UPGPACK, exec_file.sh $(EXEC))
62 74
75exec_file_extern.tmp: want_exec want_upg want_log
76 cat exec_file_extern.sh.in | sed "s|NWZ_EXEC_THIS|$(EXEC)|" |\
77 sed "s|NWZ_LOG_THIS|$(LOG)|" > $@
78.INTERMEDIATE: exec_file_extern.tmp
79
80exec_file_extern: want_target want_exec want_upg want_log exec_file_extern.tmp
81 $(call UPGPACK, exec_file_extern.tmp)
82
63dump_rootfs: want_target want_upg 83dump_rootfs: want_target want_upg
64 $(call UPGPACK, dump_rootfs.sh) 84 $(call UPGPACK, dump_rootfs.sh)
65 85
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
51 51
52# run it and redirect all outputs to exec.txt 52# run it and redirect all outputs to exec.txt
53lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..." 53lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..."
54/tmp/exec 2>&1 >$CONTENTS/exec.txt 54/tmp/exec >$CONTENTS/exec.txt 2>&1
55 55
56# 4) Success screen 56# 4) Success screen
57lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds." 57lcdmsg -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 @@
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
7nvpflag fup 0xFFFFFFFF
8
9#
10# This script remounts the user (aka contents) partition read-write-exec and
11# runs the file given and redirects its output and error to a file.
12# To use this file, you need to replace NWZ_EXEC_THIS by the file you want to
13# execute and NWZ_LOG_THIS by the name of the file you want to log to. You may
14# use sed as follows for this purpose:
15# cat exec_file_extern.sh.in | sed 's|NWZ_EXEC_THIS|myfile.elf|' | \
16# sed 's|NWZ_LOG_THIS|exec.log|' > my_exec_file.sh
17#
18# NOTE 1: technically, NWZ_EXEC_THIS can be any command, not just a file
19# NOTE 2: this script will export the variable NWZ_CONTENTS that is the path to
20# the user partition, so that if NWZ_EXEC_THIS is a bash script, it can
21# easily use it
22#
23
24# go to /tmp
25cd /tmp
26
27# get content partition path
28CONTENTS="/contents"
29CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'`
30
31lcdmsg -c -f /usr/local/bin/font_08x12.bmp -l 0,3 "Contents partition:\n$CONTENTS_PART"
32
33# 2) We need to remount the contents partition in read-write mode be able to
34# write something on it
35lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw and exec"
36if ! mount -o remount,rw,umask=000 $CONTENTS_PART $CONTENTS
37then
38 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed"
39 sleep 3
40 exit 0
41fi
42
43# run file and redirect all outputs
44lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..."
45export NWZ_CONTENTS="$CONTENTS"
46$CONTENTS/NWZ_EXEC_THIS >$CONTENTS/NWZ_LOG_THIS 2>&1
47
48# 4) Success screen
49lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds."
50sleep 3
51sync
52
53# finish
54exit 0