source: src/router/services/sysinit/devinit.c @ 17209

Last change on this file since 17209 was 17209, checked in by BrainSlayer, 2 years ago

new x86 code

File size: 4.2 KB
Line 
1/*
2 * devinit.c
3 *
4 * Copyright (C) 2010 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#include <cymac.h>
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
54
55#ifdef HAVE_X86
56
57static char *getdisc(void)      // works only for squashfs
58{
59        int i;
60        static char ret[4];
61        unsigned char *disks[]={"sda2","sdb2","sdc2","sdd2","sde2","sdf2","sdg2","sdh2","sdi2"};
62        for (i = 0; i < 9; i++) {
63                char dev[64];
64
65                sprintf(dev, "/dev/%s", disks[i]);
66                FILE *in = fopen(dev, "rb");
67
68                if (in == NULL)
69                        continue;       // no second partition or disc does not
70                // exist, skipping
71                char buf[4];
72
73                fread(buf, 4, 1, in);
74                if (buf[0] == 'h' && buf[1] == 's' && buf[2] == 'q'
75                    && buf[3] == 't') {
76                        fclose(in);
77                        // filesystem detected
78                        strncpy(ret,disks[i],3);
79                        return ret;
80                }
81                fclose(in);
82        }
83        return NULL;
84}
85
86#endif
87void start_devinit(void)
88{
89        unlink("/etc/nvram/.lock");
90        cprintf("sysinit() proc\n");
91
92        /*
93         * /proc
94         */
95        mount("proc", "/proc", "proc", MS_MGC_VAL, NULL);
96        mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL);
97#ifdef HAVE_ATH9K
98        mount("debugfs", "/sys/kernel/debug", "debugfs", MS_MGC_VAL, NULL);
99#endif
100        cprintf("sysinit() tmp\n");
101        /*
102         * /tmp
103         */
104        mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
105#ifdef HAVE_HOTPLUG2
106        // shell-skript. otherwise we loose our console
107        system("echo >/proc/sys/kernel/hotplug");
108        system("mount -t tmpfs none /dev -o size=512K");
109        system("mknod /dev/console c 5 1");
110        system("mknod /dev/null c 1 3");
111        system("mkdir /dev/pts");
112#else
113        // fix for linux kernel 2.6
114        eval("mknod", "/dev/ppp", "c", "108", "0");
115#endif
116// fix me udevtrigger does not create that (yet) not registered?
117        eval("mknod", "/dev/nvram", "c", "229", "0");
118        eval("mknod", "/dev/watchdog", "c", "10", "130");
119
120        mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL);
121        mount("devpts", "/proc/bus/usb", "usbfs", MS_MGC_VAL, NULL);
122        eval("mkdir", "/tmp/www");
123
124        unlink("/tmp/nvram/.lock");
125        eval("mkdir", "/tmp/nvram");
126
127        /*
128         * /var
129         */
130        mkdir("/tmp/var", 0777);
131        mkdir("/var/lock", 0777);
132        mkdir("/var/lock/subsys", 0777);
133        mkdir("/var/log", 0777);
134        mkdir("/var/run", 0777);
135        mkdir("/var/tmp", 0777);
136fprintf(stderr,"starting hotplug\n");
137#ifdef HAVE_HOTPLUG2
138        system("/etc/hotplug2.startup");
139#endif
140#ifdef HAVE_X86
141        fprintf(stderr,"waiting for hotplug\n");
142        char dev[64];
143        char *disc = getdisc();
144
145        if (disc == NULL) {
146                fprintf(stderr,
147                        "no valid dd-wrt partition found, calling shell");
148                eval("/bin/sh");
149        }
150        // sprintf (dev, "/dev/discs/disc%d/part1", index);
151        // mount (dev, "/boot", "ext2", MS_MGC_VAL, NULL);
152
153        sprintf(dev, "/dev/%s3", disc);
154        if (mount(dev, "/usr/local", "ext2", MS_MGC_VAL, NULL)) {
155                eval("/sbin/mke2fs", "-F", "-b", "1024", dev);
156                mount(dev, "/usr/local", "ext2", MS_MGC_VAL, NULL);
157//              eval("/bin/tar", "-xvvjf", "/etc/local.tar.bz2", "-C", "/");
158        }
159        eval("mkdir", "-p", "/usr/local/nvram");
160#endif
161fprintf(stderr,"done\n");
162}
Note: See TracBrowser for help on using the repository browser.