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