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

Revision 12224, 6.3 kB (checked in by BrainSlayer, 6 months ago)

code formating

Line 
1 /*
2  * sysinit-rt2880.c
3  *
4  * Copyright (C) 2008 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 #define sys_reboot() eval("sync"); eval("event","3","1","15")
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         cprintf("sysinit() proc\n");
66         /*
67          * /proc
68          */
69         mount("proc", "/proc", "proc", MS_MGC_VAL, NULL);
70         mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL);
71         cprintf("sysinit() tmp\n");
72
73         /*
74          * /tmp
75          */
76         mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
77         // fix for linux kernel 2.6
78         mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL);
79         eval("mkdir", "/tmp/www");
80         eval("mknod", "/dev/nvram", "c", "229", "0");
81         eval("mknod", "/dev/ppp", "c", "108", "0");
82         eval("mknod", "-m", "0660", "/dev/mmc", "b", "126", "0");
83         eval("mknod", "-m", "0660", "/dev/mmc0", "b", "126", "1");
84         eval("mknod", "-m", "0660", "/dev/mmc1", "b", "126", "2");
85         eval("mknod", "-m", "0660", "/dev/mmc2", "b", "126", "3");
86         eval("mknod", "-m", "0660", "/dev/mmc3", "b", "126", "4");
87
88 /*    eval( "mkdir", "/dev/mtd" );
89     eval( "mknod", "/dev/mtd/0", "c", "90", "0" );
90     eval( "mknod", "/dev/mtd/0ro", "c", "90", "1" );
91     eval( "mknod", "/dev/mtd/1", "c", "90", "2" );
92     eval( "mknod", "/dev/mtd/1ro", "c", "90", "3" );
93     eval( "mknod", "/dev/mtd/2", "c", "90", "4" );
94     eval( "mknod", "/dev/mtd/2ro", "c", "90", "5" );
95     eval( "mknod", "/dev/mtd/3", "c", "90", "6" );
96     eval( "mknod", "/dev/mtd/3ro", "c", "90", "7" );
97     eval( "mknod", "/dev/mtd/4", "c", "90", "8" );
98     eval( "mknod", "/dev/mtd/4ro", "c", "90", "9" );
99 */
100         eval("mknod", "/dev/gpio", "c", "252", "0");
101
102         cprintf("sysinit() var\n");
103
104         /*
105          * /var
106          */
107         mkdir("/tmp/var", 0777);
108         mkdir("/var/lock", 0777);
109         mkdir("/var/log", 0777);
110         mkdir("/var/run", 0777);
111         mkdir("/var/tmp", 0777);
112         cprintf("sysinit() setup console\n");
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          * load some netfilter stuff
127          */
128
129 //    eval( "watchdog" );
130         /*
131          * Set a sane date
132          */
133
134         stime(&tm);
135         nvram_set("wl0_ifname", "ra0");
136
137         insmod("rt2860v2_ap");
138
139         /* switch config */
140         if (getRouterBrand() != ROUTER_BOARD_ECB9750)   // lets load
141         {
142                 eval("ifconfig", "eth2", "up");
143                 eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
144                 eval("vconfig", "add", "eth2", "1");    //LAN
145                 eval("vconfig", "add", "eth2", "2");    //WAN
146                 sysprintf("switch reg w 14 405555");
147                 sysprintf("switch reg w 50 2001");
148                 sysprintf("switch reg w 98 7f3f");
149                 sysprintf("switch reg w e4 3f");
150 #ifdef HAVE_ALLNET11N
151                 sysprintf("switch reg w 40 1002");
152                 sysprintf("switch reg w 44 1001");
153                 sysprintf("switch reg w 48 1001");
154                 sysprintf("switch reg w 70 ffff417e");
155 #else
156                 sysprintf("switch reg w 40 1001");
157                 sysprintf("switch reg w 44 1001");
158                 sysprintf("switch reg w 48 1002");
159                 sysprintf("switch reg w 70 ffff506f");
160 #endif
161         }
162
163 /*
164
165         switch reg w 14 405555
166         switch reg w 50 2001
167         switch reg w 98 7f3f
168         if [ "$CONFIG_ESW_DOUBLE_VLAN_TAG" == "y" ]; then
169                 switch reg w e4 3f
170         fi
171         if [ "$1" = "LLLLW" ]; then
172                 switch reg w 40 1001
173                 switch reg w 44 1001
174                 switch reg w 48 1002
175                 switch reg w 70 ffff506f
176         elif [ "$1" = "WLLLL" ]; then
177                 switch reg w 40 1002
178                 switch reg w 44 1001
179                 switch reg w 48 1001
180                 switch reg w 70 ffff417e
181         elif [ "$1" = "GW" ]; then
182                 switch reg w 40 1001
183                 switch reg w 44 1001
184                 switch reg w 48 2001
185                 switch reg w 70 ffff605f
186         fi
187
188
189 */
190         return;
191 }
192
193 int check_cfe_nv(void)
194 {
195         nvram_set("portprio_support", "0");
196         return 0;
197 }
198
199 int check_pmon_nv(void)
200 {
201         return 0;
202 }
203
204 void start_overclocking(void)
205 {
206 }
207
208 char *enable_dtag_vlan(int enable)
209 {
210         if (getRouterBrand() != ROUTER_BOARD_ECB9750) {
211                 if (enable) {
212                         sysprintf("switch reg w 14 405555");
213                         sysprintf("switch reg w 50 7001");
214                         sysprintf("switch reg w 98 7f2f");
215                         sysprintf("switch reg w e4 2f");
216 #ifdef HAVE_ALLNET11N
217                         sysprintf("switch reg w 40 1007");
218                         sysprintf("switch reg w 44 1001");
219                         sysprintf("switch reg w 48 1001");
220                         sysprintf("switch reg w 70 ffff417e");
221 #else
222                         sysprintf("switch reg w 40 1001");
223                         sysprintf("switch reg w 44 1001");
224                         sysprintf("switch reg w 48 1007");
225                         sysprintf("switch reg w 70 ffff506f");
226 #endif
227                         // now we got vlan7, how do we trunk now. lets find out
228                         return "eth2";
229                 } else {
230                         sysprintf("switch reg w 14 405555");
231                         sysprintf("switch reg w 50 2001");
232                         sysprintf("switch reg w 98 7f3f");
233                         sysprintf("switch reg w e4 3f");
234 #ifdef HAVE_ALLNET11N
235                         sysprintf("switch reg w 40 1002");
236                         sysprintf("switch reg w 44 1001");
237                         sysprintf("switch reg w 48 1001");
238                         sysprintf("switch reg w 70 ffff417e");
239 #else
240                         sysprintf("switch reg w 40 1001");
241                         sysprintf("switch reg w 44 1001");
242                         sysprintf("switch reg w 48 1002");
243                         sysprintf("switch reg w 70 ffff506f");
244 #endif
245                         eval("vconfig", "set_name_type",
246                              "VLAN_PLUS_VID_NO_PAD");
247                         eval("vconfig", "add", "eth2", "2");    //WAN
248                         return "eth2";
249                 }
250         } else {
251                 return "eth2";
252         }
253 }
Note: See TracBrowser for help on using the browser.