bcm53xx: revert SPI controller commit breaking flash reads
[openwrt/openwrt.git] / target / linux / brcm47xx / base-files / etc / board.d / 01_detect
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2015 OpenWrt.org
3
4 . /lib/functions/system.sh
5 . /lib/functions/uci-defaults.sh
6
7 detect_by_vlanports() {
8 local vlan0ports="$(nvram get vlan0ports)"
9 local vlan1ports="$(nvram get vlan1ports)"
10 local vlan2ports="$(nvram get vlan2ports)"
11 local cpuport="$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")"
12
13 if [ "${vlan0ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \
14 [ "${vlan1ports:0:9}" = "0 1 2 3 8" -a "${vlan2ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \
15 [ "${vlan2ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ];
16 then
17 ucidef_add_switch "switch0" \
18 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
19
20 elif [ "${vlan0ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \
21 [ "${vlan1ports:0:9}" = "1 2 3 4 8" -a "${vlan2ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \
22 [ "${vlan2ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ];
23 then
24 ucidef_add_switch "switch0" \
25 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "8@eth0"
26
27 elif [ "${vlan0ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \
28 [ "${vlan1ports:0:9}" = "0 1 2 3 5" -a "${vlan2ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \
29 [ "${vlan2ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ];
30 then
31 ucidef_add_switch "switch0" \
32 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
33
34 elif [ "${vlan0ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \
35 [ "${vlan1ports:0:9}" = "1 2 3 4 5" -a "${vlan2ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \
36 [ "${vlan2ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ];
37 then
38 ucidef_add_switch "switch0" \
39 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
40
41 else
42 logger -t "01_detect" "Unable to determine network configuration"
43 ucidef_set_interface_lan "eth0"
44 fi
45 }
46
47 detect_by_boardnum() {
48 local boardnum="$1"
49
50 case "$boardnum" in
51 # WAP54G, Sitecom WL-105b
52 "2" | \
53 "1024")
54 ucidef_set_interface_lan "eth0"
55 ;;
56
57 # Generic detection fallback
58 *)
59 detect_by_vlanports
60 ;;
61 esac
62 }
63
64 detect_by_boardtype() {
65 local boardtype="$1"
66 local boardnum="$2"
67
68 case "$boardtype" in
69 "bcm94710r4")
70 ucidef_set_interfaces_lan_wan "eth0" "eth1"
71 ;;
72
73 "0x0467")
74 ucidef_add_switch "switch0" \
75 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
76 ;;
77
78 "0x042f" | \
79 "0x0472")
80 # WL-500gP
81 if [ "$boardnum" = "45" ]; then
82 ucidef_add_switch "switch0" \
83 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
84
85 # Generic BCM94704
86 else
87 ucidef_set_interface_wan "eth1"
88 ucidef_add_switch "switch0" \
89 "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
90
91 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
92 local mac="$(nvram get et0macaddr)"
93 local pat="[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
94 pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
95 pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
96
97 case "$mac" in
98 $pat)
99 ucidef_set_interface_macaddr "lan" "$mac"
100 ucidef_set_interface_macaddr "wan" "$(macaddr_add "$mac" 1)"
101 ;;
102 esac
103 fi
104 ;;
105
106 # Buffalo WBR-B11 and Buffalo WBR-G54
107 "bcm94710ap")
108 ucidef_set_interface_wan "eth1"
109 ucidef_add_switch "switch0" \
110 "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
111 ;;
112
113 *)
114 detect_by_boardnum "$boardnum"
115 ;;
116 esac
117 }
118
119 detect_by_model() {
120 local model="$1"
121 local boardtype="$2"
122 local boardnum="$3"
123
124 # Netgear WGT634U exception
125 if grep -sqE 'mtd0: 000(6|a)0000' /proc/mtd; then
126 ucidef_add_switch "switch0" \
127 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
128 return
129 fi
130
131 case "$model" in
132 "Asus WLHDD" | \
133 "Asus WL300G")
134 ucidef_set_interface_lan "eth1"
135 ;;
136
137 "Asus WL330GE")
138 ucidef_add_switch "switch0" "4:lan" "5t@eth0"
139 ;;
140
141 "Asus WL500G" | \
142 "Microsoft MN-700")
143 ucidef_set_interfaces_lan_wan "eth0" "eth1"
144 ;;
145
146 "Asus RT-N12"* | \
147 "Asus WL500GP V2" | \
148 "Buffalo WHR-G125" | \
149 "D-Link DIR-330" | \
150 "Motorola WR850G" | \
151 "Siemens SE505 V2")
152 ucidef_add_switch "switch0" \
153 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
154 ;;
155
156 "Asus WL700")
157 ucidef_add_switch "switch0" \
158 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
159 ;;
160
161 "Asus WL500W" | \
162 "Dell TrueMobile 2300")
163 ucidef_set_interface_wan "eth1"
164 ucidef_add_switch "switch0" \
165 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
166 ;;
167
168 "Asus RT-N16"* | \
169 "Linksys E3000 V1")
170 ucidef_add_switch "switch0" \
171 "0:wan" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "8@eth0"
172 ;;
173
174 *)
175 detect_by_boardtype "$boardtype" "$boardnum"
176 ;;
177 esac
178 }
179
180
181 model="$(board_name)"
182 boardtype="$(nvram get boardtype)"
183 boardnum="$(nvram get boardnum)"
184
185 board_config_update
186
187 ucidef_set_board_id "$boardtype${boardnum:+:$boardnum}"
188 ucidef_set_model_name "$model"
189
190 detect_by_model "$model" "$boardtype" "$boardnum"
191
192 board_config_flush