fix typos (#260)
[openwrt/svn-archive/archive.git] / openwrt / target / linux / package / base-files / files / brcm-2.4 / etc / init.d / S05nvram
1 #!/bin/sh
2 # NVRAM setup
3 #
4 # This file handles the NVRAM quirks of various hardware.
5
6 . /etc/network.overrides
7 alias debug=${DEBUG:-:}
8
9 # WGT634u
10 [ "$(/usr/bin/head -c4 /dev/mtdblock/1 | /usr/bin/tail -c3)" = "ELF" ] && exit
11
12 remap () {
13 for type in lan wifi wan pppoe
14 do
15 for s in '' s
16 do
17 eval nvram set ${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\"
18 done
19 done
20 }
21
22 nvram_default() {
23 [ -z "$(nvram get $1)" ] && nvram set "$1=$2"
24 }
25
26 nvram_set() { # for the linksys fixup part
27 [ "$(nvram get "$1")" = "$2" -a "$2" != "" ] || {
28 COMMIT=1
29 /usr/sbin/nvram set "$1=$2"
30 }
31 }
32
33 # work around braindead CFE defaults in linksys routers
34 boardtype=$(nvram get boardtype)
35 boardflags=$(($(nvram get boardflags)))
36 [ "$boardtype" = "bcm94710dev" ] && boardtype="0xdeadbeef"
37 adm_switch="$(( ($boardflags & 0x80) >> 7 ))"
38 case "$(( $boardtype ))" in
39 "$((0x708))")
40 if [ "$adm_switch" = 0 ]; then
41 nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
42 [ "$COMMIT" = 1 ] && {
43 nvram_set sdram_config 0x0062
44 nvram_set clkfreq 216
45 nvram_set sdram_ncdl 0x0
46 nvram_set pa0itssit 62
47 nvram_set pa0b0 0x15eb
48 nvram_set pa0b1 0xfa82
49 nvram_set pa0b2 0xfe66
50 nvram_set pa0maxpwr 0x4e
51 }
52 fi
53 ;;
54 "$((0x467))")
55 nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
56 [ "$COMMIT" = 1 ] && {
57 nvram_set sdram_config 0x0062
58 nvram_set sdram_ncdl 0x0
59 nvram_set pa0itssit 62
60 nvram_set pa0b0 0x168b
61 nvram_set pa0b1 0xfabf
62 nvram_set pa0b2 0xfeaf
63 nvram_set pa0maxpwr 0x4e
64 }
65 ;;
66 esac
67 [ "$COMMIT" = "1" ] && nvram commit
68
69
70 # linksys bug; remove when not using static configuration for lan
71 nvram set lan_proto="static"
72
73 # hacks for wrt54g 1.x hardware
74 [ "$(nvram get boardnum)" = "42" \
75 -a "$(nvram get boardtype)" = "bcm94710dev" ] && {
76 debug "### wrt54g 1.x hack ###"
77 nvram set vlan1hwname="et0"
78 nvram set vlan2hwname="et0"
79 remap eth0 vlan2
80 remap eth1 vlan1
81 }
82
83 # hacks for asus wl-500g deluxe
84 [ "$(nvram get boardtype)" = "bcm95365r" \
85 -a "$(nvram get boardnum)" = "45" ] && {
86 debug "### wl-500g deluxe hacks ###"
87 nvram set vlan0hwname="et0"
88 nvram set vlan1hwname="et0"
89 remap eth0.1 vlan0
90 remap eth0 vlan1
91
92 # set up the vlan*ports variables for the asus wl-500g deluxe
93 # if they don't already exist
94 nvram_default vlan0ports "1 2 3 4 5*"
95 nvram_default vlan1ports "0 5"
96 }
97
98 # hacks for asus
99 case "$(nvram get productid)" in
100 WL300g)
101 debug "### wl-300g hacks ###"
102 nvram set lan_ifnames="eth0 eth2"
103 nvram set wan_ifname="none"
104 ;;
105 WLHDD)
106 debug "### wl-hdd hacks ###"
107 nvram set lan_ifnames="eth1 eth2"
108 nvram set wan_ifname="none"
109 ;;
110 *)
111 # wl-500g defaults. these are placed here, because WL-HDD and WL-300g
112 # might have the same nvram settings.
113 [ "$(nvram get boardnum)" = "asusX" \
114 -a "$(nvram get boardtype)" = "bcm94710dev" ] && {
115 nvram_default wan_device "eth1"
116 }
117 ;;
118 esac
119
120 # hacks for wap54g hardware
121 [ "$(nvram get boardnum)" = "2" \
122 -o "$(nvram get boardnum)" = "1024" ] && {
123 debug "### wap54g hack ###"
124 nvram set wan_ifname="none"
125 }
126
127 # hacks for buffalo wla2-g54l
128 [ "$(nvram get boardnum)" = "00" \
129 -a "$(nvram get product_name)" = "Product_name" \
130 -o "$(nvram get product_name)" = "WLA2-G54L" ] && {
131 debug "### wla2-g54l hacks ###"
132 nvram set wan_ifname="none"
133 nvram set lan_ifnames="vlan0"
134 }
135
136 # needed at least for wrt54gs v1.1 and wrt54g v2.0, v2.2
137 [ \! -z "$(nvram get boardrev)" ] && {
138 nvram_default wl0id 0x4320
139 }
140
141 # defaults
142 nvram_default lan_ifname "br0"
143 nvram_default lan_ifnames "$FAILSAFE_ifnames"
144
145 nvram_default wan_ifname "vlan1"
146 nvram_default wan_device "vlan1"
147 nvram_default wan_proto "dhcp"
148
149 nvram_default wl0_ssid OpenWrt
150 nvram_default wl0_mode ap
151 nvram_default wl0_infra 1
152 nvram_default wl0_radio 1
153
154 WAN_PROTO="$(nvram get wan_proto)"
155 WAN_IFNAME="$(nvram get wan_ifname)"
156 case "$WAN_PROTO" in
157 pp*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || nvram set wan_ifname=ppp0;;
158 *) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] && nvram set wan_ifname="$(nvram get wan_device)";;
159 esac
160
161 [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
162 # if default wifi mac, set two higher than the lan mac
163 nvram set il0macaddr=$(nvram get et0macaddr|
164 awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
165 }
166