root/src/router/services/sysinit/sysinit-broadcom.c

Revision 8451, 27.1 kB (checked in by eko, 2 years ago)

required change for new wireless driver

Line 
1 /*
2  * sysinit-broadcom.c
3  *
4  * Copyright (C) 2006 Sebastian Gottschall <gottschall@dd-wrt.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * $Id:
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <limits.h>
26 #include <time.h>
27 #include <unistd.h>
28 #include <errno.h>
29 #include <syslog.h>
30 #include <signal.h>
31 #include <string.h>
32 #include <termios.h>
33 #include <sys/klog.h>
34 #include <sys/types.h>
35 #include <sys/mount.h>
36 #include <sys/reboot.h>
37 #include <sys/stat.h>
38 #include <sys/sysmacros.h>
39 #include <sys/time.h>
40 #include <sys/utsname.h>
41 #include <sys/wait.h>
42
43 #include <bcmnvram.h>
44 #include <shutils.h>
45 #include <utils.h>
46 #include <bcmdevs.h>
47
48 static void
49 check_brcm_cpu_type (void)
50 {
51   FILE *fcpu;
52   char cpu_type[20];
53   char type2[30];
54
55   fcpu = fopen ("/proc/cpuinfo", "r");
56
57   if (fcpu == NULL)
58     cprintf ("Open /proc/cpuinfo fail...0\n");
59   else
60     {
61       char buf[500];
62       fgets (buf, 500, fcpu);
63       fscanf (fcpu, "%s %s %s %s %s", buf, buf, buf, cpu_type, type2);
64       if (!strcmp (type2, "BCM4704"))
65         {
66           nvram_set ("cpu_type", cpu_type);
67           fclose (fcpu);
68           return;
69         }
70       if (!strcmp (type2, "BCM4712"))
71         {
72           nvram_set ("cpu_type", cpu_type);
73           fclose (fcpu);
74           return;
75         }
76       if (!strcmp (type2, "BCM4702"))
77         {
78           nvram_set ("cpu_type", cpu_type);
79           fclose (fcpu);
80           return;
81         }
82       if (!strcmp (type2, "BCM3302"))
83         {
84           nvram_set ("cpu_type", cpu_type);
85           fclose (fcpu);
86           return;
87         }
88       fgets (buf, 500, fcpu);
89       fscanf (fcpu, "%s %s %s %s %s", buf, buf, buf, cpu_type, type2);
90       //fprintf(stderr, "cpu_type : %s\n", cpu_type);
91       fclose (fcpu);
92       if (!strcmp (cpu_type, "BCM4710") || !strcmp (cpu_type, "BCM4702"))
93         {
94           cprintf ("We got BCM4702 board...\n");
95           nvram_set ("cpu_type", cpu_type);
96         }
97       else if (!strcmp (cpu_type, "BCM3302") || !strcmp (cpu_type, "BCM4712"))
98         {
99           cprintf ("We got BCM4712 board...\n");
100           nvram_set ("cpu_type", cpu_type);
101         }
102       else
103         {
104           cprintf ("We got unknown board...\n");
105           nvram_set ("cpu_type", cpu_type);
106         }
107     }
108
109
110
111 }
112
113 static void
114 loadWlModule (void)             //set wled params, get boardflags, set afterburner bit, load wl, unset afterburner bit
115 {
116
117   int brand = getRouterBrand ();
118
119 #ifdef HAVE_MSSID               //v24
120
121 #ifndef HAVE_BUFFALO
122   nvram_set ("pa0maxpwr", "251");       //force pa0maxpwr to be 251
123 #endif
124
125   switch (brand)
126     {
127     case ROUTER_ASUS_WL500G_PRE:
128     case ROUTER_ASUS_WL500W:
129     case ROUTER_WRT54G:
130     case ROUTER_WRT54G_V8:
131     case ROUTER_MOTOROLA:
132     case ROUTER_BUFFALO_WLAG54C:
133     case ROUTER_NETGEAR_WG602_V3:
134     case ROUTER_RT480W:
135       nvram_set ("wl0gpio0", "136");
136       break;
137     case ROUTER_WAP54G_V3:
138       nvram_set ("wl0gpio0", "0");
139       nvram_set ("wl0gpio2", "255");
140       nvram_set ("wl0gpio3", "255");
141       nvram_set ("wl0gpio5", "136");
142       break;
143     case ROUTER_ASUS_WL520GUGC:
144       nvram_set ("wl0gpio0", "0");
145       nvram_set ("wl0gpio1", "136");     
146       nvram_set ("wl0gpio2", "0");
147       nvram_set ("wl0gpio3", "0");
148       break;
149     case ROUTER_LINKSYS_WTR54GS:
150     case ROUTER_WAP54G_V1:
151       nvram_set ("wl0gpio0", "136");
152       nvram_set ("wl0gpio1", "0");
153       nvram_set ("wl0gpio2", "0");
154       nvram_set ("wl0gpio3", "0");
155       break;
156     case ROUTER_BUFFALO_WBR54G:
157     case ROUTER_BUFFALO_WBR2G54S:
158     case ROUTER_WRT150N:
159     case ROUTER_WRT300N:
160     case ROUTER_WRT600N:
161     case ROUTER_WRT350N:
162       nvram_set ("wl0gpio0", "8");
163       break;
164     case ROUTER_BUFFALO_WHRG54S:
165     case ROUTER_BUFFALO_WLI_TX4_G54HP:
166       nvram_set ("wl0gpio2", "136");
167       break;
168     case ROUTER_BUFFALO_WLA2G54C:
169       nvram_set ("wl0gpio0", "0");
170       nvram_set ("wl0gpio5", "136");
171       break;
172     case ROUTER_ASUS_WL500GD:
173       nvram_unset ("wl0gpio0");
174       break;
175     case ROUTER_BELKIN_F5D7230_V2000:
176     case ROUTER_BELKIN_F5D7231:
177       nvram_set ("wl0gpio3", "136");
178       break;
179     }
180 #else //v23
181
182   switch (brand)
183     {
184     case ROUTER_BUFFALO_WZRRSG54:
185     case ROUTER_BUFFALO_WBR54G:
186     case ROUTER_BUFFALO_WBR2G54S:
187       nvram_set ("wl0gpio0", "130");
188       break;
189     case ROUTER_MOTOROLA:
190     case ROUTER_WAP54G_V1:
191     case ROUTER_NETGEAR_WG602_V3:
192     case ROUTER_RT480W:
193       nvram_set ("wl0gpio0", "2");
194       break;
195     case ROUTER_BUFFALO_WLA2G54C:
196       nvram_set ("wl0gpio0", "0");
197       nvram_set ("wl0gpio5", "2");
198       break;
199     case ROUTER_WAP54G_V3:
200       nvram_set ("wl0gpio0", "0");
201       nvram_set ("wl0gpio2", "255");
202       nvram_set ("wl0gpio3", "255");
203       nvram_set ("wl0gpio5", "2");
204       break;
205     case ROUTER_ASUS_WL500GD:
206       nvram_unset ("wl0gpio0");
207       break;
208     case ROUTER_BELKIN_F5D7230_V2000:
209       nvram_set ("wl0gpio3", "2");
210       break;   
211     }
212 #endif
213
214   int boardflags;
215
216   switch (brand)
217     {
218     case ROUTER_WRT150N:
219     case ROUTER_WRT300N:
220     case ROUTER_WRT350N:
221     case ROUTER_WRT600N:
222     case ROUTER_BUFFALO_WZRG144NH:
223     case ROUTER_BUFFALO_WZRG300N:
224     case ROUTER_NETGEAR_WNR834B:
225     case ROUTER_ASUS_WL500W:
226       eval ("insmod", "wl");    //load module
227       break;
228     default:
229       boardflags = strtoul (nvram_safe_get ("boardflags"), NULL, 0);
230       fprintf (stderr, "boardflags are 0x%04X\n", boardflags);
231       if (boardflags == 0)      //we can try anyway
232         {
233           nvram_set ("boardflags", "0x0200");
234           eval ("insmod", "wl");        //load module
235           nvram_unset ("boardflags");
236         }
237       else if (boardflags & BFL_AFTERBURNER)    //ab flag already set
238         {
239           eval ("insmod", "wl");        //load module
240         }
241       else                      //ab flag not set
242         {
243           char bf[16];
244           sprintf (bf, "0x%04X", boardflags);
245           boardflags |= BFL_AFTERBURNER;
246           fprintf (stderr, "enable Afterburner, boardflags are 0x%04X\n",
247                    boardflags);
248           char ab[16];
249           sprintf (ab, "0x%04X", boardflags);
250           nvram_set ("boardflags", ab); //set boardflags with AfterBurner bit on
251           eval ("insmod", "wl");        //load module
252           nvram_set ("boardflags", bf); //set back to original
253         }
254
255     }
256   return;
257 }
258
259
260 char wanifname[8], wlifname[8];
261 #define BCM4712_CPUTYPE "0x4712"
262
263 static void
264 setup_4712 (void)
265 {
266   uint boardflags = strtoul (nvram_safe_get ("boardflags"), NULL, 0);
267   if (nvram_match ("cpu_type", BCM4712_CPUTYPE) ||
268       nvram_match ("cpu_type", "BCM3302") ||
269       nvram_match ("cpu_type", "BCM4712"))
270     {
271       if (boardflags & BFL_ENETVLAN)
272         {
273           cprintf ("setup_4712(): Enable VLAN\n");
274           //nvram_set("setup_4712","1");
275           strcpy (wanifname, "vlan1");
276           strcpy (wlifname, "eth1");
277           if (!strcmp (nvram_safe_get ("wan_ifname"), "eth1"))
278             {
279               //nvram_set("setup_4712","1-1");
280               nvram_set ("wan_ifname", "vlan1");
281               nvram_set ("wan_ifnames", "vlan1");
282             }
283           if (!strstr (nvram_safe_get ("lan_ifnames"), "vlan0"))
284             {
285               //nvram_set("setup_4712","1-2");
286               nvram_set ("lan_ifnames", "vlan0 eth1");
287               nvram_set ("vlan0hwname", "et0");
288               nvram_set ("vlan1hwname", "et0");
289               nvram_set ("wl0_ifname", "eth1");
290 //              nvram_set ("need_commit","1");
291             }
292         }                       // VLAN enabled
293       else
294         {
295           //nvram_set("setup_4712","2");
296           cprintf ("setup_4712(): Disable VLAN, it must be in bridge mode\n");
297           nvram_set ("lan_ifnames", "eth0 eth1");
298           strcpy (wlifname, "eth1");
299           nvram_set ("wl0_ifname", "eth1");
300         }
301     }
302   else
303     {                           // 4702, 4704
304       cprintf
305         ("setup_4712(): It's a 4702 or 4704 hardware, VLAN can't be used in these 2 boards\n");
306       strcpy (wanifname, "eth1");
307       strcpy (wlifname, "eth2");
308       nvram_set ("wl0_ifname", "eth2");
309       if (!strcmp (nvram_safe_get ("wan_ifname"), ""))
310         nvram_set ("lan_ifnames", "eth0 eth1 eth2 wlanb0 wlana0");
311       else
312         nvram_set ("lan_ifnames", "eth0 eth2");
313     }
314 //nvram_set ("need_commit","1");
315
316
317
318 }
319
320
321 int
322 start_sysinit (void)
323 {
324   char buf[PATH_MAX];
325   struct utsname name;
326   struct stat tmp_stat;
327   time_t tm = 0;
328   cprintf ("sysinit() proc\n");
329   /* /proc */
330   mount ("proc", "/proc", "proc", MS_MGC_VAL, NULL);
331   cprintf ("sysinit() tmp\n");
332
333   /* /tmp */
334   mount ("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
335   eval ("mkdir", "/tmp/www");
336
337   cprintf ("sysinit() var\n");
338
339   /* /var */
340   mkdir ("/tmp/var", 0777);
341   mkdir ("/var/lock", 0777);
342   mkdir ("/var/lock/subsys", 0777);
343   mkdir ("/var/log", 0777);
344   mkdir ("/var/run", 0777);
345   mkdir ("/var/tmp", 0777);
346   cprintf ("sysinit() setup console\n");
347
348   eval ("/sbin/watchdog");      // system watchdog
349
350   /* Setup console */
351
352   cprintf ("sysinit() klogctl\n");
353   klogctl (8, NULL, atoi (nvram_safe_get ("console_loglevel")));
354   cprintf ("sysinit() get router\n");
355
356   int brand = getRouterBrand ();
357   led_control (LED_DIAG, LED_ON);
358   char *rname = getRouter ();
359   fprintf (stderr, "Booting Device:%s\n", rname);
360
361   nvram_unset ("port_swap");
362  
363   switch (brand)
364     {
365     case ROUTER_BUFFALO_WZRRSG54:
366       check_brcm_cpu_type ();
367       setup_4712 ();
368           nvram_set ("lan_ifnames", "eth0 eth2");
369       nvram_set ("wan_ifname", "eth1");
370       nvram_set ("wl0_ifname", "eth2");
371       break;
372
373     case ROUTER_MOTOROLA:
374       nvram_set ("cpu_type", "BCM4712");
375       setup_4712 ();
376       break;
377
378     case ROUTER_RT480W:
379     case ROUTER_USR_5461:
380       setup_4712 ();
381       break;
382
383     case ROUTER_BELKIN_F5D7231:
384       nvram_set ("lan_ifnames", "vlan0 eth1");
385       nvram_set ("wan_ifname", "vlan1");
386       nvram_set ("wl0_ifname", "eth1");
387       if (nvram_match ("vlan1ports", "0 5u"))
388          nvram_set ("vlan1ports", "0 5");
389       break;     
390      
391     case ROUTER_RT210W:
392       setup_4712 ();
393       nvram_set ("wan_ifname", "eth1"); // fix for Belkin f5d7230 v1000 WAN problem.
394       if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
395         {
396           nvram_set ("et0macaddr", "00:16:E3:00:00:10");        //fix for missing cfe default = dead LAN ports.
397         }
398       break;
399
400     case ROUTER_BRCM4702_GENERIC:
401     case ROUTER_ASUS_WL500G:
402       setup_4712 ();
403       nvram_set ("wan_ifname", "eth1"); // fix for Belkin f5d7230 v1000 WAN problem.
404
405       if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
406         {
407           nvram_set ("et0macaddr", "00:0C:6E:00:00:10");        //fix for missing cfe default = dead LAN ports.
408         }
409       break;
410
411     case ROUTER_DELL_TRUEMOBILE_2300:
412       setup_4712 ();
413       nvram_set ("wan_ifname", "eth1"); // fix for WAN problem.
414       break;
415
416     case ROUTER_BUFFALO_WBR54G: //for WLA-G54
417           nvram_set ("lan_ifnames", "eth0 eth2");
418       nvram_set ("wan_ifname", "eth1");
419       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
420         {
421           nvram_set ("lan_ifnames", "eth2");
422           nvram_set ("wan_ifname", "eth0");
423         }
424       break;
425
426     case ROUTER_BUFFALO_WLI2_TX1_G54:
427     case ROUTER_BUFFALO_WLAG54C:
428     case ROUTER_WAP54G_V1:
429     case ROUTER_SITECOM_WL105B:
430       nvram_set ("lan_ifnames", "eth1 eth2");
431       nvram_set ("wl0_ifname", "eth2");
432       nvram_set ("wan_ifname", "eth0"); //WAN to nonexist. iface.
433       nvram_set ("port_swap", "1");
434       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
435         {
436           nvram_set ("lan_ifnames", "eth2");
437           nvram_set ("wan_ifname", "eth1");
438         }
439       break;
440
441     case ROUTER_SITECOM_WL111:
442       nvram_set ("lan_ifnames", "eth0 eth2");
443       nvram_set ("wl0_ifname", "eth2");
444       nvram_set ("wan_ifname", "eth1");
445       break;
446
447     case ROUTER_MOTOROLA_WE800G:
448       nvram_set ("lan_ifnames", "eth1 eth2");
449       nvram_set ("wl0_ifname", "eth2");
450       nvram_set ("wan_ifname", "eth0"); //WAN to nonexist. iface.
451       nvram_set ("port_swap", "1");
452       eval ("gpio", "disable", "7");
453       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
454         {
455           nvram_set ("lan_ifnames", "eth2");
456           nvram_set ("wan_ifname", "eth1");
457         }
458       break;
459
460     case ROUTER_MOTOROLA_V1:
461       nvram_set ("wan_ifname", "eth1");
462       eval ("gpio", "disable", "7");
463       break;
464
465     case ROUTER_BUFFALO_WZRG300N:
466     case ROUTER_NETGEAR_WNR834B:
467     case ROUTER_WRT150N:
468     case ROUTER_WRT300N:
469     case ROUTER_ASUS_WL500W:
470     case ROUTER_BUFFALO_WLAH_G54:
471     case ROUTER_BUFFALO_WAPM_HP_AM54G54:
472     case ROUTER_WRTSL54GS:
473     case ROUTER_MICROSOFT_MN700:
474       nvram_set ("wan_ifname", "eth1");
475       break;
476
477     case ROUTER_WRT54G1X:
478       if (check_vlan_support ())
479         {
480           nvram_set ("lan_ifnames", "vlan0 eth2");
481           nvram_set ("wan_ifname", "vlan1");
482         }
483       break;
484
485     case ROUTER_WRT350N:
486       nvram_set ("wan_ifname", "vlan2");
487       break;
488     case ROUTER_WRT600N:
489       nvram_set ("wan_ifname", "vlan2");
490       break;
491
492     case ROUTER_BUFFALO_WZRG144NH:
493       nvram_set ("wan_ifname", "vlan1");
494       break;
495
496     case ROUTER_ASUS_WL500G_PRE:
497       nvram_set ("sdram_init", "0x0009");
498 //      nvram_set ("sdram_ncdl", "0x208");
499       nvram_set ("lan_ifnames", "vlan0 eth2");
500       nvram_set ("wl0_ifname", "eth2");
501       nvram_set ("wan_ifname", "vlan1");        // fix for Asus WL500gPremium WAN problem.
502       if (nvram_match ("vlan1ports", "0 5u"))
503          nvram_set ("vlan1ports", "0 5");
504       break;
505
506     case ROUTER_ASUS_WL500GD:
507     case ROUTER_ASUS_WL550GE:
508       nvram_set ("wl0_ifname", "eth1");
509       break;
510
511     case ROUTER_BUFFALO_WLA2G54C:
512     case ROUTER_WAP54G_V2:
513     case ROUTER_VIEWSONIC_WAPBR_100:
514     case ROUTER_USR_5430:
515     case ROUTER_BUFFALO_WLI_TX4_G54HP:
516     case ROUTER_BELKIN_F5D7230_V2000:
517     case ROUTER_NETGEAR_WG602_V3:
518       nvram_set ("lan_ifnames", "eth0 eth1");
519       nvram_set ("wl0_ifname", "eth1");
520       nvram_set ("wan_ifname", "eth2"); // map WAN port to nonexistant interface
521       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
522         {
523           nvram_set ("lan_ifnames", "eth1");
524           nvram_set ("wan_ifname", "eth0");
525         }
526       break;
527
528     case ROUTER_DELL_TRUEMOBILE_2300_V2:        //we must fix cfe defaults with CR added
529       nvram_set ("vlan0hwname", "et0");
530       nvram_set ("vlan1hwname", "et0");
531       nvram_set ("et0mdcport", "0");
532       nvram_set ("et0phyaddr", "30");
533       nvram_set ("gpio2", "adm_eecs");
534       nvram_set ("gpio3", "adm_eesk");
535       nvram_set ("gpio4", "adm_eedi");
536       nvram_set ("gpio5", "adm_rc");
537       nvram_unset ("gpio6");
538       break;
539      
540     case ROUTER_WRT54G_V8:
541       nvram_set ("reset_gpio", "7");
542       break;
543      
544     case ROUTER_ASUS_WL520GUGC:     
545       if (nvram_match ("vlan1ports", "0 5u"))
546          nvram_set ("vlan1ports", "0 5");
547       break;
548            
549     case ROUTER_LINKSYS_WTR54GS:
550         eval ("gpio", "enable", "3");  //prevent reboot loop on reset
551         break;
552            
553     case ROUTER_WAP54G_V3:
554         eval ("gpio", "enable", "0");  //reset gpio 0 for reset button
555 //      nvram_set ("vlan0ports", "1 5*");
556 //      nvram_set ("vlan1ports", "4 5");
557 //      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))      // = no lan
558 //      {
559 //        nvram_set ("vlan0ports", "4 5*");
560 //        nvram_set ("vlan1ports", "1 5");
561 //      }
562       break;
563
564    }
565    
566   /* fix il0macaddr */
567   unsigned char mac[20];
568   if (nvram_match ("port_swap", "1"))
569     strcpy (mac, nvram_safe_get ("et1macaddr"));
570   else
571     strcpy (mac, nvram_safe_get ("et0macaddr"));
572   MAC_ADD (mac);
573   nvram_set ("il0macaddr", mac);
574    
575   /* ifnames */
576   strcpy (wanifname, nvram_safe_get ("wan_ifname"));
577   strcpy (wlifname, nvram_safe_get ("wl0_ifname"));
578
579   /* set wan_ifnames, pppoe_wan_ifname and pppoe_ifname*/
580   nvram_set ("wan_ifnames", wanifname);
581   nvram_set ("pppoe_wan_ifname", wanifname);
582   nvram_set ("pppoe_ifname", wanifname);
583  
584   /* additional boardflags adjustment */
585   switch (brand)
586     {
587     case ROUTER_BELKIN_F5D7231:     
588       if (nvram_match ("boardflags", "0x388") || nvram_match ("boardflags", "0x0388"))
589          nvram_set ("boardflags", "0x0f58");
590       break;
591      
592     case ROUTER_BUFFALO_WLI_TX4_G54HP:
593       if (!nvram_match ("buffalo_hp", "1")
594        && (nvram_match ("boardflags", "0x1658") || nvram_match ("boardflags", "0x2658")))
595         {
596         nvram_set ("buffalo_hp", "1");
597 #ifndef HAVE_BUFFALO  // if HAVE_BUFFALO not used to be FCC/CE valid   
598         nvram_set ("boardflags", "0x3658");  // enable high gain PA
599 #endif
600         }
601       break;
602      
603     case ROUTER_BUFFALO_WHRG54S:  //for HP only
604       if (!nvram_match ("buffalo_hp", "1") && nvram_match ("boardflags", "0x1758"))
605         {
606             nvram_set ("buffalo_hp", "1");
607 #ifndef HAVE_BUFFALO  // if HAVE_BUFFALO not used to be FCC/CE valid
608         nvram_set ("boardflags", "0x3758");  // enable high gain PA
609 #endif
610         }
611       break;
612     }
613
614   /* Modules */
615   uname (&name);
616
617
618   snprintf (buf, sizeof (buf), "/lib/modules/%s", name.release);
619   if (stat ("/proc/modules", &tmp_stat) == 0 && stat (buf, &tmp_stat) == 0)
620     {
621       char module[80], *modules, *next;
622       //modules="wl switch-core";
623       nvram_set ("portprio_support", "1");
624
625       if (check_vlan_support () && check_hw_type () != BCM5325E_CHIP)
626         {
627           switch (brand)
628             {
629             case ROUTER_WRT350N:
630             case ROUTER_WRT600N:
631             case ROUTER_BUFFALO_WZRG144NH:
632               nvram_set ("portprio_support", "0");
633               modules = "bcm57xxlsys";
634               break;
635             case ROUTER_LINKSYS_WRT55AG:
636             case ROUTER_MOTOROLA:
637             case ROUTER_BUFFALO_WBR2G54S:
638             case ROUTER_DELL_TRUEMOBILE_2300_V2:
639               modules =
640                 nvram_invmatch ("ct_modules",
641                                 "") ? nvram_safe_get ("ct_modules") :
642                 "switch-core switch-adm";
643               break;
644              
645             case ROUTER_WRT54G_V8:
646             case ROUTER_ASUS_WL520GUGC:
647               modules =
648                 nvram_invmatch ("ct_modules",
649                                 "") ? nvram_safe_get ("ct_modules") :
650                 "switch-core switch-robo";
651                   break;
652                  
653             case ROUTER_WRT54G1X:
654             case ROUTER_WRT54G:
655               modules = "diag";
656               eval ("insmod", "switch-core");
657               if (eval ("insmod", "switch-robo"))
658                 eval ("insmod", "switch-adm");
659               break;
660
661             case ROUTER_RT480W:
662             case ROUTER_BUFFALO_WLI2_TX1_G54:
663               modules =
664                 nvram_invmatch ("ct_modules",
665                                 "") ? nvram_safe_get ("ct_modules") : "";
666               eval ("insmod", "switch-core");
667               if (eval ("insmod", "switch-robo"))
668                 eval ("insmod", "switch-adm");
669               break;
670
671             case ROUTER_WRT54G3G:
672               modules =
673                 nvram_invmatch ("ct_modules",
674                                 "") ? nvram_safe_get ("ct_modules") :
675                 "switch-core switch-robo pcmcia_core yenta_socket ds serial_cs usbcore usb-ohci usbserial sierra";
676               break;
677
678             default:
679
680               modules =
681                 nvram_invmatch ("ct_modules",
682                                 "") ? nvram_safe_get ("ct_modules") :
683                 "switch-core switch-robo";
684               break;
685             }
686         }
687       else
688         {
689           switch (brand)
690             {
691             case ROUTER_WRT350N:
692             case ROUTER_WRT600N:
693             case ROUTER_BUFFALO_WZRG144NH:
694               nvram_set ("portprio_support", "0");
695               modules = "bcm57xxlsys";
696               break;
697             case ROUTER_LINKSYS_WRT55AG:
698               modules =
699                 nvram_invmatch ("ct_modules",
700                                 "") ? nvram_safe_get ("ct_modules") :
701                 "switch-core switch-adm";
702
703               break;
704             case ROUTER_ASUS_WL500GD:
705             case ROUTER_ASUS_WL550GE:
706           modules =
707                 nvram_invmatch ("ct_modules",
708                                 "") ? nvram_safe_get ("ct_modules") :
709                 "switch-core switch-robo";
710               break;
711             case ROUTER_BUFFALO_WZRRSG54:
712               nvram_set ("portprio_support", "0");
713               modules =
714                 nvram_invmatch ("ct_modules",
715                                 "") ? nvram_safe_get ("ct_modules") : "";
716               break;
717             case ROUTER_WRT54G3G:
718               if (check_vlan_support ())
719                 modules =
720                   nvram_invmatch ("ct_modules",
721                                   "") ? nvram_safe_get ("ct_modules") :
722                   "switch-core switch-robo pcmcia_core yenta_socket ds";
723               else
724                 {
725                   nvram_set ("portprio_support", "0");
726
727                   modules =
728                     nvram_invmatch ("ct_modules",
729                                     "") ? nvram_safe_get ("ct_modules") :
730                     "pcmcia_core yenta_socket ds";
731                 }
732               break;
733
734             default:
735               if (check_vlan_support ())
736                 modules =
737                   nvram_invmatch ("ct_modules",
738                                   "") ? nvram_safe_get ("ct_modules") :
739                   "switch-core switch-robo";
740               else
741                 {
742                   nvram_set ("portprio_support", "0");
743                   modules =
744                     nvram_invmatch ("ct_modules",
745                                     "") ? nvram_safe_get ("ct_modules") : "";
746                 }
747               break;
748             }
749         }
750       cprintf ("insmod %s\n", modules);
751
752       foreach (module, modules, next)
753       {
754 #ifdef HAVE_MACBIND
755         if (nvram_match ("et0macaddr", MACBRAND))
756           eval ("insmod", module);
757 #else
758
759         cprintf ("loading %s\n", module);
760         eval ("insmod", module);
761         cprintf ("done\n");
762 #endif
763       }
764
765       loadWlModule ();
766
767 #ifdef HAVE_USB
768 //load usb driver. we will add samba server, ftp server and ctorrent support in future
769       modules =
770         "usbcore usb-ohci usb-uhci ehci-hcd scsi_mod usb-storage ide-core ide-detect ide-disk ide-scsi cdrom ide-cd printer sd_mod sr_mod"
771         foreach (module, modules, next)
772       {
773         cprintf ("loading %s\n", module);
774         eval ("insmod", module);
775       }
776 #endif
777
778     }
779   /* Set a sane date */
780   stime (&tm);
781
782   led_control (LED_POWER, LED_ON);
783   led_control (LED_SES, LED_OFF);
784   led_control (LED_BRIDGE, LED_OFF);
785   led_control (LED_WLAN, LED_OFF);
786
787   if (brand == ROUTER_WRT54G3G)
788     {
789       eval ("cardmgr");
790     }
791
792   cprintf ("done\n");
793   return 0;
794
795 }
796 static int
797 check_nv (char *name, char *value)
798 {
799   int ret = 0;
800   if (nvram_match ("manual_boot_nv", "1"))
801     return 0;
802
803   if (!nvram_get (name))
804     {
805       cprintf ("ERR: Cann't find %s !.......................\n", name);
806       nvram_set (name, value);
807       ret++;
808     }
809   else if (nvram_invmatch (name, value))
810     {
811       cprintf ("ERR: The %s is %s, not %s !.................\n", name,
812                nvram_safe_get (name), value);
813       nvram_set (name, value);
814       ret++;
815     }
816
817   return ret;
818 }
819
820 int
821 check_cfe_nv (void)
822 {
823   int ret = 0;
824   switch (getRouterBrand ())
825     {
826     case ROUTER_BUFFALO_WZRRSG54:
827       ret += check_nv ("lan_hwnames", "et0 wl0");
828       ret += check_nv ("wan_hwname", "et1");
829       ret += check_nv ("vlans", "0");
830       break;
831     case ROUTER_BUFFALO_WBR2G54S:
832       ret += check_nv ("aa0", "3");
833
834       ret += check_nv ("pa0itssit", "62");
835       ret += check_nv ("pa0b0", "0x1136");
836       ret += check_nv ("pa0b1", "0xfb93");
837       ret += check_nv ("pa0b2", "0xfea5");
838 #ifndef HAVE_MSSID
839       ret += check_nv ("pa0maxpwr", "60");
840 #endif
841       ret += check_nv ("wl0gpio2", "0");
842       ret += check_nv ("wl0gpio3", "0");
843       ret += check_nv ("cctl", "0");
844       ret += check_nv ("ccode", "0");
845       break;
846 #ifndef HAVE_BUFFALO
847
848     case ROUTER_WRT54G:
849     case ROUTER_WRT54G_V8:
850       ret += check_nv ("aa0", "3");
851       if (check_hw_type () == BCM5352E_CHIP
852           || check_hw_type () == BCM5354G_CHIP)
853         ret += check_nv ("ag0", "0x02");
854       else
855         ret += check_nv ("ag0", "255");
856       if (check_hw_type () == BCM5325E_CHIP)
857         {
858           /* Lower the DDR ram drive strength , the value will be stable for all boards
859              Latency 3 is more stable for all ddr 20050420 by honor */
860
861           ret += check_nv ("sdram_init", "0x010b");
862           ret += check_nv ("sdram_config", "0x0062");
863
864           if (nvram_match ("clkfreq", "200")
865               && nvram_match ("overclocking", "200"))
866             {
867               ret += check_nv ("clkfreq", "216");
868               nvram_set ("overclocking", "216");
869             }
870
871           if (ret)
872             {
873               nvram_set ("sdram_ncdl", "0x0");
874
875             }
876           ret += check_nv ("pa0itssit", "62");
877           ret += check_nv ("pa0b0", "0x15eb");
878           ret += check_nv ("pa0b1", "0xfa82");
879           ret += check_nv ("pa0b2", "0xfe66");
880 #ifndef HAVE_MSSID
881           ret += check_nv ("pa0maxpwr", "0x4e");
882 #endif
883         }
884       else if (check_hw_type () == BCM5354G_CHIP)
885         {
886           ret += check_nv ("pa0itssit", "62");
887           ret += check_nv ("pa0b0", "0x1326");
888           ret += check_nv ("pa0b1", "0xFB51");
889           ret += check_nv ("pa0b2", "0xFE87");
890           ret += check_nv ("reset_gpio", "7");
891         }
892       else if (check_hw_type () == BCM4705_BCM5397_EWC_CHIP)
893         {
894           // nothing to do
895         }
896       else if (check_hw_type () == BCM4704_BCM5325F_CHIP)
897         {
898           //nothing to do
899         }
900       else
901         {
902           ret += check_nv ("pa0itssit", "62");
903           ret += check_nv ("pa0b0", "0x170c");
904           ret += check_nv ("pa0b1", "0xfa24");
905           ret += check_nv ("pa0b2", "0xfe70");
906 #ifndef HAVE_MSSID
907           ret += check_nv ("pa0maxpwr", "0x48");
908 #endif
909         }
910
911       //ret += check_nv("gpio2", "adm_eecs");
912       //ret += check_nv("gpio3", "adm_eesk");
913       //ret += check_nv("gpio5", "adm_eedi");
914       //ret += check_nv("gpio6", "adm_rc");
915
916       ret += check_nv ("wl0gpio2", "0");
917       ret += check_nv ("wl0gpio3", "0");
918
919       ret += check_nv ("cctl", "0");
920       ret += check_nv ("ccode", "0");
921       break;
922 #endif
923     }
924   if (ret)
925     {
926       cprintf ("Some error found, we want to reboot!.....................\n");
927       nvram_commit ();
928       kill (1, SIGTERM);
929       exit (0);
930     }
931
932
933   return ret;
934 }
935
936 int
937 check_pmon_nv (void)
938 {
939   return 0;
940 }
941
942
943 void
944 start_overclocking (void)
945 {
946 #ifdef HAVE_OVERCLOCKING
947   cprintf ("Overclocking started\n");
948  
949   int rev = cpu_plltype ();
950   if (rev == 0)
951     return;                     //unsupported
952    
953   char *ov = nvram_get ("overclocking");
954   if (ov == NULL)
955     return;
956   int clk = atoi (ov);
957
958   if (nvram_get ("clkfreq") == NULL)
959     return;                     //unsupported
960
961
962   char *pclk = nvram_safe_get ("clkfreq");
963   char dup[64];
964   strcpy (dup, pclk);
965   int i;
966   for (i = 0; i < strlen (dup); i++)
967     if (dup[i] == ',')
968       dup[i] = 0;
969   int cclk = atoi (dup);
970   if ((cclk < 150 && rev == 3) || (cclk < 192 && rev == 4) || (cclk < 183 && rev == 7))
971     {
972       cprintf ("clkfreq is %d (%s), this is unsupported\n", cclk, dup);
973       return;                   //unsupported
974     }
975
976   if (clk == cclk)
977     {
978       cprintf ("clkfreq identical with new setting\n");
979       return;                   //clock already set
980     }
981
982
983   int set = 1;
984   int clk2 = 0;
985   char clkfr[16];
986
987   switch (clk)
988     {
989     case 150:
990       clk2 = 75;
991 //      nvram_set ("clkfreq", "150,75");
992       break;       
993     case 183:
994       clk2 = 92;
995 //      nvram_set ("clkfreq", "183,92");
996       break;
997     case 187:
998       clk2 = 94;
999 //      nvram_set ("clkfreq", "187,94");
1000       break;
1001     case 192:
1002       clk2 = 96;
1003 //      nvram_set ("clkfreq", "192,96");
1004       break;
1005     case 198:
1006       clk2 = 98;
1007 //      nvram_set ("clkfreq", "198,98");
1008       break;
1009     case 200:
1010       clk2 = 100;
1011 //      nvram_set ("clkfreq", "200,100");
1012       break;
1013     case 216:
1014       clk2 = 108;
1015 //      nvram_set ("clkfreq", "216,108");
1016       break;
1017     case 225:
1018       clk2 = 113;
1019 //      nvram_set ("clkfreq", "225,113");
1020       break;
1021     case 228:
1022       clk2 = 114;
1023 //      nvram_set ("clkfreq", "228,114");
1024       break;
1025     case 233:
1026       clk2 = 116;
1027 //      nvram_set ("clkfreq", "233,116");
1028       break;
1029     case 237:
1030       clk2 = 119;
1031 //     nvram_set ("clkfreq", "237,119");
1032       break;
1033     case 240:
1034       clk2 = 120;
1035 //      nvram_set ("clkfreq", "240,120");
1036       break;
1037     case 250:
1038       clk2 = 125;
1039 //      nvram_set ("clkfreq", "250,125");
1040       break;
1041     case 252:
1042       clk2 = 126;
1043 //      nvram_set ("clkfreq", "252,126");
1044       break;
1045     case 264:
1046       clk2 = 132;
1047 //      nvram_set ("clkfreq", "264,132");
1048       break;
1049     case 280:
1050       clk2 = 120;
1051 //      nvram_set ("clkfreq", "280,120");
1052       break;
1053     case 300:
1054       clk2 = 120;
1055 //      nvram_set ("clkfreq", "300,120");
1056       break;
1057     default:
1058       set = 0;
1059       break;
1060     }
1061
1062   if (set)
1063     {
1064       cprintf ("clock frequency adjusted from %d to %d, reboot needed\n",
1065                cclk, clk);
1066       sprintf (clkfr, "%d,%d", clk, clk2);
1067       nvram_set ("clkfreq", clkfr);
1068       nvram_commit ();
1069       cprintf ("Overclocking done, rebooting...\n");
1070       kill (1, SIGTERM);
1071       exit (0);
1072     }
1073 #endif
1074 }
1075
Note: See TracBrowser for help on using the browser.