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

Revision 8455, 27.5 kB (checked in by eko, 2 years ago)

set il0macaddress and reboot if needed.

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   int need_reboot = 0;
365  
366   switch (brand)
367     {
368     case ROUTER_BUFFALO_WZRRSG54:
369       check_brcm_cpu_type ();
370       setup_4712 ();
371           nvram_set ("lan_ifnames", "eth0 eth2");
372       nvram_set ("wan_ifname", "eth1");
373       nvram_set ("wl0_ifname", "eth2");
374       break;
375
376     case ROUTER_MOTOROLA:
377       nvram_set ("cpu_type", "BCM4712");
378       setup_4712 ();
379       break;
380
381     case ROUTER_RT480W:
382     case ROUTER_USR_5461:
383       setup_4712 ();
384       break;
385
386     case ROUTER_BELKIN_F5D7231:
387       nvram_set ("lan_ifnames", "vlan0 eth1");
388       nvram_set ("wan_ifname", "vlan1");
389       nvram_set ("wl0_ifname", "eth1");
390       if (nvram_match ("vlan1ports", "0 5u"))
391          nvram_set ("vlan1ports", "0 5");
392       break;     
393      
394     case ROUTER_RT210W:
395       setup_4712 ();
396       nvram_set ("wan_ifname", "eth1"); // fix for Belkin f5d7230 v1000 WAN problem.
397       if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
398         {
399           nvram_set ("et0macaddr", "00:16:E3:00:00:10");        //fix for missing cfe default = dead LAN ports.
400           need_reboot = 1;
401         }
402       break;
403
404     case ROUTER_BRCM4702_GENERIC:
405     case ROUTER_ASUS_WL500G:
406       setup_4712 ();
407       nvram_set ("wan_ifname", "eth1"); // fix for Belkin f5d7230 v1000 WAN problem.
408
409       if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
410         {
411           nvram_set ("et0macaddr", "00:0C:6E:00:00:10");        //fix for missing cfe default = dead LAN ports.
412           need_reboot = 1;
413         }
414       break;
415
416     case ROUTER_DELL_TRUEMOBILE_2300:
417       setup_4712 ();
418       nvram_set ("wan_ifname", "eth1"); // fix for WAN problem.
419       break;
420
421     case ROUTER_BUFFALO_WBR54G: //for WLA-G54
422           nvram_set ("lan_ifnames", "eth0 eth2");
423       nvram_set ("wan_ifname", "eth1");
424       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
425         {
426           nvram_set ("lan_ifnames", "eth2");
427           nvram_set ("wan_ifname", "eth0");
428         }
429       break;
430
431     case ROUTER_BUFFALO_WLI2_TX1_G54:
432     case ROUTER_BUFFALO_WLAG54C:
433     case ROUTER_WAP54G_V1:
434     case ROUTER_SITECOM_WL105B:
435       nvram_set ("lan_ifnames", "eth1 eth2");
436       nvram_set ("wl0_ifname", "eth2");
437       nvram_set ("wan_ifname", "eth0"); //WAN to nonexist. iface.
438       nvram_set ("port_swap", "1");
439       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
440         {
441           nvram_set ("lan_ifnames", "eth2");
442           nvram_set ("wan_ifname", "eth1");
443         }
444       break;
445
446     case ROUTER_SITECOM_WL111:
447       nvram_set ("lan_ifnames", "eth0 eth2");
448       nvram_set ("wl0_ifname", "eth2");
449       nvram_set ("wan_ifname", "eth1");
450       break;
451
452     case ROUTER_MOTOROLA_WE800G:
453       nvram_set ("lan_ifnames", "eth1 eth2");
454       nvram_set ("wl0_ifname", "eth2");
455       nvram_set ("wan_ifname", "eth0"); //WAN to nonexist. iface.
456       nvram_set ("port_swap", "1");
457       eval ("gpio", "disable", "7");
458       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
459         {
460           nvram_set ("lan_ifnames", "eth2");
461           nvram_set ("wan_ifname", "eth1");
462         }
463       break;
464
465     case ROUTER_MOTOROLA_V1:
466       nvram_set ("wan_ifname", "eth1");
467       eval ("gpio", "disable", "7");
468       break;
469
470     case ROUTER_BUFFALO_WZRG300N:
471     case ROUTER_NETGEAR_WNR834B:
472     case ROUTER_WRT150N:
473     case ROUTER_WRT300N:
474     case ROUTER_ASUS_WL500W:
475     case ROUTER_BUFFALO_WLAH_G54:
476     case ROUTER_BUFFALO_WAPM_HP_AM54G54:
477     case ROUTER_WRTSL54GS:
478     case ROUTER_MICROSOFT_MN700:
479       nvram_set ("wan_ifname", "eth1");
480       break;
481
482     case ROUTER_WRT54G1X:
483       if (check_vlan_support ())
484         {
485           nvram_set ("lan_ifnames", "vlan0 eth2");
486           nvram_set ("wan_ifname", "vlan1");
487         }
488       break;
489
490     case ROUTER_WRT350N:
491       nvram_set ("wan_ifname", "vlan2");
492       break;
493     case ROUTER_WRT600N:
494       nvram_set ("wan_ifname", "vlan2");
495       break;
496
497     case ROUTER_BUFFALO_WZRG144NH:
498       nvram_set ("wan_ifname", "vlan1");
499       break;
500
501     case ROUTER_ASUS_WL500G_PRE:
502       nvram_set ("sdram_init", "0x0009");
503 //      nvram_set ("sdram_ncdl", "0x208");
504       nvram_set ("lan_ifnames", "vlan0 eth2");
505       nvram_set ("wl0_ifname", "eth2");
506       nvram_set ("wan_ifname", "vlan1");        // fix for Asus WL500gPremium WAN problem.
507       if (nvram_match ("vlan1ports", "0 5u"))
508          nvram_set ("vlan1ports", "0 5");
509       break;
510
511     case ROUTER_ASUS_WL500GD:
512     case ROUTER_ASUS_WL550GE:
513       nvram_set ("wl0_ifname", "eth1");
514       break;
515
516     case ROUTER_BUFFALO_WLA2G54C:
517     case ROUTER_WAP54G_V2:
518     case ROUTER_VIEWSONIC_WAPBR_100:
519     case ROUTER_USR_5430:
520     case ROUTER_BUFFALO_WLI_TX4_G54HP:
521     case ROUTER_BELKIN_F5D7230_V2000:
522     case ROUTER_NETGEAR_WG602_V3:
523       nvram_set ("lan_ifnames", "eth0 eth1");
524       nvram_set ("wl0_ifname", "eth1");
525       nvram_set ("wan_ifname", "eth2"); // map WAN port to nonexistant interface
526       if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
527         {
528           nvram_set ("lan_ifnames", "eth1");
529           nvram_set ("wan_ifname", "eth0");
530         }
531       break;
532
533     case ROUTER_DELL_TRUEMOBILE_2300_V2:        //we must fix cfe defaults with CR added
534       nvram_set ("vlan0hwname", "et0");
535       nvram_set ("vlan1hwname", "et0");
536       nvram_set ("et0mdcport", "0");
537       nvram_set ("et0phyaddr", "30");
538       nvram_set ("gpio2", "adm_eecs");
539       nvram_set ("gpio3", "adm_eesk");
540       nvram_set ("gpio4", "adm_eedi");
541       nvram_set ("gpio5", "adm_rc");
542       nvram_unset ("gpio6");
543       break;
544      
545     case ROUTER_WRT54G_V8:
546       nvram_set ("reset_gpio", "7");
547       break;
548      
549     case ROUTER_ASUS_WL520GUGC:     
550       if (nvram_match ("vlan1ports", "0 5u"))
551          nvram_set ("vlan1ports", "0 5");
552       break;
553            
554     case ROUTER_LINKSYS_WTR54GS:
555         eval ("gpio", "enable", "3");  //prevent reboot loop on reset
556         break;
557            
558     case ROUTER_WAP54G_V3:
559         eval ("gpio", "enable", "0");  //reset gpio 0 for reset button
560 //      nvram_set ("vlan0ports", "1 5*");
561 //      nvram_set ("vlan1ports", "4 5");
562 //      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))      // = no lan
563 //      {
564 //        nvram_set ("vlan0ports", "4 5*");
565 //        nvram_set ("vlan1ports", "1 5");
566 //      }
567       break;
568
569    }
570    
571   /* fix il0macaddr to be lanmac+2 */
572   if (nvram_get ("il0macaddr") = NULL)
573     need_reboot = 1;
574  
575   unsigned char mac[20];
576   if (nvram_match ("port_swap", "1"))
577     strcpy (mac, nvram_safe_get ("et1macaddr"));
578   else
579     strcpy (mac, nvram_safe_get ("et0macaddr"));
580   MAC_ADD (mac);
581   MAC_ADD (mac);
582   nvram_set ("il0macaddr", mac);
583    
584   /* ifnames */
585   strcpy (wanifname, nvram_safe_get ("wan_ifname"));
586   strcpy (wlifname, nvram_safe_get ("wl0_ifname"));
587
588   /* set wan_ifnames, pppoe_wan_ifname and pppoe_ifname*/
589   nvram_set ("wan_ifnames", wanifname);
590   nvram_set ("pppoe_wan_ifname", wanifname);
591   nvram_set ("pppoe_ifname", wanifname);
592  
593   /* additional boardflags adjustment */
594   switch (brand)
595     {
596     case ROUTER_BELKIN_F5D7231:     
597       if (nvram_match ("boardflags", "0x388") || nvram_match ("boardflags", "0x0388"))
598          nvram_set ("boardflags", "0x0f58");
599       break;
600      
601     case ROUTER_BUFFALO_WLI_TX4_G54HP:
602       if (!nvram_match ("buffalo_hp", "1")
603        && (nvram_match ("boardflags", "0x1658") || nvram_match ("boardflags", "0x2658")))
604         {
605         nvram_set ("buffalo_hp", "1");
606 #ifndef HAVE_BUFFALO  // if HAVE_BUFFALO not used to be FCC/CE valid   
607         nvram_set ("boardflags", "0x3658");  // enable high gain PA
608 #endif
609         }
610       break;
611      
612     case ROUTER_BUFFALO_WHRG54S:  //for HP only
613       if (!nvram_match ("buffalo_hp", "1") && nvram_match ("boardflags", "0x1758"))
614         {
615             nvram_set ("buffalo_hp", "1");
616 #ifndef HAVE_BUFFALO  // if HAVE_BUFFALO not used to be FCC/CE valid
617         nvram_set ("boardflags", "0x3758");  // enable high gain PA
618 #endif
619         }
620       break;
621     }
622    
623   if (need_reboot)
624     {
625       cprintf ("Need reboot now to set some mac addresses\n");
626       nvram_commit ();
627       kill (1, SIGTERM);
628       exit (0);
629     }
630
631   /* Modules */
632   uname (&name);
633
634
635   snprintf (buf, sizeof (buf), "/lib/modules/%s", name.release);
636   if (stat ("/proc/modules", &tmp_stat) == 0 && stat (buf, &tmp_stat) == 0)
637     {
638       char module[80], *modules, *next;
639       //modules="wl switch-core";
640       nvram_set ("portprio_support", "1");
641
642       if (check_vlan_support () && check_hw_type () != BCM5325E_CHIP)
643         {
644           switch (brand)
645             {
646             case ROUTER_WRT350N:
647             case ROUTER_WRT600N:
648             case ROUTER_BUFFALO_WZRG144NH:
649               nvram_set ("portprio_support", "0");
650               modules = "bcm57xxlsys";
651               break;
652             case ROUTER_LINKSYS_WRT55AG:
653             case ROUTER_MOTOROLA:
654             case ROUTER_BUFFALO_WBR2G54S:
655             case ROUTER_DELL_TRUEMOBILE_2300_V2:
656               modules =
657                 nvram_invmatch ("ct_modules",
658                                 "") ? nvram_safe_get ("ct_modules") :
659                 "switch-core switch-adm";
660               break;
661              
662             case ROUTER_WRT54G_V8:
663             case ROUTER_ASUS_WL520GUGC:
664               modules =
665                 nvram_invmatch ("ct_modules",
666                                 "") ? nvram_safe_get ("ct_modules") :
667                 "switch-core switch-robo";
668                   break;
669                  
670             case ROUTER_WRT54G1X:
671             case ROUTER_WRT54G:
672               modules = "diag";
673               eval ("insmod", "switch-core");
674               if (eval ("insmod", "switch-robo"))
675                 eval ("insmod", "switch-adm");
676               break;
677
678             case ROUTER_RT480W:
679             case ROUTER_BUFFALO_WLI2_TX1_G54:
680               modules =
681                 nvram_invmatch ("ct_modules",
682                                 "") ? nvram_safe_get ("ct_modules") : "";
683               eval ("insmod", "switch-core");
684               if (eval ("insmod", "switch-robo"))
685                 eval ("insmod", "switch-adm");
686               break;
687
688             case ROUTER_WRT54G3G:
689               modules =
690                 nvram_invmatch ("ct_modules",
691                                 "") ? nvram_safe_get ("ct_modules") :
692                 "switch-core switch-robo pcmcia_core yenta_socket ds serial_cs usbcore usb-ohci usbserial sierra";
693               break;
694
695             default:
696
697               modules =
698                 nvram_invmatch ("ct_modules",
699                                 "") ? nvram_safe_get ("ct_modules") :
700                 "switch-core switch-robo";
701               break;
702             }
703         }
704       else
705         {
706           switch (brand)
707             {
708             case ROUTER_WRT350N:
709             case ROUTER_WRT600N:
710             case ROUTER_BUFFALO_WZRG144NH:
711               nvram_set ("portprio_support", "0");
712               modules = "bcm57xxlsys";
713               break;
714             case ROUTER_LINKSYS_WRT55AG:
715               modules =
716                 nvram_invmatch ("ct_modules",
717                                 "") ? nvram_safe_get ("ct_modules") :
718                 "switch-core switch-adm";
719
720               break;
721             case ROUTER_ASUS_WL500GD:
722             case ROUTER_ASUS_WL550GE:
723           modules =
724                 nvram_invmatch ("ct_modules",
725                                 "") ? nvram_safe_get ("ct_modules") :
726                 "switch-core switch-robo";
727               break;
728             case ROUTER_BUFFALO_WZRRSG54:
729               nvram_set ("portprio_support", "0");
730               modules =
731                 nvram_invmatch ("ct_modules",
732                                 "") ? nvram_safe_get ("ct_modules") : "";
733               break;
734             case ROUTER_WRT54G3G:
735               if (check_vlan_support ())
736                 modules =
737                   nvram_invmatch ("ct_modules",
738                                   "") ? nvram_safe_get ("ct_modules") :
739                   "switch-core switch-robo pcmcia_core yenta_socket ds";
740               else
741                 {
742                   nvram_set ("portprio_support", "0");
743
744                   modules =
745                     nvram_invmatch ("ct_modules",
746                                     "") ? nvram_safe_get ("ct_modules") :
747                     "pcmcia_core yenta_socket ds";
748                 }
749               break;
750
751             default:
752               if (check_vlan_support ())
753                 modules =
754                   nvram_invmatch ("ct_modules",
755                                   "") ? nvram_safe_get ("ct_modules") :
756                   "switch-core switch-robo";
757               else
758                 {
759                   nvram_set ("portprio_support", "0");
760                   modules =
761                     nvram_invmatch ("ct_modules",
762                                     "") ? nvram_safe_get ("ct_modules") : "";
763                 }
764               break;
765             }
766         }
767       cprintf ("insmod %s\n", modules);
768
769       foreach (module, modules, next)
770       {
771 #ifdef HAVE_MACBIND
772         if (nvram_match ("et0macaddr", MACBRAND))
773           eval ("insmod", module);
774 #else
775
776         cprintf ("loading %s\n", module);
777         eval ("insmod", module);
778         cprintf ("done\n");
779 #endif
780       }
781
782       loadWlModule ();
783
784 #ifdef HAVE_USB
785 //load usb driver. we will add samba server, ftp server and ctorrent support in future
786       modules =
787         "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"
788         foreach (module, modules, next)
789       {
790         cprintf ("loading %s\n", module);
791         eval ("insmod", module);
792       }
793 #endif
794
795     }
796   /* Set a sane date */
797   stime (&tm);
798
799   led_control (LED_POWER, LED_ON);
800   led_control (LED_SES, LED_OFF);
801   led_control (LED_BRIDGE, LED_OFF);
802   led_control (LED_WLAN, LED_OFF);
803
804   if (brand == ROUTER_WRT54G3G)
805     {
806       eval ("cardmgr");
807     }
808
809   cprintf ("done\n");
810   return 0;
811
812 }
813 static int
814 check_nv (char *name, char *value)
815 {
816   int ret = 0;
817   if (nvram_match ("manual_boot_nv", "1"))
818     return 0;
819
820   if (!nvram_get (name))
821     {
822       cprintf ("ERR: Cann't find %s !.......................\n", name);
823       nvram_set (name, value);
824       ret++;
825     }
826   else if (nvram_invmatch (name, value))
827     {
828       cprintf ("ERR: The %s is %s, not %s !.................\n", name,
829                nvram_safe_get (name), value);
830       nvram_set (name, value);
831       ret++;
832     }
833
834   return ret;
835 }
836
837 int
838 check_cfe_nv (void)
839 {
840   int ret = 0;
841   switch (getRouterBrand ())
842     {
843     case ROUTER_BUFFALO_WZRRSG54:
844       ret += check_nv ("lan_hwnames", "et0 wl0");
845       ret += check_nv ("wan_hwname", "et1");
846       ret += check_nv ("vlans", "0");
847       break;
848     case ROUTER_BUFFALO_WBR2G54S:
849       ret += check_nv ("aa0", "3");
850
851       ret += check_nv ("pa0itssit", "62");
852       ret += check_nv ("pa0b0", "0x1136");
853       ret += check_nv ("pa0b1", "0xfb93");
854       ret += check_nv ("pa0b2", "0xfea5");
855 #ifndef HAVE_MSSID
856       ret += check_nv ("pa0maxpwr", "60");
857 #endif
858       ret += check_nv ("wl0gpio2", "0");
859       ret += check_nv ("wl0gpio3", "0");
860       ret += check_nv ("cctl", "0");
861       ret += check_nv ("ccode", "0");
862       break;
863 #ifndef HAVE_BUFFALO
864
865     case ROUTER_WRT54G:
866     case ROUTER_WRT54G_V8:
867       ret += check_nv ("aa0", "3");
868       if (check_hw_type () == BCM5352E_CHIP
869           || check_hw_type () == BCM5354G_CHIP)
870         ret += check_nv ("ag0", "0x02");
871       else
872         ret += check_nv ("ag0", "255");
873       if (check_hw_type () == BCM5325E_CHIP)
874         {
875           /* Lower the DDR ram drive strength , the value will be stable for all boards
876              Latency 3 is more stable for all ddr 20050420 by honor */
877
878           ret += check_nv ("sdram_init", "0x010b");
879           ret += check_nv ("sdram_config", "0x0062");
880
881           if (nvram_match ("clkfreq", "200")
882               && nvram_match ("overclocking", "200"))
883             {
884               ret += check_nv ("clkfreq", "216");
885               nvram_set ("overclocking", "216");
886             }
887
888           if (ret)
889             {
890               nvram_set ("sdram_ncdl", "0x0");
891
892             }
893           ret += check_nv ("pa0itssit", "62");
894           ret += check_nv ("pa0b0", "0x15eb");
895           ret += check_nv ("pa0b1", "0xfa82");
896           ret += check_nv ("pa0b2", "0xfe66");
897 #ifndef HAVE_MSSID
898           ret += check_nv ("pa0maxpwr", "0x4e");
899 #endif
900         }
901       else if (check_hw_type () == BCM5354G_CHIP)
902         {
903           ret += check_nv ("pa0itssit", "62");
904           ret += check_nv ("pa0b0", "0x1326");
905           ret += check_nv ("pa0b1", "0xFB51");
906           ret += check_nv ("pa0b2", "0xFE87");
907           ret += check_nv ("reset_gpio", "7");
908         }
909       else if (check_hw_type () == BCM4705_BCM5397_EWC_CHIP)
910         {
911           // nothing to do
912         }
913       else if (check_hw_type () == BCM4704_BCM5325F_CHIP)
914         {
915           //nothing to do
916         }
917       else
918         {
919           ret += check_nv ("pa0itssit", "62");
920           ret += check_nv ("pa0b0", "0x170c");
921           ret += check_nv ("pa0b1", "0xfa24");
922           ret += check_nv ("pa0b2", "0xfe70");
923 #ifndef HAVE_MSSID
924           ret += check_nv ("pa0maxpwr", "0x48");
925 #endif
926         }
927
928       //ret += check_nv("gpio2", "adm_eecs");
929       //ret += check_nv("gpio3", "adm_eesk");
930       //ret += check_nv("gpio5", "adm_eedi");
931       //ret += check_nv("gpio6", "adm_rc");
932
933       ret += check_nv ("wl0gpio2", "0");
934       ret += check_nv ("wl0gpio3", "0");
935
936       ret += check_nv ("cctl", "0");
937       ret += check_nv ("ccode", "0");
938       break;
939 #endif
940     }
941   if (ret)
942     {
943       cprintf ("Some error found, we want to reboot!.....................\n");
944       nvram_commit ();
945       kill (1, SIGTERM);
946       exit (0);
947     }
948
949
950   return ret;
951 }
952
953 int
954 check_pmon_nv (void)
955 {
956   return 0;
957 }
958
959
960 void
961 start_overclocking (void)
962 {
963 #ifdef HAVE_OVERCLOCKING
964   cprintf ("Overclocking started\n");
965  
966   int rev = cpu_plltype ();
967   if (rev == 0)
968     return;                     //unsupported
969    
970   char *ov = nvram_get ("overclocking");
971   if (ov == NULL)
972     return;
973   int clk = atoi (ov);
974
975   if (nvram_get ("clkfreq") == NULL)
976     return;                     //unsupported
977
978
979   char *pclk = nvram_safe_get ("clkfreq");
980   char dup[64];
981   strcpy (dup, pclk);
982   int i;
983   for (i = 0; i < strlen (dup); i++)
984     if (dup[i] == ',')
985       dup[i] = 0;
986   int cclk = atoi (dup);
987   if ((cclk < 150 && rev == 3) || (cclk < 192 && rev == 4) || (cclk < 183 && rev == 7))
988     {
989       cprintf ("clkfreq is %d (%s), this is unsupported\n", cclk, dup);
990       return;                   //unsupported
991     }
992
993   if (clk == cclk)
994     {
995       cprintf ("clkfreq identical with new setting\n");
996       return;                   //clock already set
997     }
998
999
1000   int set = 1;
1001   int clk2 = 0;
1002   char clkfr[16];
1003
1004   switch (clk)
1005     {
1006     case 150:
1007       clk2 = 75;
1008 //      nvram_set ("clkfreq", "150,75");
1009       break;       
1010     case 183:
1011       clk2 = 92;
1012 //      nvram_set ("clkfreq", "183,92");
1013       break;
1014     case 187:
1015       clk2 = 94;
1016 //      nvram_set ("clkfreq", "187,94");
1017       break;
1018     case 192:
1019       clk2 = 96;
1020 //      nvram_set ("clkfreq", "192,96");
1021       break;
1022     case 198:
1023       clk2 = 98;
1024 //      nvram_set ("clkfreq", "198,98");
1025       break;
1026     case 200:
1027       clk2 = 100;
1028 //      nvram_set ("clkfreq", "200,100");
1029       break;
1030     case 216:
1031       clk2 = 108;
1032 //      nvram_set ("clkfreq", "216,108");
1033       break;
1034     case 225:
1035       clk2 = 113;
1036 //      nvram_set ("clkfreq", "225,113");
1037       break;
1038     case 228:
1039       clk2 = 114;
1040 //      nvram_set ("clkfreq", "228,114");
1041       break;
1042     case 233:
1043       clk2 = 116;
1044 //      nvram_set ("clkfreq", "233,116");
1045       break;
1046     case 237:
1047       clk2 = 119;
1048 //     nvram_set ("clkfreq", "237,119");
1049       break;
1050     case 240:
1051       clk2 = 120;
1052 //      nvram_set ("clkfreq", "240,120");
1053       break;
1054     case 250:
1055       clk2 = 125;
1056 //      nvram_set ("clkfreq", "250,125");
1057       break;
1058     case 252:
1059       clk2 = 126;
1060 //      nvram_set ("clkfreq", "252,126");
1061       break;
1062     case 264:
1063       clk2 = 132;
1064 //      nvram_set ("clkfreq", "264,132");
1065       break;
1066     case 280:
1067       clk2 = 120;
1068 //      nvram_set ("clkfreq", "280,120");
1069       break;
1070     case 300:
1071       clk2 = 120;
1072 //      nvram_set ("clkfreq", "300,120");
1073       break;
1074     default:
1075       set = 0;
1076       break;
1077     }
1078
1079   if (set)
1080     {
1081       cprintf ("clock frequency adjusted from %d to %d, reboot needed\n",
1082                cclk, clk);
1083       sprintf (clkfr, "%d,%d", clk, clk2);
1084       nvram_set ("clkfreq", clkfr);
1085       nvram_commit ();
1086       cprintf ("Overclocking done, rebooting...\n");
1087       kill (1, SIGTERM);
1088       exit (0);
1089     }
1090 #endif
1091 }
1092
Note: See TracBrowser for help on using the browser.