ar71xx: enable sysupgrade for the OpenMesh MR600
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright (C) 2011 OpenWrt.org
3 #
4
5 . /lib/ar71xx.sh
6
7 PART_NAME=firmware
8 RAMFS_COPY_DATA=/lib/ar71xx.sh
9
10 CI_BLKSZ=65536
11 CI_LDADR=0x80060000
12
13 platform_find_partitions() {
14 local first dev size erasesize name
15 while read dev size erasesize name; do
16 name=${name#'"'}; name=${name%'"'}
17 case "$name" in
18 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin|rootfs|filesystem)
19 if [ -z "$first" ]; then
20 first="$name"
21 else
22 echo "$erasesize:$first:$name"
23 break
24 fi
25 ;;
26 esac
27 done < /proc/mtd
28 }
29
30 platform_find_kernelpart() {
31 local part
32 for part in "${1%:*}" "${1#*:}"; do
33 case "$part" in
34 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin)
35 echo "$part"
36 break
37 ;;
38 esac
39 done
40 }
41
42 platform_do_upgrade_combined() {
43 local partitions=$(platform_find_partitions)
44 local kernelpart=$(platform_find_kernelpart "${partitions#*:}")
45 local erase_size=$((0x${partitions%%:*})); partitions="${partitions#*:}"
46 local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
47 local kern_blocks=$(($kern_length / $CI_BLKSZ))
48 local root_blocks=$((0x$(dd if="$1" bs=2 skip=5 count=4 2>/dev/null) / $CI_BLKSZ))
49
50 if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
51 [ ${kern_blocks:-0} -gt 0 ] && \
52 [ ${root_blocks:-0} -gt ${kern_blocks:-0} ] && \
53 [ ${erase_size:-0} -gt 0 ];
54 then
55 local append=""
56 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
57
58 ( dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null; \
59 dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null ) | \
60 mtd -r $append -F$kernelpart:$kern_length:$CI_LDADR,rootfs write - $partitions
61 fi
62 }
63
64 tplink_get_image_hwid() {
65 get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
66 }
67
68 tplink_get_image_boot_size() {
69 get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
70 }
71
72 platform_check_image() {
73 local board=$(ar71xx_board_name)
74 local magic="$(get_magic_word "$1")"
75 local magic_long="$(get_magic_long "$1")"
76
77 [ "$ARGC" -gt 1 ] && return 1
78
79 case "$board" in
80 all0315n | \
81 all0258n | \
82 cap4200ag)
83 platform_check_image_allnet "$1" && return 0
84 return 1
85 ;;
86 alfa-ap96 | \
87 alfa-nx | \
88 ap113 | \
89 ap121 | \
90 ap121-mini | \
91 ap136 | \
92 ap96 | \
93 db120 | \
94 hornet-ub | \
95 zcn-1523h-2 | \
96 zcn-1523h-5)
97 [ "$magic_long" != "68737173" -a "$magic_long" != "19852003" ] && {
98 echo "Invalid image type."
99 return 1
100 }
101 return 0
102 ;;
103 ap81 | \
104 ap83 | \
105 dir-600-a1 | \
106 dir-615-c1 | \
107 dir-615-e4 | \
108 ew-dorin | \
109 ew-dorin-router | \
110 mzk-w04nu | \
111 mzk-w300nh | \
112 tew-632brp | \
113 tew-712br | \
114 wrt400n | \
115 airrouter | \
116 bullet-m | \
117 nanostation-m | \
118 rocket-m | \
119 rw2458n | \
120 wzr-hp-g300nh2 | \
121 wzr-hp-g300nh | \
122 wzr-hp-g450h | \
123 wzr-hp-ag300h | \
124 whr-g301n | \
125 whr-hp-g300n | \
126 whr-hp-gn | \
127 wlae-ag300n | \
128 nbg460n_550n_550nh | \
129 unifi | \
130 unifi-outdoor )
131 [ "$magic" != "2705" ] && {
132 echo "Invalid image type."
133 return 1
134 }
135 return 0
136 ;;
137
138 dir-825-b1 | \
139 tew-673gru)
140 dir825b_check_image "$1" && return 0
141 ;;
142
143 mr600 | \
144 om2p | \
145 om2p-hs | \
146 om2p-lc)
147 platform_check_image_openmesh "$magic_long" "$1" && return 0
148 return 1
149 ;;
150 tl-mr11u | \
151 tl-mr3020 | \
152 tl-mr3040 | \
153 tl-mr3220 | \
154 tl-mr3420 | \
155 tl-wa7510n | \
156 tl-wa901nd | \
157 tl-wa901nd-v2 | \
158 tl-wdr4300 | \
159 tl-wr703n | \
160 tl-wr741nd | \
161 tl-wr741nd-v4 | \
162 tl-wr841n-v1 | \
163 tl-wr841n-v7 | \
164 tl-wr841n-v8 | \
165 tl-wr941nd | \
166 tl-wr1041n-v2 | \
167 tl-wr1043nd | \
168 tl-wr2543n)
169 [ "$magic" != "0100" ] && {
170 echo "Invalid image type."
171 return 1
172 }
173
174 local hwid
175 local imageid
176
177 hwid=$(tplink_get_hwid)
178 imageid=$(tplink_get_image_hwid "$1")
179
180 [ "$hwid" != "$imageid" ] && {
181 echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
182 return 1
183 }
184
185 local boot_size
186
187 boot_size=$(tplink_get_image_boot_size "$1")
188 [ "$boot_size" != "00000000" ] && {
189 echo "Invalid image, it contains a bootloader."
190 return 1
191 }
192
193 return 0
194 ;;
195 wndr3700)
196 local hw_magic
197
198 hw_magic="$(ar71xx_get_mtd_part_magic firmware)"
199 [ "$magic_long" != "$hw_magic" ] && {
200 echo "Invalid image, hardware ID mismatch, hw:$hw_magic image:$magic_long."
201 return 1
202 }
203 return 0
204 ;;
205 wrt160nl)
206 [ "$magic" != "4e4c" ] && {
207 echo "Invalid image type."
208 return 1
209 }
210 return 0
211 ;;
212 routerstation | \
213 routerstation-pro | \
214 ls-sr71 | \
215 pb42 | \
216 pb44 | \
217 all0305 | \
218 eap7660d | \
219 ja76pf | \
220 ja76pf2 | \
221 jwap003)
222 [ "$magic" != "4349" ] && {
223 echo "Invalid image. Use *-sysupgrade.bin files on this board"
224 return 1
225 }
226
227 local md5_img=$(dd if="$1" bs=2 skip=9 count=16 2>/dev/null)
228 local md5_chk=$(dd if="$1" bs=$CI_BLKSZ skip=1 2>/dev/null | md5sum -); md5_chk="${md5_chk%% *}"
229
230 if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
231 return 0
232 else
233 echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
234 return 1
235 fi
236 return 0
237 ;;
238 esac
239
240 echo "Sysupgrade is not yet supported on $board."
241 return 1
242 }
243
244 platform_do_upgrade() {
245 local board=$(ar71xx_board_name)
246
247 case "$board" in
248 routerstation | \
249 routerstation-pro | \
250 ls-sr71 | \
251 all0305 | \
252 eap7660d | \
253 pb42 | \
254 pb44 | \
255 ja76pf | \
256 ja76pf2 | \
257 jwap003)
258 platform_do_upgrade_combined "$ARGV"
259 ;;
260 all0258n )
261 platform_do_upgrade_allnet "0x9f050000" "$ARGV"
262 ;;
263 all0315n )
264 platform_do_upgrade_allnet "0x9f080000" "$ARGV"
265 ;;
266 cap4200ag)
267 platform_do_upgrade_allnet "0xbf0a0000" "$ARGV"
268 ;;
269 dir-825-b1 |\
270 tew-673gru)
271 platform_do_upgrade_dir825b "$ARGV"
272 ;;
273 mr600 | \
274 om2p | \
275 om2p-hs | \
276 om2p-lc)
277 platform_do_upgrade_openmesh "$ARGV"
278 ;;
279 *)
280 default_do_upgrade "$ARGV"
281 ;;
282 esac
283 }
284
285 disable_watchdog() {
286 killall watchdog
287 ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
288 echo 'Could not disable watchdog'
289 return 1
290 }
291 }
292
293 append sysupgrade_pre_upgrade disable_watchdog