ramips: extract board name from device tree as a fallback
[openwrt/openwrt.git] / target / linux / ramips / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/system.sh
6
7 ramips_setup_rt3x5x_vlans()
8 {
9 if [ ! -x /sbin/swconfig ]; then
10 # legacy default
11 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
12 return
13 fi
14 local wanports=""
15 local lanports=""
16 for port in 5 4 3 2 1 0; do
17 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
18 continue
19 fi
20 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
21 wanports="$port:wan $wanports"
22 else
23 lanports="$port:lan $lanports"
24 fi
25 done
26 ucidef_add_switch "rt305x" $lanports $wanports "6t@eth0"
27 }
28
29 ramips_setup_interfaces()
30 {
31 local board="$1"
32
33 case $board in
34 11acnas|\
35 w2914nsv2|\
36 zbt-we2026)
37 ucidef_add_switch "switch0" \
38 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
39 ;;
40 3g150b|\
41 3g300m|\
42 a5-v11|\
43 all0256n-4M|\
44 all0256n-8M|\
45 all5002|\
46 all5003|\
47 broadway|\
48 dcs-930|\
49 dcs-930l-b1|\
50 ht-tm02|\
51 linkits7688 | \
52 linkits7688d | \
53 m2m|\
54 microwrt|\
55 mpr-a2|\
56 ncs601w|\
57 omega2 | \
58 omega2p | \
59 timecloud|\
60 w150m|\
61 widora-neo|\
62 wnce2001|\
63 zbt-cpe102|\
64 zte-q7)
65 ucidef_add_switch "switch0"
66 ucidef_add_switch_attr "switch0" "enable" "false"
67 ucidef_set_interface_lan "eth0"
68 ;;
69 mlw221|\
70 mr-102n)
71 ucidef_set_interface_lan "eth0.2"
72 ;;
73 3g-6200n|\
74 ai-br100|\
75 d240|\
76 db-wrt01|\
77 dir-300-b7|\
78 dir-320-b1|\
79 dir-610-a1|\
80 dir-615-h1|\
81 ew1200|\
82 firewrt|\
83 hc5661a|\
84 hc5962|\
85 hlk-rm04|\
86 k2p|\
87 kn|\
88 kn_rc|\
89 mac1200rv2|\
90 miwifi-mini|\
91 miwifi-nano|\
92 mt7621|\
93 mt7628|\
94 mzk-750dhp|\
95 mzk-w300nh2|\
96 nixcore-x1-8M|\
97 nixcore-x1-16M|\
98 oy-0001|\
99 pbr-m1|\
100 psg1208|\
101 psg1218a|\
102 r6220|\
103 sap-g3200u3|\
104 sk-wb8|\
105 u7621-06-256M-16M|\
106 vr500|\
107 wf-2881|\
108 witi|\
109 wl-wn575a3|\
110 wndr3700v5|\
111 wt1520-4M|\
112 wt1520-8M|\
113 y1|\
114 youku-yk1|\
115 zbt-ape522ii|\
116 zbt-we1326|\
117 zbt-we826-16M|\
118 zbt-we826-32M|\
119 zbt-wg2626|\
120 zbt-wg3526-16M|\
121 zbt-wg3526-32M|\
122 zbt-wr8305rt)
123 ucidef_add_switch "switch0" \
124 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
125 ;;
126 mir3g)
127 ucidef_add_switch "switch0" \
128 "2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
129 ;;
130 psg1218b)
131 ucidef_add_switch "switch0" \
132 "0:lan:3" "1:lan:2" "2:lan:1" "3:wan" "6@eth0"
133 ;;
134 whr-300hp2|\
135 whr-600d|\
136 wsr-1166|\
137 wsr-600)
138 ucidef_add_switch "switch0" \
139 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
140 ;;
141 ar670w|\
142 ar725w|\
143 rt-ac51u)
144 ucidef_add_switch "switch0" \
145 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
146 ;;
147 rt-n15|\
148 wl-351)
149 ucidef_add_switch "switch0" \
150 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
151 ;;
152 asl26555-8M|\
153 asl26555-16M|\
154 rp-n53)
155 ucidef_add_switch "switch0" \
156 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
157 ;;
158 atp-52b|\
159 awm002-evb-4M|\
160 awm002-evb-8M|\
161 c20i|\
162 dir-645|\
163 f5d8235-v2|\
164 gl-mt300a|\
165 gl-mt300n|\
166 gl-mt750|\
167 hg255d|\
168 jhr-n805r|\
169 jhr-n825r|\
170 jhr-n926r|\
171 mzk-wdpr|\
172 rb750gr3|\
173 rt-n14u|\
174 tl-wr840n-v4|\
175 tl-wr840n-v5|\
176 tl-wr841n-v13|\
177 u7628-01-128M-16M|\
178 ubnt-erx|\
179 ubnt-erx-sfp|\
180 ur-326n4g|\
181 wrtnode|\
182 wrtnode2p | \
183 wrtnode2r | \
184 wt3020-4M|\
185 wt3020-8M|\
186 zbt-wa05)
187 ucidef_add_switch "switch0" \
188 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
189 ;;
190 c20|\
191 c50)
192 ucidef_add_switch "switch0" \
193 "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
194 ;;
195 dir-860l-b1)
196 ucidef_add_switch "switch0" \
197 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
198 ;;
199 gb-pc1)
200 ucidef_add_switch "switch0" \
201 "0:lan" "4:lan" "6@eth0"
202 ;;
203 gl-mt300n-v2)
204 ucidef_add_switch "switch0" \
205 "1:lan" "0:wan" "6@eth0"
206 ;;
207 awapn2403)
208 ucidef_add_switch "switch0" \
209 "0:lan" "1:wan" "6@eth0"
210 ;;
211 b2c|\
212 nw718|\
213 psr-680w|\
214 sl-r7205|\
215 ur-336un|\
216 w502u|\
217 wr6202)
218 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
219 ;;
220 br-6475nd)
221 ucidef_add_switch "switch0" \
222 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
223 ;;
224 c108|\
225 cf-wr800n)
226 ucidef_add_switch "switch0" \
227 "4:lan" "6t@eth0"
228 ;;
229 cy-swr1100)
230 ucidef_add_switch "switch0" \
231 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
232 ;;
233 cs-qr10|\
234 d105|\
235 dch-m225|\
236 ex2700|\
237 ex3700|\
238 hpm|\
239 mzk-ex300np|\
240 mzk-ex750np|\
241 na930|\
242 pbr-d1|\
243 u25awf-h1|\
244 wli-tx4-ag300n|\
245 wmdr-143n|\
246 wmr-300|\
247 wn3000rpv3|\
248 wrh-300cr)
249 ucidef_set_interface_lan "eth0"
250 ;;
251 duzun-dm06)
252 ucidef_add_switch "switch0" \
253 "1:lan" "0:wan" "6@eth0"
254 ;;
255 e1700|\
256 mt7620a_mt7530)
257 ucidef_add_switch "switch1" \
258 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
259 ;;
260 hc5*61|\
261 y1s)
262 ucidef_add_switch "switch0" \
263 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
264 ;;
265 kn_rf)
266 ucidef_add_switch "switch0" \
267 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
268 ;;
269 kng_rc)
270 ucidef_add_switch "switch1" \
271 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
272 ;;
273 mlwg2|\
274 wizard8800|\
275 wl-330n)
276 ucidef_set_interface_lan "eth0.1"
277 ;;
278 mr200)
279 ucidef_add_switch "switch0" \
280 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
281 ucidef_set_interface_wan "usb0"
282 ;;
283 mzk-dp150n|\
284 vocore-8M|\
285 vocore-16M)
286 ucidef_add_switch "switch0" \
287 "0:lan" "4:lan" "6t@eth0"
288 ;;
289 newifi-d1)
290 ucidef_add_switch "switch0" \
291 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
292 ;;
293 re350-v1)
294 ucidef_add_switch "switch0" \
295 "0:lan" "6@eth0"
296 ;;
297 re6500)
298 ucidef_add_switch "switch0" \
299 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
300 ;;
301 rt-n56u)
302 ucidef_add_switch "switch0" \
303 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
304 ;;
305 tew-638apb-v2)
306 ucidef_add_switch "switch0" \
307 "4:lan" "6@eth0"
308 ;;
309 tew-691gr|\
310 tew-692gr|\
311 wlr-6000)
312 ucidef_add_switch "switch0" \
313 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
314 ;;
315 vocore2|\
316 vocore2lite)
317 ucidef_add_switch "switch0" \
318 "0:lan" "2:lan" "6t@eth0"
319 ;;
320 f5d8235-v1|\
321 tew-714tru|\
322 v11st-fe|\
323 wzr-agl300nh)
324 ucidef_add_switch "switch0" \
325 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
326 ;;
327 wcr-1166ds)
328 ucidef_add_switch "switch0" \
329 "3:lan" "4:wan" "6@eth0"
330 ;;
331 wcr-150gn|\
332 we1026-5g-16m)
333 ucidef_add_switch "switch0" \
334 "0:lan" "6t@eth0"
335 ;;
336 whr-1166d)
337 ucidef_add_switch "switch0" \
338 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
339 ;;
340 wizfi630a)
341 ucidef_add_switch "switch0" \
342 "1:lan" "2:lan" "0:wan" "6@eth0"
343 ;;
344 *)
345 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
346 if [ -n "${RT3X5X}" ]; then
347 ramips_setup_rt3x5x_vlans
348 else
349 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
350 fi
351 ;;
352 esac
353 }
354
355 ramips_setup_macs()
356 {
357 local board="$1"
358 local lan_mac=""
359 local wan_mac=""
360
361 case $board in
362 a5-v11|\
363 ht-tm02|\
364 wmdr-143n)
365 lan_mac=$(cat /sys/class/net/eth0/address)
366 ;;
367 all0239-3g|\
368 carambola|\
369 freestation5|\
370 w502u|\
371 wnce2001)
372 wan_mac=$(mtd_get_mac_binary factory 46)
373 ;;
374 bc2|\
375 broadway|\
376 d105|\
377 dir-300-b7|\
378 dir-320-b1|\
379 dir-620-a1|\
380 esr-9753|\
381 freestation5|\
382 hlk-rm04|\
383 mpr-a1|\
384 psr-680w|\
385 sl-r7205|\
386 y1|\
387 y1s)
388 lan_mac=$(cat /sys/class/net/eth0/address)
389 lan_mac=$(macaddr_setbit_la "$lan_mac")
390 wan_mac=$(macaddr_add "$lan_mac" 1)
391 ;;
392 br-6475nd)
393 lan_mac=$(cat /sys/class/net/eth0/address)
394 wan_mac=$(mtd_get_mac_binary devdata 7)
395 ;;
396 cy-swr1100|\
397 dch-m225)
398 lan_mac=$(mtd_get_mac_ascii factory lanmac)
399 ;;
400 dir-645)
401 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
402 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
403 ;;
404 dir-860l-b1)
405 lan_mac=$(mtd_get_mac_ascii factory lanmac)
406 wan_mac=$(mtd_get_mac_ascii factory wanmac)
407 ;;
408 e1700)
409 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
410 ;;
411 gl-mt300n-v2)
412 wan_mac=$(mtd_get_mac_binary factory 4)
413 ;;
414 hc5*61|\
415 hc5661a|\
416 hc5962)
417 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
418 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
419 wan_mac=$(macaddr_add "$lan_mac" 1)
420 ;;
421 kn_rc|\
422 kn_rf|\
423 kng_rc)
424 wan_mac=$(mtd_get_mac_binary factory 40)
425 ;;
426 linkits7688 | \
427 linkits7688d)
428 wan_mac=$(mtd_get_mac_binary factory 4)
429 lan_mac=$(mtd_get_mac_binary factory 46)
430 ;;
431 mac1200rv2)
432 lan_mac=$(mtd_get_mac_binary factory_info 13)
433 wan_mac=$(macaddr_add "$lan_mac" 1)
434 ;;
435 mir3g)
436 lan_mac=$(mtd_get_mac_binary Factory 0xe006)
437 ;;
438 miwifi-mini)
439 wan_mac=$(cat /sys/class/net/eth0/address)
440 lan_mac=$(macaddr_setbit_la "$wan_mac")
441 ;;
442 m3|\
443 m4-4M|\
444 m4-8M|\
445 x5|\
446 x8)
447 lan_mac=$(cat /sys/class/net/eth0/address)
448 lan_mac=$(macaddr_add "$lan_mac" -2)
449 ;;
450 newifi-d1)
451 lan_mac=$(cat /sys/class/net/eth0/address)
452 lan_mac=$(macaddr_add "$lan_mac" 2)
453 ;;
454 omega2|\
455 omega2p)
456 wan_mac=$(mtd_get_mac_binary factory 4)
457 lan_mac=$(mtd_get_mac_binary factory 46)
458 ;;
459 oy-0001)
460 lan_mac=$(mtd_get_mac_binary factory 40)
461 wan_mac=$(mtd_get_mac_binary factory 46)
462 ;;
463 r6220)
464 wan_mac=$(mtd_get_mac_binary factory 4)
465 lan_mac=$(macaddr_add "$wan_mac" 1)
466 ;;
467 rt-n56u)
468 lan_mac=$(cat /sys/class/net/eth0/address)
469 lan_mac=$(macaddr_setbit_la "$lan_mac")
470 wan_mac=$(mtd_get_mac_binary factory 32772)
471 ;;
472 sk-wb8)
473 wan_mac=$(mtd_get_mac_binary factory 57350)
474 ;;
475 tew-691gr)
476 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
477 ;;
478 tew-692gr)
479 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
480 ;;
481 tiny-ac)
482 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
483 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
484 ;;
485 vr500)
486 lan_mac=$(mtd_get_mac_binary factory 57344)
487 wan_mac=$(mtd_get_mac_binary factory 57350)
488 ;;
489 w306r-v20)
490 lan_mac=$(cat /sys/class/net/eth0/address)
491 wan_mac=$(macaddr_add "$lan_mac" 5)
492 ;;
493 wcr-1166ds|\
494 wsr-1166)
495 local index="$(find_mtd_index "board_data")"
496 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
497 lan_mac=$wan_mac
498 ;;
499 wcr-150gn)
500 wan_mac=$(mtd_get_mac_binary factory 40)
501 ;;
502 whr-1166d|\
503 whr-300hp2|\
504 whr-600d|\
505 wsr-600)
506 wan_mac=$(mtd_get_mac_binary factory 4)
507 lan_mac=$wan_mac
508 ;;
509 wizfi630a)
510 lan_mac=$(mtd_get_mac_binary factory 4)
511 wan_mac=$(mtd_get_mac_binary factory 40)
512 ;;
513 wlr-6000)
514 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
515 ;;
516 *)
517 lan_mac=$(cat /sys/class/net/eth0/address)
518 wan_mac=$(macaddr_add "$lan_mac" 1)
519 ;;
520 esac
521
522 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
523 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
524 }
525
526 board_config_update
527 board=$(board_name)
528 ramips_setup_interfaces $board
529 ramips_setup_macs $board
530 board_config_flush
531
532 exit 0