ar71xx: dragino2: add missing sysupgrade support.
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / lib / ar71xx.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2009-2011 OpenWrt.org
4 #
5
6 AR71XX_BOARD_NAME=
7 AR71XX_MODEL=
8
9 ar71xx_get_mtd_offset_size_format() {
10 local mtd="$1"
11 local offset="$2"
12 local size="$3"
13 local format="$4"
14 local dev
15
16 dev=$(find_mtd_part $mtd)
17 [ -z "$dev" ] && return
18
19 dd if=$dev bs=1 skip=$offset count=$size 2>/dev/null | hexdump -v -e "1/1 \"$format\""
20 }
21
22 ar71xx_get_mtd_part_magic() {
23 local mtd="$1"
24 ar71xx_get_mtd_offset_size_format "$mtd" 0 4 %02x
25 }
26
27 wndr3700_board_detect() {
28 local machine="$1"
29 local magic
30 local name
31
32 name="wndr3700"
33
34 magic="$(ar71xx_get_mtd_part_magic firmware)"
35 case $magic in
36 "33373030")
37 machine="NETGEAR WNDR3700"
38 ;;
39 "33373031")
40 local model
41 model=$(ar71xx_get_mtd_offset_size_format art 56 10 %c)
42 if [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ]; then
43 machine="NETGEAR WNDR3700v2"
44 elif [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xffN' ]; then
45 machine="NETGEAR WNDRMAC"
46 else
47 machine="NETGEAR $model"
48 fi
49 ;;
50 esac
51
52 AR71XX_BOARD_NAME="$name"
53 AR71XX_MODEL="$machine"
54 }
55
56 cybertan_get_hw_magic() {
57 local part
58
59 part=$(find_mtd_part firmware)
60 [ -z "$part" ] && return 1
61
62 dd bs=8 count=1 skip=0 if=$part 2>/dev/null | hexdump -v -n 8 -e '1/1 "%02x"'
63 }
64
65 tplink_get_hwid() {
66 local part
67
68 part=$(find_mtd_part firmware)
69 [ -z "$part" ] && return 1
70
71 dd if=$part bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
72 }
73
74 tplink_get_mid() {
75 local part
76
77 part=$(find_mtd_part firmware)
78 [ -z "$part" ] && return 1
79
80 dd if=$part bs=4 count=1 skip=17 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
81 }
82
83 tplink_board_detect() {
84 local model="$1"
85 local hwid
86 local hwver
87
88 hwid=$(tplink_get_hwid)
89 mid=$(tplink_get_mid)
90 hwver=${hwid:6:2}
91 hwver="v${hwver#0}"
92
93 case "$hwid" in
94 "070300"*)
95 model="TP-Link TL-WR703N"
96 ;;
97 "071000"*)
98 model="TP-Link TL-WR710N"
99 ;;
100 "072001"*)
101 model="TP-Link TL-WR720N"
102 ;;
103 "070100"*)
104 model="TP-Link TL-WA701N/ND"
105 ;;
106 "074000"*)
107 model="TP-Link TL-WR740N/ND"
108 ;;
109 "074100"*)
110 model="TP-Link TL-WR741N/ND"
111 ;;
112 "074300"*)
113 model="TP-Link TL-WR743N/ND"
114 ;;
115 "075000"*)
116 model="TP-Link TL-WA750RE"
117 ;;
118 "080100"*)
119 model="TP-Link TL-WA801N/ND"
120 ;;
121 "083000"*)
122 model="TP-Link TL-WA830RE"
123 ;;
124 "084100"*)
125 model="TP-Link TL-WR841N/ND"
126 ;;
127 "084200"*)
128 model="TP-Link TL-WR842N/ND"
129 ;;
130 "085000"*)
131 model="TP-Link TL-WA850RE"
132 ;;
133 "090100"*)
134 model="TP-Link TL-WA901N/ND"
135 ;;
136 "094100"*)
137 if [ "$hwid" == "09410002" -a "$mid" == "00420001" ]; then
138 model="Rosewill RNX-N360RT"
139 hwver=""
140 else
141 model="TP-Link TL-WR941N/ND"
142 fi
143 ;;
144 "104100"*)
145 model="TP-Link TL-WR1041N/ND"
146 ;;
147 "104300"*)
148 model="TP-Link TL-WR1043N/ND"
149 ;;
150 "254300"*)
151 model="TP-Link TL-WR2543N/ND"
152 ;;
153 "001001"*)
154 model="TP-Link TL-MR10U"
155 ;;
156 "001101"*)
157 model="TP-Link TL-MR11U"
158 ;;
159 "001301"*)
160 model="TP-Link TL-MR13U"
161 ;;
162 "302000"*)
163 model="TP-Link TL-MR3020"
164 ;;
165 "304000"*)
166 model="TP-Link TL-MR3040"
167 ;;
168 "322000"*)
169 model="TP-Link TL-MR3220"
170 ;;
171 "342000"*)
172 model="TP-Link TL-MR3420"
173 ;;
174 "350000"*)
175 model="TP-Link TL-WDR3500"
176 ;;
177 "360000"*)
178 model="TP-Link TL-WDR3600"
179 ;;
180 "430000"*)
181 model="TP-Link TL-WDR4300"
182 ;;
183 "431000"*)
184 model="TP-Link TL-WDR4310"
185 ;;
186 "453000"*)
187 model="MERCURY MW4530R"
188 ;;
189 *)
190 hwver=""
191 ;;
192 esac
193
194 AR71XX_MODEL="$model $hwver"
195 }
196
197 ar71xx_board_detect() {
198 local machine
199 local name
200
201 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
202
203 case "$machine" in
204 *"AirRouter")
205 name="airrouter"
206 ;;
207 *"ALFA Network AP96")
208 name="alfa-ap96"
209 ;;
210 *"ALFA Network N2/N5")
211 name="alfa-nx"
212 ;;
213 *ALL0258N)
214 name="all0258n"
215 ;;
216 *ALL0305)
217 name="all0305"
218 ;;
219 *ALL0315N)
220 name="all0315n"
221 ;;
222 *AP113)
223 name="ap113"
224 ;;
225 *AP121)
226 name="ap121"
227 ;;
228 *AP121-MINI)
229 name="ap121-mini"
230 ;;
231 *"AP132 reference board")
232 name="ap132"
233 ;;
234 *"AP136-010 reference board")
235 name="ap136-010"
236 ;;
237 *"AP136-020 reference board")
238 name="ap136-020"
239 ;;
240 *"AP135-020 reference board")
241 name="ap135-020"
242 ;;
243 *AP81)
244 name="ap81"
245 ;;
246 *AP83)
247 name="ap83"
248 ;;
249 *"Archer C7")
250 name="archer-c7"
251 ;;
252 *"Atheros AP96")
253 name="ap96"
254 ;;
255 *AW-NR580)
256 name="aw-nr580"
257 ;;
258 *CAP4200AG)
259 name="cap4200ag"
260 ;;
261 *"DB120 reference board")
262 name="db120"
263 ;;
264 *"DIR-505 rev. A1")
265 name="dir-505-a1"
266 ;;
267 *"DIR-600 rev. A1")
268 name="dir-600-a1"
269 ;;
270 *"DIR-615 rev. E4")
271 name="dir-615-e4"
272 ;;
273 *"DIR-825 rev. B1")
274 name="dir-825-b1"
275 ;;
276 *"DIR-825 rev. C1")
277 name="dir-825-c1"
278 ;;
279 *"DIR-835 rev. A1")
280 name="dir-835-a1"
281 ;;
282 *"Dragino v2")
283 name="dragino2"
284 ;;
285 *EAP7660D)
286 name="eap7660d"
287 ;;
288 *JA76PF)
289 name="ja76pf"
290 ;;
291 *JA76PF2)
292 name="ja76pf2"
293 ;;
294 *"Bullet M")
295 name="bullet-m"
296 ;;
297 *"Nanostation M")
298 name="nanostation-m"
299 ;;
300 *JWAP003)
301 name="jwap003"
302 ;;
303 *"Hornet-UB")
304 local size
305 size=$(awk '/firmware/ { print $2 }' /proc/mtd)
306
307 if [ "x$size" = "x00790000" ]; then
308 name="hornet-ub"
309 fi
310
311 if [ "x$size" = "x00f90000" ]; then
312 name="hornet-ub-x2"
313 fi
314 ;;
315 *LS-SR71)
316 name="ls-sr71"
317 ;;
318 *MR600v2)
319 name="mr600v2"
320 ;;
321 *MR600)
322 name="mr600"
323 ;;
324 *"My Net N600")
325 name="mynet-n600"
326 ;;
327 *"My Net N750")
328 name="mynet-n750"
329 ;;
330 *"WD My Net Wi-Fi Range Extender")
331 name="mynet-rext"
332 ;;
333 *MZK-W04NU)
334 name="mzk-w04nu"
335 ;;
336 *MZK-W300NH)
337 name="mzk-w300nh"
338 ;;
339 *"NBG460N/550N/550NH")
340 name="nbg460n_550n_550nh"
341 ;;
342 *OM2P)
343 name="om2p"
344 ;;
345 *"OM2P HS")
346 name="om2p-hs"
347 ;;
348 *"OM2P LC")
349 name="om2p-lc"
350 ;;
351 *PB42)
352 name="pb42"
353 ;;
354 *"PB44 reference board")
355 name="pb44"
356 ;;
357 *PB92)
358 name="pb92"
359 ;;
360 *"RouterBOARD 411/A/AH")
361 name="rb-411"
362 ;;
363 *"RouterBOARD 411U")
364 name="rb-411u"
365 ;;
366 *"RouterBOARD 433/AH")
367 name="rb-433"
368 ;;
369 *"RouterBOARD 433UAH")
370 name="rb-433u"
371 ;;
372 *"RouterBOARD 435G")
373 name="rb-435g"
374 ;;
375 *"RouterBOARD 450")
376 name="rb-450"
377 ;;
378 *"RouterBOARD 450G")
379 name="rb-450g"
380 ;;
381 *"RouterBOARD 493/AH")
382 name="rb-493"
383 ;;
384 *"RouterBOARD 493G")
385 name="rb-493g"
386 ;;
387 *"RouterBOARD 750")
388 name="rb-750"
389 ;;
390 *"RouterBOARD 750GL")
391 name="rb-750gl"
392 ;;
393 *"RouterBOARD 751")
394 name="rb-751"
395 ;;
396 *"RouterBOARD 751G")
397 name="rb-751g"
398 ;;
399 *"RouterBOARD 951G-2HnD")
400 name="rb-951g-2hnd"
401 ;;
402 *"RouterBOARD 2011L")
403 name="rb-2011l"
404 ;;
405 *"RouterBOARD 2011UAS")
406 name="rb-2011uas"
407 ;;
408 *"RouterBOARD 2011UAS-2HnD")
409 name="rb-2011uas-2hnd"
410 ;;
411 *"Rocket M")
412 name="rocket-m"
413 ;;
414 *RouterStation)
415 name="routerstation"
416 ;;
417 *"RouterStation Pro")
418 name="routerstation-pro"
419 ;;
420 *RW2458N)
421 name="rw2458n"
422 ;;
423 *TEW-632BRP)
424 name="tew-632brp"
425 ;;
426 *TEW-673GRU)
427 name="tew-673gru"
428 ;;
429 *TEW-712BR)
430 name="tew-712br"
431 ;;
432 *TEW-732BR)
433 name="tew-732br"
434 ;;
435 *"TL-WR1041N v2")
436 name="tl-wr1041n-v2"
437 ;;
438 *TL-WR1043ND)
439 name="tl-wr1043nd"
440 ;;
441 *"TL-WR1043ND v2")
442 name="tl-wr1043nd-v2"
443 ;;
444 *TL-WR2543N*)
445 name="tl-wr2543n"
446 ;;
447 *"DIR-615 rev. C1")
448 name="dir-615-c1"
449 ;;
450 *TL-MR3020)
451 name="tl-mr3020"
452 ;;
453 *TL-MR3040)
454 name="tl-mr3040"
455 ;;
456 *"TL-MR3040 v2")
457 name="tl-mr3040-v2"
458 ;;
459 *TL-MR3220)
460 name="tl-mr3220"
461 ;;
462 *"TL-MR3220 v2")
463 name="tl-mr3220-v2"
464 ;;
465 *TL-MR3420)
466 name="tl-mr3420"
467 ;;
468 *"TL-MR3420 v2")
469 name="tl-mr3420-v2"
470 ;;
471 *TL-WA750RE)
472 name="tl-wa750re"
473 ;;
474 *TL-WA7510N)
475 name="tl-wa7510n"
476 ;;
477 *TL-WA850RE)
478 name="tl-wa850re"
479 ;;
480 *"TL-WA801ND v2")
481 name="tl-wa801nd-v2"
482 ;;
483 *TL-WA901ND)
484 name="tl-wa901nd"
485 ;;
486 *"TL-WA901ND v2")
487 name="tl-wa901nd-v2"
488 ;;
489 *"TL-WA901ND v3")
490 name="tl-wa901nd-v3"
491 ;;
492 *"TL-WDR3500")
493 name="tl-wdr3500"
494 ;;
495 *"TL-WDR3600/4300/4310")
496 name="tl-wdr4300"
497 ;;
498 *TL-WR741ND)
499 name="tl-wr741nd"
500 ;;
501 *"TL-WR741ND v4")
502 name="tl-wr741nd-v4"
503 ;;
504 *"TL-WR841N v1")
505 name="tl-wr841n-v1"
506 ;;
507 *"TL-WR841N/ND v7")
508 name="tl-wr841n-v7"
509 ;;
510 *"TL-WR841N/ND v8")
511 name="tl-wr841n-v8"
512 ;;
513 *"TL-WR842N/ND v2")
514 name="tl-wr842n-v2"
515 ;;
516 *TL-WR941ND)
517 name="tl-wr941nd"
518 ;;
519 *"TL-WR703N v1")
520 name="tl-wr703n"
521 ;;
522 *"TL-WR710N v1")
523 name="tl-wr710n"
524 ;;
525 *"TL-WR720N v3")
526 name="tl-wr720n-v3"
527 ;;
528 *"TL-MR10U")
529 name="tl-mr10u"
530 ;;
531 *"TL-MR11U")
532 name="tl-mr11u"
533 ;;
534 *"TL-MR13U")
535 name="tl-mr13u"
536 ;;
537 *UniFi)
538 name="unifi"
539 ;;
540 *"UniFi AP Pro")
541 name="uap-pro"
542 ;;
543 *WHR-G301N)
544 name="whr-g301n"
545 ;;
546 *WHR-HP-GN)
547 name="whr-hp-gn"
548 ;;
549 *WLAE-AG300N)
550 name="wlae-ag300n"
551 ;;
552 *"UniFiAP Outdoor")
553 name="unifi-outdoor"
554 ;;
555 *WP543)
556 name="wp543"
557 ;;
558 *WPE72)
559 name="wpe72"
560 ;;
561 *WNDAP360)
562 name="wndap360"
563 ;;
564 *"WNDR3700/WNDR3800/WNDRMAC")
565 wndr3700_board_detect "$machine"
566 ;;
567 *"WNDR4300")
568 name="wndr4300"
569 ;;
570 *"WNR2000 V3")
571 name="wnr2000-v3"
572 ;;
573 *WNR2000)
574 name="wnr2000"
575 ;;
576 *WNR2200)
577 name="wnr2200"
578 ;;
579 *"WNR612 V2")
580 name="wnr612-v2"
581 ;;
582 *WRT160NL)
583 name="wrt160nl"
584 ;;
585 *WRT400N)
586 name="wrt400n"
587 ;;
588 *"WZR-HP-AG300H/WZR-600DHP")
589 name="wzr-hp-ag300h"
590 ;;
591 *WZR-HP-G300NH)
592 name="wzr-hp-g300nh"
593 ;;
594 *WZR-HP-G450H)
595 name="wzr-hp-g450h"
596 ;;
597 *WZR-HP-G300NH2)
598 name="wzr-hp-g300nh2"
599 ;;
600 *WHR-HP-G300N)
601 name="whr-hp-g300n"
602 ;;
603 *ZCN-1523H-2)
604 name="zcn-1523h-2"
605 ;;
606 *ZCN-1523H-5)
607 name="zcn-1523h-5"
608 ;;
609 *EmbWir-Dorin)
610 name="ew-dorin"
611 ;;
612 *EmbWir-Dorin-Router)
613 name="ew-dorin-router"
614 ;;
615 "8devices Carambola2"*)
616 name="carambola2"
617 ;;
618 *"Sitecom WLR-8100")
619 name="wlr8100"
620 ;;
621 *"BHU BXU2000n-2 rev. A1")
622 name="bxu2000n-2-a1"
623 ;;
624 esac
625
626 case "$machine" in
627 *TL-WR* | *TL-WA* | *TL-MR* | *TL-WD*)
628 tplink_board_detect "$machine"
629 ;;
630 esac
631
632 [ -z "$name" ] && name="unknown"
633
634 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
635 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
636
637 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
638
639 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
640 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
641 }
642
643 ar71xx_board_name() {
644 local name
645
646 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
647 [ -z "$name" ] && name="unknown"
648
649 echo "$name"
650 }