ar71xx: add support for dir 505 a1
[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-010 | \
92 ap136-020 | \
93 ap135-020 | \
94 ap96 | \
95 db120 | \
96 hornet-ub | \
97 zcn-1523h-2 | \
98 zcn-1523h-5)
99 [ "$magic_long" != "68737173" -a "$magic_long" != "19852003" ] && {
100 echo "Invalid image type."
101 return 1
102 }
103 return 0
104 ;;
105 ap81 | \
106 ap83 | \
107 ap132 | \
108 dir-505-a1 | \
109 dir-600-a1 | \
110 dir-615-c1 | \
111 dir-615-e4 | \
112 dir-825-c1 | \
113 dir-835-a1 | \
114 ew-dorin | \
115 ew-dorin-router | \
116 mzk-w04nu | \
117 mzk-w300nh | \
118 tew-632brp | \
119 tew-712br | \
120 wrt400n | \
121 airrouter | \
122 bullet-m | \
123 nanostation-m | \
124 rocket-m | \
125 rw2458n | \
126 wndap360 | \
127 wzr-hp-g300nh2 | \
128 wzr-hp-g300nh | \
129 wzr-hp-g450h | \
130 wzr-hp-ag300h | \
131 whr-g301n | \
132 whr-hp-g300n | \
133 whr-hp-gn | \
134 wlae-ag300n | \
135 nbg460n_550n_550nh | \
136 unifi | \
137 unifi-outdoor | \
138 carambola2 )
139 [ "$magic" != "2705" ] && {
140 echo "Invalid image type."
141 return 1
142 }
143 return 0
144 ;;
145
146 dir-825-b1 | \
147 tew-673gru)
148 dir825b_check_image "$1" && return 0
149 ;;
150
151 mr600 | \
152 mr600v2 | \
153 om2p | \
154 om2p-hs | \
155 om2p-lc)
156 platform_check_image_openmesh "$magic_long" "$1" && return 0
157 return 1
158 ;;
159
160 archer-c7 | \
161 tl-mr10u | \
162 tl-mr11u | \
163 tl-mr3020 | \
164 tl-mr3040 | \
165 tl-mr3220 | \
166 tl-mr3220-v2 | \
167 tl-mr3420 | \
168 tl-mr3420-v2 | \
169 tl-wa7510n | \
170 tl-wa901nd | \
171 tl-wa901nd-v2 | \
172 tl-wdr3500 | \
173 tl-wdr4300 | \
174 tl-wr703n | \
175 tl-wr710n | \
176 tl-wr720n-v3 | \
177 tl-wr741nd | \
178 tl-wr741nd-v4 | \
179 tl-wr841n-v1 | \
180 tl-wr841n-v7 | \
181 tl-wr841n-v8 | \
182 tl-wr941nd | \
183 tl-wr1041n-v2 | \
184 tl-wr1043nd | \
185 tl-wr2543n)
186 [ "$magic" != "0100" ] && {
187 echo "Invalid image type."
188 return 1
189 }
190
191 local hwid
192 local imageid
193
194 hwid=$(tplink_get_hwid)
195 imageid=$(tplink_get_image_hwid "$1")
196
197 [ "$hwid" != "$imageid" ] && {
198 echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
199 return 1
200 }
201
202 local boot_size
203
204 boot_size=$(tplink_get_image_boot_size "$1")
205 [ "$boot_size" != "00000000" ] && {
206 echo "Invalid image, it contains a bootloader."
207 return 1
208 }
209
210 return 0
211 ;;
212 uap-pro)
213 [ "$magic_long" != "19852003" ] && {
214 echo "Invalid image type."
215 return 1
216 }
217 return 0
218 ;;
219 wndr3700 | \
220 wnr612-v2)
221 local hw_magic
222
223 hw_magic="$(ar71xx_get_mtd_part_magic firmware)"
224 [ "$magic_long" != "$hw_magic" ] && {
225 echo "Invalid image, hardware ID mismatch, hw:$hw_magic image:$magic_long."
226 return 1
227 }
228 return 0
229 ;;
230 wrt160nl)
231 [ "$magic" != "4e4c" ] && {
232 echo "Invalid image type."
233 return 1
234 }
235 return 0
236 ;;
237 routerstation | \
238 routerstation-pro | \
239 ls-sr71 | \
240 pb42 | \
241 pb44 | \
242 all0305 | \
243 eap7660d | \
244 ja76pf | \
245 ja76pf2 | \
246 jwap003)
247 [ "$magic" != "4349" ] && {
248 echo "Invalid image. Use *-sysupgrade.bin files on this board"
249 return 1
250 }
251
252 local md5_img=$(dd if="$1" bs=2 skip=9 count=16 2>/dev/null)
253 local md5_chk=$(dd if="$1" bs=$CI_BLKSZ skip=1 2>/dev/null | md5sum -); md5_chk="${md5_chk%% *}"
254
255 if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
256 return 0
257 else
258 echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
259 return 1
260 fi
261 return 0
262 ;;
263 esac
264
265 echo "Sysupgrade is not yet supported on $board."
266 return 1
267 }
268
269 platform_do_upgrade() {
270 local board=$(ar71xx_board_name)
271
272 case "$board" in
273 routerstation | \
274 routerstation-pro | \
275 ls-sr71 | \
276 all0305 | \
277 eap7660d | \
278 pb42 | \
279 pb44 | \
280 ja76pf | \
281 ja76pf2 | \
282 jwap003)
283 platform_do_upgrade_combined "$ARGV"
284 ;;
285 all0258n )
286 platform_do_upgrade_allnet "0x9f050000" "$ARGV"
287 ;;
288 all0315n )
289 platform_do_upgrade_allnet "0x9f080000" "$ARGV"
290 ;;
291 cap4200ag)
292 platform_do_upgrade_allnet "0xbf0a0000" "$ARGV"
293 ;;
294 dir-825-b1 |\
295 tew-673gru)
296 platform_do_upgrade_dir825b "$ARGV"
297 ;;
298 mr600 | \
299 mr600v2 | \
300 om2p | \
301 om2p-hs | \
302 om2p-lc)
303 platform_do_upgrade_openmesh "$ARGV"
304 ;;
305 *)
306 default_do_upgrade "$ARGV"
307 ;;
308 esac
309 }
310
311 disable_watchdog() {
312 killall watchdog
313 ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
314 echo 'Could not disable watchdog'
315 return 1
316 }
317 }
318
319 append sysupgrade_pre_upgrade disable_watchdog