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

Revision 12395, 5.0 kB (checked in by BrainSlayer, 5 months ago)

take out this set from the static ram

Line 
1 /*
2  * sysinit-fonera.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 #include <stdio.h>
23 #include <stdlib.h>
24 #include <limits.h>
25 #include <time.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <syslog.h>
29 #include <signal.h>
30 #include <string.h>
31 #include <termios.h>
32 #include <sys/klog.h>
33 #include <sys/types.h>
34 #include <sys/mount.h>
35 #include <sys/reboot.h>
36 #include <sys/stat.h>
37 #include <sys/sysmacros.h>
38 #include <sys/time.h>
39 #include <sys/utsname.h>
40 #include <sys/wait.h>
41 #include <linux/if_ether.h>
42 #include <linux/mii.h>
43 #include <linux/sockios.h>
44 #include <net/if.h>
45
46 #include <arpa/inet.h>
47 #include <sys/socket.h>
48 #include <linux/sockios.h>
49 #include <linux/mii.h>
50
51 #include <bcmnvram.h>
52 #include <shutils.h>
53 #include <utils.h>
54 #include <cymac.h>
55
56 extern void vlan_init(int num);
57
58 void start_sysinit(void)
59 {
60         char buf[PATH_MAX];
61         struct utsname name;
62         struct stat tmp_stat;
63         time_t tm = 0;
64
65         unlink("/etc/nvram/.lock");
66         cprintf("sysinit() proc\n");
67         /*
68          * /proc
69          */
70         mount("proc", "/proc", "proc", MS_MGC_VAL, NULL);
71         mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL);
72         cprintf("sysinit() tmp\n");
73
74         /*
75          * /tmp
76          */
77         mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
78         // fix for linux kernel 2.6
79         mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL);
80         eval("mkdir", "/tmp/www");
81         eval("mknod", "/dev/nvram", "c", "229", "0");
82         eval("mknod", "/dev/ppp", "c", "108", "0");
83         eval("mknod", "-m", "0660", "/dev/mmc", "b", "126", "0");
84         eval("mknod", "-m", "0660", "/dev/mmc0", "b", "126", "1");
85         eval("mknod", "-m", "0660", "/dev/mmc1", "b", "126", "2");
86         eval("mknod", "-m", "0660", "/dev/mmc2", "b", "126", "3");
87         eval("mknod", "-m", "0660", "/dev/mmc3", "b", "126", "4");
88
89         unlink("/tmp/nvram/.lock");
90         eval("mkdir", "/tmp/nvram");
91         eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/");
92         FILE *in = fopen("/tmp/nvram/nvram.db", "rb");
93
94         if (in != NULL) {
95                 fclose(in);
96                 eval("/usr/sbin/convertnvram");
97                 eval("/sbin/mtd", "erase", "nvram");
98                 nvram_commit();
99         }
100         cprintf("sysinit() var\n");
101
102         /*
103          * /var
104          */
105         mkdir("/tmp/var", 0777);
106         mkdir("/var/lock", 0777);
107         mkdir("/var/log", 0777);
108         mkdir("/var/run", 0777);
109         mkdir("/var/tmp", 0777);
110         cprintf("sysinit() setup console\n");
111         if (!nvram_match("disable_watchdog", "1"))
112                 eval("watchdog");
113         /*
114          * Setup console
115          */
116
117         cprintf("sysinit() klogctl\n");
118         klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
119         cprintf("sysinit() get router\n");
120
121         /*
122          * Modules
123          */
124         uname(&name);
125         /*
126          * network drivers
127          */
128         insmod("ar2313");
129         insmod("ath_hal");
130         if (nvram_get("rate_control") != NULL) {
131                 char rate[64];
132
133                 sprintf(rate, "ratectl=%s", nvram_safe_get("rate_control"));
134                 eval("insmod", "ath_ahb", rate);
135         } else {
136                 insmod("ath_ahb");
137         }
138
139 #if defined(HAVE_EAP3660) || defined(HAVE_EOC2610) || defined(HAVE_ECB3500) || defined(HAVE_EOC1650)
140         system2("echo 2 >/proc/sys/dev/wifi0/ledpin");
141         system2("echo 1 >/proc/sys/dev/wifi0/softled");
142 #endif
143 #ifdef HAVE_GWMF54G2
144         system2("echo 4 >/proc/sys/dev/wifi0/ledpin");
145         system2("echo 1 >/proc/sys/dev/wifi0/softled");
146 #endif
147         // eval ("ifconfig", "wifi0", "up");
148 #ifdef HAVE_LS2
149         eval("ifconfig", "eth0", "up"); // wan
150         vlan_init(5);           // 4 lan + 1 wan, but only first one is used
151 #endif
152         if (getRouterBrand() == ROUTER_BOARD_FONERA2200) {
153                 eval("ifconfig", "eth0", "up", "promisc");      // required for vlan config
154                 eval("/sbin/vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
155                 eval("/sbin/vconfig", "add", "eth0", "0");
156                 eval("/sbin/vconfig", "add", "eth0", "1");
157                 struct ifreq ifr;
158                 int s;
159
160                 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
161                         char eabuf[32];
162
163                         strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
164                         ioctl(s, SIOCGIFHWADDR, &ifr);
165                         char macaddr[32];
166
167                         strcpy(macaddr,
168                                ether_etoa((unsigned char *)ifr.ifr_hwaddr.
169                                           sa_data, eabuf));
170                         nvram_set("et0macaddr", macaddr);
171 //          MAC_ADD( macaddr );
172                         ether_atoe(macaddr,
173                                    (unsigned char *)ifr.ifr_hwaddr.sa_data);
174                         strncpy(ifr.ifr_name, "vlan1", IFNAMSIZ);
175                         ioctl(s, SIOCSIFHWADDR, &ifr);
176                         close(s);
177                 }
178         }
179         // insmod("ipv6");
180
181         /*
182          * Set a sane date
183          */
184         stime(&tm);
185         nvram_set("wl0_ifname", "ath0");
186
187         return;
188 }
189
190 int check_cfe_nv(void)
191 {
192         nvram_set("portprio_support", "0");
193         return 0;
194 }
195
196 int check_pmon_nv(void)
197 {
198         return 0;
199 }
200
201 void start_overclocking(void)
202 {
203 }
204
205 void enable_dtag_vlan(int enable)
206 {
207
208 }
Note: See TracBrowser for help on using the browser.