realtek: add support for TP-Link SG2452P v4 aka T1600G-52PS v4
[openwrt/openwrt.git] / target / linux / realtek / base-files / etc / board.d / 02_network
1
2 . /lib/functions.sh
3 . /lib/functions/uci-defaults.sh
4 . /lib/functions/system.sh
5
6 ucidef_set_poe() {
7 json_select_object poe
8 json_add_string "budget" "$1"
9 json_select_array ports
10 for port in $2; do
11 if [ -n "$3" -a -n "$(expr "$3" : "\(.\+[[:space:]]\)\{0,1\}$port\([[:space:]].*\|\$\)")" ]; then
12 continue # skip ports passed via $3
13 fi
14 json_add_string "" "$port"
15 done
16 json_select ..
17 json_select ..
18 }
19
20 board=$(board_name)
21 board_config_update
22
23 lan_list=$(ls -1 -v -d /sys/class/net/lan* | xargs -n1 basename | xargs)
24 ucidef_set_bridge_device switch
25 ucidef_set_interface_lan "$lan_list"
26
27 lan_mac=""
28 lan_mac_start=""
29 lan_mac_end=""
30 label_mac=""
31 case $board in
32 hpe,1920-8g|\
33 hpe,1920-16g|\
34 hpe,1920-24g)
35 label_mac=$(mtd_get_mac_binary factory 0x68)
36 lan_mac=$label_mac
37 mac_count1=$(hexdump -v -n 4 -s 0x110 -e '4 "%d"' $(find_mtd_part factory) 2>/dev/null)
38 mac_count2=$(hexdump -v -n 4 -s 0x114 -e '4 "%d"' $(find_mtd_part factory) 2>/dev/null)
39 lan_mac_start=$(macaddr_add $lan_mac 2)
40 lan_mac_end=$(macaddr_add $lan_mac $((mac_count2-mac_count1)))
41 ;;
42 tplink,sg2008p-v1|\
43 tplink,sg2452p-v4)
44 label_mac=$(mtd_get_mac_binary para 0xfdff4)
45 lan_mac="$label_mac"
46 ;;
47 *)
48 lan_mac=$(mtd_get_mac_ascii u-boot-env2 mac_start)
49 lan_mac_end=$(mtd_get_mac_ascii u-boot-env2 mac_end)
50 label_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
51 [ -z "$lan_mac" ] && lan_mac=$label_mac
52 ;;
53 esac
54
55 ucidef_set_interface_macaddr "lan" $lan_mac
56 ucidef_set_bridge_mac "$lan_mac"
57 ucidef_set_network_device_mac eth0 $lan_mac
58 [ -z "$lan_mac_start" ] && lan_mac_start=$lan_mac
59 for lan in $lan_list; do
60 ucidef_set_network_device_mac $lan $lan_mac_start
61 [ -z "$lan_mac_end" ] || [ "$lan_mac_start" == "$lan_mac_end" ] && lan_mac_start=$(macaddr_setbit_la $lan_mac_start)
62 lan_mac_start=$(macaddr_add $lan_mac_start 1)
63 done
64 [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
65
66 case $board in
67 netgear,gs110tpp-v1)
68 ucidef_set_poe 130 "$lan_list" "lan9 lan10"
69 ;;
70 netgear,gs310tp-v1)
71 ucidef_set_poe 55 "$lan_list" "lan9 lan10"
72 ;;
73 zyxel,gs1900-10hp)
74 ucidef_set_poe 77 "$lan_list" "lan9 lan10"
75 ;;
76 zyxel,gs1900-8hp-v1|\
77 zyxel,gs1900-8hp-v2)
78 ucidef_set_poe 70 "$lan_list"
79 ;;
80 zyxel,gs1900-24hp-v1|\
81 zyxel,gs1900-24hp-v2)
82 ucidef_set_poe 170 "$lan_list" "lan25 lan26"
83 ;;
84 esac
85
86 board_config_flush
87
88 exit 0