70fbd4662493b8e900fb14f038dac03e9485470a
[openwrt/staging/mkresin.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" = "bcm4710dev" ] && 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 esac
111
112 # hacks for wap54g hardware
113 [ "$(nvram get boardnum)" = "2" \
114 -o "$(nvram get boardnum)" = "1024" ] && {
115 debug "### wap54g hack ###"
116 nvram set wan_ifname="none"
117 }
118
119 # hacks for buffalo wla2-g54l
120 [ "$(nvram get boardnum)" = "00" \
121 -a "$(nvram get product_name)" = "Product_name" \
122 -o "$(nvram get product_name)" = "WLA2-G54L" ] && {
123 debug "### wla2-g54l hacks ###"
124 nvram set wan_ifname="none"
125 nvram set lan_ifnames="vlan0"
126 }
127
128 # needed at least for wrt54gs v1.1 and wrt54g v2.0, v2.2
129 [ \! -z "$(nvram get boardrev)" ] && {
130 nvram_default wl0id 0x4320
131 }
132
133 WAN_PROTO="$(nvram get wan_proto)"
134 [ "$WAN_PROTO" = "pptp" \
135 -o "$WAN_PROTO" = "pppoe" ] && {
136 WAN_IFNAME="$(nvram get wan_ifname)"
137 [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || {
138 nvram set wan_ifname=ppp0
139 nvram set ${WAN_PROTO}_ifname="$WAN_IFNAME"
140 }
141 }
142
143 # defaults
144 nvram_default lan_ifname "br0"
145 nvram_default lan_ifnames "$FAILSAFE_ifnames"
146
147 nvram_default wan_ifname "vlan1"
148 nvram_default wan_proto "dhcp"
149
150 nvram_default wl0_ssid OpenWrt
151 nvram_default wl0_mode ap
152 nvram_default wl0_infra 1
153 nvram_default wl0_radio 1
154
155 [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
156 # if default wifi mac, set two higher than the lan mac
157 nvram set il0macaddr=$(nvram get et0macaddr|
158 awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
159 }
160