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

Revision 8453, 27.2 kB (checked in by eko, 2 years ago)

better be lanmac+2

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