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

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

take out this set from the static ram

Line 
1 /*
2  * sysinit-ca8.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 <sys/ioctl.h>
42
43 #include <bcmnvram.h>
44 #include <shutils.h>
45 #include <utils.h>
46
47 #define SIOCGMIIREG     0x8948  /* Read MII PHY register.  */
48 #define SIOCSMIIREG     0x8949  /* Write MII PHY register.  */
49 #include <arpa/inet.h>
50 #include <sys/socket.h>
51 #include <linux/if.h>
52 #include <linux/sockios.h>
53 #include <linux/mii.h>
54
55 #include <bcmnvram.h>
56 #include <shutils.h>
57 #include <utils.h>
58 #include <cymac.h>
59
60 // highly experimental
61
62 void start_sysinit(void)
63 {
64         struct utsname name;
65         time_t tm = 0;
66
67         unlink("/etc/nvram/.lock");
68         cprintf("sysinit() proc\n");
69         /*
70          * /proc
71          */
72         mount("proc", "/proc", "proc", MS_MGC_VAL, NULL);
73         mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL);
74         cprintf("sysinit() tmp\n");
75
76         /*
77          * /tmp
78          */
79         mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
80         // fix for linux kernel 2.6
81         mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL);
82         eval("mkdir", "/tmp/www");
83         eval("mknod", "/dev/nvram", "c", "229", "0");
84         eval("mknod", "/dev/ppp", "c", "108", "0");
85
86         unlink("/tmp/nvram/.lock");
87         eval("mkdir", "/tmp/nvram");
88         eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/");
89         FILE *in = fopen("/tmp/nvram/nvram.db", "rb");
90
91         if (in != NULL) {
92                 fclose(in);
93                 eval("/usr/sbin/convertnvram");
94                 eval("/sbin/mtd", "erase", "nvram");
95                 nvram_commit();
96         }
97         cprintf("sysinit() var\n");
98
99         /*
100          * /var
101          */
102         mkdir("/tmp/var", 0777);
103         mkdir("/var/lock", 0777);
104         mkdir("/var/log", 0777);
105         mkdir("/var/run", 0777);
106         mkdir("/var/tmp", 0777);
107         cprintf("sysinit() setup console\n");
108         if (!nvram_match("disable_watchdog", "1"))
109                 eval("watchdog");
110         /*
111          * Setup console
112          */
113
114         cprintf("sysinit() klogctl\n");
115         klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
116         cprintf("sysinit() get router\n");
117
118         /*
119          * Modules
120          */
121         uname(&name);
122
123         /*
124          * network drivers
125          */
126         insmod("ar2313");
127         if (getRouterBrand() == ROUTER_BOARD_CA8PRO) {
128                 eval("ifconfig", "eth0", "up", "promisc");      // required for vlan config
129                 eval("/sbin/vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
130                 eval("/sbin/vconfig", "add", "eth0", "0");
131                 eval("/sbin/vconfig", "add", "eth0", "1");
132                 struct ifreq ifr;
133                 int s;
134
135                 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
136                         char eabuf[32];
137
138                         strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
139                         ioctl(s, SIOCGIFHWADDR, &ifr);
140                         char macaddr[32];
141
142                         strcpy(macaddr,
143                                ether_etoa((unsigned char *)ifr.ifr_hwaddr.
144                                           sa_data, eabuf));
145                         nvram_set("et0macaddr", macaddr);
146 //          MAC_ADD( macaddr );
147                         ether_atoe(macaddr,
148                                    (unsigned char *)ifr.ifr_hwaddr.sa_data);
149                         strncpy(ifr.ifr_name, "vlan1", IFNAMSIZ);
150                         ioctl(s, SIOCSIFHWADDR, &ifr);
151                         close(s);
152                 }
153         }
154
155         insmod("ath_hal");
156         if (nvram_get("rate_control") != NULL) {
157                 char rate[64];
158
159                 sprintf(rate, "ratectl=%s", nvram_safe_get("rate_control"));
160                 eval("insmod", "ath_ahb", rate);
161         } else {
162                 insmod("ath_ahb");
163         }
164         // eval ("ifconfig", "wifi0", "up");
165
166         insmod("ipv6");
167
168         /*
169          * Set a sane date
170          */
171         stime(&tm);
172         nvram_set("wl0_ifname", "ath0");
173
174         return;
175         cprintf("done\n");
176 }
177
178 int check_cfe_nv(void)
179 {
180         nvram_set("portprio_support", "0");
181         return 0;
182 }
183
184 int check_pmon_nv(void)
185 {
186         return 0;
187 }
188
189 void start_overclocking(void)
190 {
191 }
192
193 void enable_dtag_vlan(int enable)
194 {
195
196 }
Note: See TracBrowser for help on using the browser.