summaryrefslogtreecommitdiff
path: root/utils/mknwzboot/install_script.sh
diff options
context:
space:
mode:
Diffstat (limited to 'utils/mknwzboot/install_script.sh')
-rw-r--r--utils/mknwzboot/install_script.sh157
1 files changed, 157 insertions, 0 deletions
diff --git a/utils/mknwzboot/install_script.sh b/utils/mknwzboot/install_script.sh
new file mode 100644
index 0000000000..76bd12c4d5
--- /dev/null
+++ b/utils/mknwzboot/install_script.sh
@@ -0,0 +1,157 @@
1#!/bin/sh
2
3# NOTE: busybox is using ash, a very posix and very pedantic shell, make sure
4# you test your scripts with
5# busybox sh -n <script>
6# and if you really, really don't want to download busybox to try it, then go
7# ahead and brick your device
8
9# The updater script on the NWZ has a major bug/feature:
10# it does NOT clear the update flag if the update scrit fails
11# thus causing a update/reboot loop and a bricked device
12# always clear to make sure we don't end up being screwed
13nvpflag fup 0xFFFFFFFF
14
15# go to /tmp
16cd /tmp
17
18# get content partition path
19CONTENTS="/contents"
20CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'`
21
22# print a message to the screen and also on the standard output
23# lcdprint x,y msg
24lcdprint ()
25{
26 echo $2
27 lcdmsg -f /usr/local/bin/font_08x12.bmp -l $1 "$2"
28}
29
30# clear screen
31lcdmsg -c ""
32lcdprint 0,3 "Contents partition:\n$CONTENTS_PART"
33
34# We need to remount the contents partition in read-write mode be able to
35# write something on it
36lcdprint 0,6 "Remount $CONTENTS rw"
37mount -o remount,rw $CONTENTS_PART $CONTENTS
38if [ "$?" != 0 ]; then
39 lcdprint 0,15 "ERROR: remount failed"
40 sleep 3
41 exit 0
42fi
43
44# redirect all output to a log file
45exec > "$CONTENTS/install_dualboot_log.txt" 2>&1
46
47# import constants
48. /install_script/constant.txt
49_UPDATE_FN_=`nvpstr ufn`
50ROOTFS_TMP_DIR=/tmp/rootfs
51SPIDERAPP_PATH=$ROOTFS_TMP_DIR/usr/local/bin/SpiderApp
52
53# mount root partition
54lcdprint 0,7 "Mount root filesystem"
55mkdir $ROOTFS_TMP_DIR
56if [ "$?" != 0 ]; then
57 lcdprint 0,15 "ERROR: mkdir failed"
58 sleep 3
59 exit 0
60fi
61
62# If there is an ext4 mounter, try it. Otherwise or on failure, try ext3 and
63# then ext2.
64# NOTE some platforms probably use an mtd and this might need some fixing
65if [ -e /usr/local/bin/icx_mount.ext4 ]; then
66 /usr/local/bin/icx_mount.ext4 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
67else
68 false
69fi
70if [ "$?" != 0 ]; then
71 mount -t ext3 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
72fi
73if [ "$?" != 0 ]; then
74 mount -t ext2 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
75fi
76if [ "$?" != 0 ]; then
77 lcdprint 0,15 "ERROR: mount failed"
78 sleep 3
79 exit 0
80fi
81
82# rename the previous main application unless there is already a copy
83lcdprint 0,8 "Backup OF"
84if [ ! -e $SPIDERAPP_PATH.of ]; then
85 mv $SPIDERAPP_PATH $SPIDERAPP_PATH.of
86fi
87
88# extract our payload: the second file in the upgrade is a tar file
89# the files in the archive have paths of the form ./absolute/path and we extract
90# it at the rootfs mount it, so it can create/overwrite any file
91#
92# we need a small trick here: we want to pipe directly the output of the decryption
93# tool to tar, to avoid using space in /tmp/ or on the user partition
94lcdprint 0,9 "Install rockbox"
95FIFO_FILE=/tmp/rb.fifo
96mkfifo $FIFO_FILE
97if [ "$?" != 0 ]; then
98 umount "$ROOTFS_TMP_DIR"
99 lcdprint 0,15 "ERROR: cannot create fifo"
100 sleep 3
101 exit 0
102fi
103fwpchk -f /contents/$_UPDATE_FN_.UPG -c -1 $FIFO_FILE &
104#tar -tvf $FIFO_FILE
105tar -C $ROOTFS_TMP_DIR -xvf $FIFO_FILE
106if [ "$?" != 0 ]; then
107 umount "$ROOTFS_TMP_DIR"
108 lcdprint 0,15 "ERROR: extraction failed"
109 sleep 3
110 exit 0
111fi
112# wait for fwpchk
113wait
114if [ "$?" != 0 ]; then
115 umount "$ROOTFS_TMP_DIR"
116 lcdprint 0,15 "ERROR: no file to extract"
117 sleep 3
118 exit 0
119fi
120
121# create a symlink from /.rockbox to /contents/.rockbox (see dualboot code
122# for why)
123lcdprint 0,10 "Create rockbox symlink"
124rm -f "$ROOTFS_TMP_DIR/.rockbox"
125ln -s "$CONTENTS/.rockbox" "$ROOTFS_TMP_DIR/.rockbox"
126if [ "$?" != 0 ]; then
127 umount "$ROOTFS_TMP_DIR"
128 lcdprint 0,15 "ERROR: cannot create rockbox symlink"
129 sleep 3
130 exit 0
131fi
132
133# unmount root partition
134lcdprint 0,11 "Unmount root filesystem"
135sync
136if [ "$?" != 0 ]; then
137 umount "$ROOTFS_TMP_DIR"
138 lcdprint 0,15 "ERROR: sync failed"
139 sleep 3
140 exit 0
141fi
142
143umount $ROOTFS_TMP_DIR
144if [ "$?" != 0 ]; then
145 lcdprint 0,15 "ERROR: umount failed"
146 sleep 3
147 exit 0
148fi
149
150# Success screen
151lcdprint 0,15 "Rebooting in 3 seconds."
152sleep 3
153sync
154
155echo "Installation successful"
156# finish
157exit 0