ar71xx: use different machtype and setup for the TL-MR3040
[openwrt/svn-archive/archive.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 tplink_get_hwid() {
57 local part
58
59 part=$(find_mtd_part firmware)
60 [ -z "$part" ] && return 1
61
62 dd if=$part bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
63 }
64
65 tplink_board_detect() {
66 local model="$1"
67 local hwid
68 local hwver
69
70 hwid=$(tplink_get_hwid)
71 hwver=${hwid:6:2}
72 hwver="v${hwver#0}"
73
74 case "$hwid" in
75 "070300"*)
76 model="TP-Link TL-WR703N"
77 ;;
78 "070100"*)
79 model="TP-Link TL-WA701N/ND"
80 ;;
81 "074000"*)
82 model="TP-Link TL-WR740N/ND"
83 ;;
84 "074100"*)
85 model="TP-Link TL-WR741N/ND"
86 ;;
87 "074300"*)
88 model="TP-Link TL-WR743N/ND"
89 ;;
90 "084100"*)
91 model="TP-Link TL-WR841N/ND"
92 ;;
93 "084200"*)
94 model="TP-Link TL-WR842N/ND"
95 ;;
96 "090100"*)
97 model="TP-Link TL-WA901N/ND"
98 ;;
99 "094100"*)
100 model="TP-Link TL-WR941N/ND"
101 ;;
102 "104100"*)
103 model="TP-Link TL-WR1041N/ND"
104 ;;
105 "104300"*)
106 model="TP-Link TL-WR1043N/ND"
107 ;;
108 "254300"*)
109 model="TP-Link TL-WR2543N/ND"
110 ;;
111 "110101"*)
112 model="TP-Link TL-MR11U"
113 ;;
114 "302000"*)
115 model="TP-Link TL-MR3020"
116 ;;
117 "304000"*)
118 model="TP-Link TL-MR3040"
119 ;;
120 "322000"*)
121 model="TP-Link TL-MR3220"
122 ;;
123 "342000"*)
124 model="TP-Link TL-MR3420"
125 ;;
126 "360000"*)
127 model="TP-Link TL-WDR3600"
128 ;;
129 "430000"*)
130 model="TP-Link TL-WDR4300"
131 ;;
132 "431000"*)
133 model="TP-Link TL-WDR4310"
134 ;;
135 *)
136 hwver=""
137 ;;
138 esac
139
140 AR71XX_MODEL="$model $hwver"
141 }
142
143 ar71xx_board_detect() {
144 local machine
145 local name
146
147 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
148
149 case "$machine" in
150 *"AirRouter")
151 name="airrouter"
152 ;;
153 *"ALFA Network AP96")
154 name="alfa-ap96"
155 ;;
156 *"ALFA Network N2/N5")
157 name="alfa-nx"
158 ;;
159 *ALL0258N)
160 name="all0258n"
161 ;;
162 *ALL0305)
163 name="all0305"
164 ;;
165 *ALL0315N)
166 name="all0315n"
167 ;;
168 *AP113)
169 name="ap113"
170 ;;
171 *AP121)
172 name="ap121"
173 ;;
174 *AP121-MINI)
175 name="ap121-mini"
176 ;;
177 *"AP136 reference board")
178 name="ap136"
179 ;;
180 *AP81)
181 name="ap81"
182 ;;
183 *AP83)
184 name="ap83"
185 ;;
186 *"Atheros AP96")
187 name="ap96"
188 ;;
189 *AW-NR580)
190 name="aw-nr580"
191 ;;
192 *"DB120 reference board")
193 name="db120"
194 ;;
195 *"DIR-600 rev. A1")
196 name="dir-600-a1"
197 ;;
198 *"DIR-615 rev. E4")
199 name="dir-615-e4"
200 ;;
201 *"DIR-825 rev. B1")
202 name="dir-825-b1"
203 ;;
204 *EAP7660D)
205 name="eap7660d"
206 ;;
207 *JA76PF)
208 name="ja76pf"
209 ;;
210 *JA76PF2)
211 name="ja76pf2"
212 ;;
213 *"Bullet M")
214 name="bullet-m"
215 ;;
216 *"Nanostation M")
217 name="nanostation-m"
218 ;;
219 *JWAP003)
220 name="jwap003"
221 ;;
222 *"Hornet-UB")
223 name="hornet-ub"
224 ;;
225 *LS-SR71)
226 name="ls-sr71"
227 ;;
228 *MZK-W04NU)
229 name="mzk-w04nu"
230 ;;
231 *MZK-W300NH)
232 name="mzk-w300nh"
233 ;;
234 *"NBG460N/550N/550NH")
235 name="nbg460n_550n_550nh"
236 ;;
237 *OM2P)
238 name="om2p"
239 ;;
240 *"OM2P LC")
241 name="om2p-lc"
242 ;;
243 *PB42)
244 name="pb42"
245 ;;
246 *"PB44 reference board")
247 name="pb44"
248 ;;
249 *PB92)
250 name="pb92"
251 ;;
252 *"RouterBOARD 411/A/AH")
253 name="rb-411"
254 ;;
255 *"RouterBOARD 411U")
256 name="rb-411u"
257 ;;
258 *"RouterBOARD 433/AH")
259 name="rb-433"
260 ;;
261 *"RouterBOARD 433UAH")
262 name="rb-433u"
263 ;;
264 *"RouterBOARD 450")
265 name="rb-450"
266 ;;
267 *"RouterBOARD 450G")
268 name="rb-450g"
269 ;;
270 *"RouterBOARD 493/AH")
271 name="rb-493"
272 ;;
273 *"RouterBOARD 493G")
274 name="rb-493g"
275 ;;
276 *"RouterBOARD 750")
277 name="rb-750"
278 ;;
279 *"RouterBOARD 750GL")
280 name="rb-750gl"
281 ;;
282 *"RouterBOARD 751")
283 name="rb-751"
284 ;;
285 *"RouterBOARD 751G")
286 name="rb-751g"
287 ;;
288 *"RouterBOARD 2011L")
289 name="rb-2011l"
290 ;;
291 *"RouterBOARD 2011UAS-2HnD")
292 name="rb-2011uas-2hnd"
293 ;;
294 *"Rocket M")
295 name="rocket-m"
296 ;;
297 *RouterStation)
298 name="routerstation"
299 ;;
300 *"RouterStation Pro")
301 name="routerstation-pro"
302 ;;
303 *RW2458N)
304 name="rw2458n"
305 ;;
306 *TEW-632BRP)
307 name="tew-632brp"
308 ;;
309 *TEW-673GRU)
310 name="tew-673gru"
311 ;;
312 *TEW-712BR)
313 name="tew-712br"
314 ;;
315 *"TL-WR1041N v2")
316 name="tl-wr1041n-v2"
317 ;;
318 *TL-WR1043ND)
319 name="tl-wr1043nd"
320 ;;
321 *TL-WR2543N*)
322 name="tl-wr2543n"
323 ;;
324 *"DIR-615 rev. C1")
325 name="dir-615-c1"
326 ;;
327 *TL-MR3020)
328 name="tl-mr3020"
329 ;;
330 *TL-MR3040)
331 name="tl-mr3040"
332 ;;
333 *TL-MR3220)
334 name="tl-mr3220"
335 ;;
336 *TL-MR3420)
337 name="tl-mr3420"
338 ;;
339 *TL-WA901ND)
340 name="tl-wa901nd"
341 ;;
342 *"TL-WA901ND v2")
343 name="tl-wa901nd-v2"
344 ;;
345 *"TL-WDR3600/4300/4310")
346 name="tl-wdr4300"
347 ;;
348 *TL-WR741ND)
349 name="tl-wr741nd"
350 ;;
351 *"TL-WR741ND v4")
352 name="tl-wr741nd-v4"
353 ;;
354 *"TL-WR841N v1")
355 name="tl-wr841n-v1"
356 ;;
357 *"TL-WR841N/ND v7")
358 name="tl-wr841n-v7"
359 ;;
360 *TL-WR941ND)
361 name="tl-wr941nd"
362 ;;
363 *"TL-WR703N v1")
364 name="tl-wr703n"
365 ;;
366 *"TL-MR11U")
367 name="tl-mr11u"
368 ;;
369 *UniFi)
370 name="unifi"
371 ;;
372 *WHR-G301N)
373 name="whr-g301n"
374 ;;
375 *WHR-HP-GN)
376 name="whr-hp-gn"
377 ;;
378 *WLAE-AG300N)
379 name="wlae-ag300n"
380 ;;
381 *WP543)
382 name="wp543"
383 ;;
384 *WPE72)
385 name="wpe72"
386 ;;
387 *"WNDR3700/WNDR3800/WNDRMAC")
388 wndr3700_board_detect "$machine"
389 ;;
390 *WNR2000)
391 name="wnr2000"
392 ;;
393 *WRT160NL)
394 name="wrt160nl"
395 ;;
396 *WRT400N)
397 name="wrt400n"
398 ;;
399 *WZR-HP-AG300H)
400 name="wzr-hp-ag300h"
401 ;;
402 *WZR-HP-G300NH)
403 name="wzr-hp-g300nh"
404 ;;
405 *WZR-HP-G450H)
406 name="wzr-hp-g450h"
407 ;;
408 *WZR-HP-G300NH2)
409 name="wzr-hp-g300nh2"
410 ;;
411 *WHR-HP-G300N)
412 name="whr-hp-g300n"
413 ;;
414 *ZCN-1523H-2)
415 name="zcn-1523h-2"
416 ;;
417 *ZCN-1523H-5)
418 name="zcn-1523h-5"
419 ;;
420 *EmbWir-Dorin)
421 name="ew-dorin"
422 ;;
423 *EmbWir-Dorin-Router)
424 name="ew-dorin-router"
425 ;;
426 esac
427
428 case "$machine" in
429 *TL-WR* | *TL-WA* | *TL-MR*)
430 tplink_board_detect "$machine"
431 ;;
432 esac
433
434 [ -z "$name" ] && name="unknown"
435
436 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
437 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
438
439 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
440
441 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
442 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
443 }
444
445 ar71xx_board_name() {
446 local name
447
448 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
449 [ -z "$name" ] && name="unknown"
450
451 echo "$name"
452 }