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