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