diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2016-09-27 00:09:06 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2016-10-19 17:09:04 +0200 |
commit | 21fb5aff39ec63ae7c69b02d26e694f07016816f (patch) | |
tree | a7d7be7fc625f60505c867be651c1516b84748c1 /utils | |
parent | 2a2800b528010320ca504a39106806ec21f02203 (diff) | |
download | rockbox-21fb5aff39ec63ae7c69b02d26e694f07016816f.tar.gz 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/Makefile | 71 | ||||
-rw-r--r-- | utils/nwztools/scripts/README | 2 | ||||
-rw-r--r-- | utils/nwztools/scripts/exec_file.sh | 62 |
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" | |||
5 | 5 | ||
6 | all: | 6 | all: |
7 | @echo "Please select an action:" | 7 | @echo "Please select an action:" |
8 | @echo "- update: uses script update.sh" | ||
9 | @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz" | 8 | @echo "- dump_rootfs: dumps the root filesystem to rootfs.tgz" |
10 | @echo "- my_update: craft an arbitrary upgrade script found in my_update.sh" | 9 | @echo "- do_fw_upgrade: put the device in NWZ_DEV in firmware upgrade mode" |
11 | @echo "- do_fw_upgrade: send a firmware upgrade to the device in NWZ_DEV" | 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" | ||
12 | @echo "- list_targets: produce of list of available targets" | 12 | @echo "- list_targets: produce of list of available targets" |
13 | 13 | ||
14 | my_update: my_update.upg | 14 | ifndef UPG |
15 | dump_rootfs: dump_rootfs.upg | 15 | want_upg: |
16 | $(info Please set UPG to the upg filename. For example:) | ||
17 | $(info make exec_file UPG=hello_world.upg ...) | ||
18 | $(error "") | ||
19 | else | ||
20 | want_upg: ; | ||
21 | endif | ||
22 | |||
23 | ifndef EXEC | ||
24 | want_exec: | ||
25 | $(info Please set EXEC to the executable filename. For example:) | ||
26 | $(info make exec_file EXEC=hello_world.sh ...) | ||
27 | $(error "") | ||
28 | else | ||
29 | want_exec: ; | ||
30 | endif | ||
16 | 31 | ||
17 | %.upg: %.sh | ||
18 | ifndef NWZ_TARGET | 32 | ifndef NWZ_TARGET |
19 | @echo "Please set NWZ_TARGET to your target. For example:" | 33 | want_target: |
20 | @echo "make $@ NWZ_TARGET=nwz-e463" | 34 | $(info Please set NWZ_TARGET to your target. For example:) |
21 | @echo "Run 'make list_targets' to get a list of all targets" | 35 | $(info make dump_rootfs NWZ_TARGET=nwz-e463) |
36 | $(info Run 'make list_targets' to get a list of all targets) | ||
37 | $(error "") | ||
22 | else | 38 | else |
23 | @echo "Target: $(NWZ_TARGET)" | 39 | want_target: ; |
24 | $(upgtool) -c -m $(NWZ_TARGET) $@ $^ | ||
25 | endif | 40 | endif |
26 | 41 | ||
42 | ifndef NWZ_DEV | ||
43 | want_dev: | ||
44 | $(info Please set NWZ_DEV to your dev. For example:) | ||
45 | $(info make do_fw_upgrade NWZ_DEV=/dev/sdx) | ||
46 | else | ||
47 | want_dev: ; | ||
48 | endif | ||
49 | |||
50 | ifndef NWZ_MOUNT | ||
51 | want_mount: | ||
52 | $(info Please set NWZ_MOUNT to your dev mount point. For example:) | ||
53 | $(info make copy_fw_upgrade NWZ_MOUNT=/media/WALKMAN ...) | ||
54 | else | ||
55 | want_mount: ; | ||
56 | endif | ||
57 | |||
58 | UPGPACK=$(upgtool) -c -m $(NWZ_TARGET) $(UPG) $(1) | ||
59 | |||
60 | exec_file: want_target want_exec want_upg | ||
61 | $(call UPGPACK, exec_file.sh $(EXEC)) | ||
62 | |||
63 | dump_rootfs: want_target want_upg | ||
64 | $(call UPGPACK, dump_rootfs.sh) | ||
65 | |||
27 | clean: | 66 | clean: |
28 | rm -rf *.upg | 67 | rm -rf *.upg |
29 | 68 | ||
30 | list_targets: | 69 | list_targets: |
31 | $(upgtool) -m ?; true # upgtool returns an error in this case, ignore it | 70 | $(upgtool) -m ?; true # upgtool returns an error in this case, ignore it |
32 | 71 | ||
33 | do_fw_upgrade: | 72 | copy_fw_upgrade: want_upg want_mount |
34 | ifdef NWZ_DEV | 73 | cp $(UPG) "$(NWZ_MOUNT)/NW_WM_FW.UPG" |
74 | |||
75 | do_fw_upgrade: want_dev | ||
35 | @echo "Device: $(NWZ_DEV)" | 76 | @echo "Device: $(NWZ_DEV)" |
36 | $(scsitool) $(NWZ_DEV) do_fw_upgrade | 77 | $(scsitool) $(NWZ_DEV) do_fw_upgrade |
37 | else | ||
38 | @echo "Please set NWZ_DEV to your dev. For example:" | ||
39 | @echo "make do_fw_upgrade NWZ_DEV=/dev/sdx" | ||
40 | 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 | |||
46 | to list all available targets. For example if your targets is one of the | 46 | to list all available targets. For example if your targets is one of the |
47 | NWZ-E460 series, the corresponding target is nwz-e46x. | 47 | NWZ-E460 series, the corresponding target is nwz-e46x. |
48 | Once you have identified the target. Run | 48 | Once you have identified the target. Run |
49 | make dump_rootfs NWZ_TARGET=nwz-exyz | 49 | make dump_rootfs NWZ_TARGET=nwz-exyz UPG=dump_rootfs.upg |
50 | (replace nwz-exyz with your target) | 50 | (replace nwz-exyz with your target) |
51 | This command will produce a firmware upgrade file called | 51 | This command will produce a firmware upgrade file called |
52 | dump_rootfs.upg | 52 | 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 @@ | |||
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 | ||
7 | nvpflag fup 0xFFFFFFFF | ||
8 | |||
9 | # | ||
10 | # This script extracts the second file from the UPG to /tmp and runs it | ||
11 | # | ||
12 | |||
13 | |||
14 | # go to /tmp | ||
15 | cd /tmp | ||
16 | |||
17 | # get content partition path | ||
18 | CONTENTS="/contents" | ||
19 | CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'` | ||
20 | |||
21 | lcdmsg -c -f /usr/local/bin/font_08x12.bmp -l 0,3 "Contents partition:\n$CONTENTS_PART" | ||
22 | |||
23 | # 2) We need to remount the contents partition in read-write mode be able to | ||
24 | # write something on it | ||
25 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw" | ||
26 | if ! mount -o remount,rw $CONTENTS_PART $CONTENTS | ||
27 | then | ||
28 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed" | ||
29 | sleep 3 | ||
30 | exit 0 | ||
31 | fi | ||
32 | |||
33 | # get update filename | ||
34 | _UPDATE_FN_=`nvpstr ufn` | ||
35 | |||
36 | # extract second file | ||
37 | fwpchk -f /contents/$_UPDATE_FN_.UPG -c -1 exec | ||
38 | if [ "$?" != 0 ]; then | ||
39 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: no file to execute" | ||
40 | sleep 3 | ||
41 | exit 0 | ||
42 | fi | ||
43 | |||
44 | # make it executable | ||
45 | chmod 755 exec | ||
46 | if [ "$?" != 0 ]; then | ||
47 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: cannot make it executable" | ||
48 | sleep 3 | ||
49 | exit 0 | ||
50 | fi | ||
51 | |||
52 | # run it and redirect all outputs to exec.txt | ||
53 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..." | ||
54 | /tmp/exec 2>&1 >$CONTENTS/exec.txt | ||
55 | |||
56 | # 4) Success screen | ||
57 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds." | ||
58 | sleep 3 | ||
59 | sync | ||
60 | |||
61 | # finish | ||
62 | exit 0 | ||