source: mainline/uspace/app/init/init.c@ 069015f2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 069015f2 was 7bbc389, checked in by Jakub Jermar <jakub@…>, 15 years ago

Do not start devman automatically.

There seems to be a problem when both devman and netstart are run. Either dp8390
crashes while writing to an IO port (when netstart runs after devman) or devman
hangs (when netstart runs before devman). The problem appears to be related to
the fact that both the dp8390 and com2 try to pio_enable() ports from the same
I/O range.

  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup init Init
30 * @brief Init process for user space environment configuration.
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <unistd.h>
39#include <ipc/ipc.h>
40#include <vfs/vfs.h>
41#include <bool.h>
42#include <errno.h>
43#include <fcntl.h>
44#include <sys/stat.h>
45#include <task.h>
46#include <malloc.h>
47#include <macros.h>
48#include <str.h>
49#include <devmap.h>
50#include <str_error.h>
51#include "init.h"
52
53#define ROOT_DEVICE "bd/initrd"
54#define ROOT_MOUNT_POINT "/"
55
56#define DEVFS_FS_TYPE "devfs"
57#define DEVFS_MOUNT_POINT "/dev"
58
59#define SCRATCH_FS_TYPE "tmpfs"
60#define SCRATCH_MOUNT_POINT "/scratch"
61
62#define DATA_FS_TYPE "fat"
63#define DATA_DEVICE "bd/disk0"
64#define DATA_MOUNT_POINT "/data"
65
66#define SRV_CONSOLE "/srv/console"
67#define APP_GETTERM "/app/getterm"
68
69static void info_print(void)
70{
71 printf("%s: HelenOS init\n", NAME);
72}
73
74static bool mount_report(const char *desc, const char *mntpt,
75 const char *fstype, const char *dev, int rc)
76{
77 switch (rc) {
78 case EOK:
79 if (dev != NULL)
80 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
81 fstype, dev);
82 else
83 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
84 break;
85 case EBUSY:
86 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
87 return false;
88 case ELIMIT:
89 printf("%s: %s limit exceeded\n", NAME, desc);
90 return false;
91 case ENOENT:
92 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
93 return false;
94 default:
95 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
96 str_error(rc));
97 return false;
98 }
99
100 return true;
101}
102
103static bool mount_root(const char *fstype)
104{
105 const char *opts = "";
106
107 if (str_cmp(fstype, "tmpfs") == 0)
108 opts = "restore";
109
110 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
111 IPC_FLAG_BLOCKING);
112 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
113 ROOT_DEVICE, rc);
114}
115
116static bool mount_devfs(void)
117{
118 int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
119 IPC_FLAG_BLOCKING);
120 return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
121 NULL, rc);
122}
123
124static void spawn(const char *fname)
125{
126 const char *argv[2];
127 struct stat s;
128
129 if (stat(fname, &s) == ENOENT)
130 return;
131
132 printf("%s: Spawning %s\n", NAME, fname);
133
134 argv[0] = fname;
135 argv[1] = NULL;
136
137 int err;
138 if (!task_spawn(fname, argv, &err))
139 printf("%s: Error spawning %s (%s)\n", NAME, fname,
140 str_error(err));
141}
142
143static void srv_start(const char *fname)
144{
145 const char *argv[2];
146 task_id_t id;
147 task_exit_t texit;
148 int rc, retval;
149 struct stat s;
150
151 if (stat(fname, &s) == ENOENT)
152 return;
153
154 printf("%s: Starting %s\n", NAME, fname);
155
156 argv[0] = fname;
157 argv[1] = NULL;
158
159 id = task_spawn(fname, argv, &retval);
160 if (!id) {
161 printf("%s: Error spawning %s (%s)\n", NAME, fname,
162 str_error(retval));
163 return;
164 }
165
166 rc = task_wait(id, &texit, &retval);
167 if (rc != EOK) {
168 printf("%s: Error waiting for %s (%s(\n", NAME, fname,
169 str_error(retval));
170 return;
171 }
172
173 if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
174 printf("%s: Server %s failed to start (%s)\n", NAME,
175 fname, str_error(retval));
176 }
177}
178
179static void console(const char *dev)
180{
181 const char *argv[3];
182 char hid_in[DEVMAP_NAME_MAXLEN];
183 int rc;
184
185 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
186
187 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
188
189 /* Wait for the input device to be ready */
190 dev_handle_t handle;
191 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
192
193 if (rc == EOK) {
194 argv[0] = SRV_CONSOLE;
195 argv[1] = hid_in;
196 argv[2] = NULL;
197
198 if (!task_spawn(SRV_CONSOLE, argv, &rc))
199 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
200 hid_in, str_error(rc));
201 } else
202 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
203 str_error(rc));
204}
205
206static void getterm(const char *dev, const char *app)
207{
208 const char *argv[4];
209 char term[DEVMAP_NAME_MAXLEN];
210 int rc;
211
212 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
213
214 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
215
216 /* Wait for the terminal device to be ready */
217 dev_handle_t handle;
218 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
219
220 if (rc == EOK) {
221 argv[0] = APP_GETTERM;
222 argv[1] = term;
223 argv[2] = app;
224 argv[3] = NULL;
225
226 if (!task_spawn(APP_GETTERM, argv, &rc))
227 printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM,
228 term, app, str_error(rc));
229 } else
230 printf("%s: Error waiting on %s (%s)\n", NAME, term,
231 str_error(rc));
232}
233
234static bool mount_scratch(void)
235{
236 int rc = mount(SCRATCH_FS_TYPE, SCRATCH_MOUNT_POINT, "", "", 0);
237 return mount_report("Scratch filesystem", SCRATCH_MOUNT_POINT,
238 SCRATCH_FS_TYPE, NULL, rc);
239}
240
241static bool mount_data(void)
242{
243 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
244 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
245 DATA_DEVICE, rc);
246}
247
248int main(int argc, char *argv[])
249{
250 info_print();
251
252 if (!mount_root(STRING(RDFMT))) {
253 printf("%s: Exiting\n", NAME);
254 return -1;
255 }
256
257 /* Make sure tmpfs is running. */
258 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
259 spawn("/srv/tmpfs");
260 }
261
262 spawn("/srv/devfs");
263 spawn("/srv/taskmon");
264
265 if (!mount_devfs()) {
266 printf("%s: Exiting\n", NAME);
267 return -2;
268 }
269
270 mount_scratch();
271
272 spawn("/srv/fhc");
273 spawn("/srv/obio");
274 srv_start("/srv/cuda_adb");
275 srv_start("/srv/i8042");
276 srv_start("/srv/s3c24ser");
277 srv_start("/srv/adb_ms");
278 srv_start("/srv/char_ms");
279 srv_start("/srv/s3c24ts");
280
281 spawn("/srv/fb");
282 spawn("/srv/kbd");
283 console("hid_in/kbd");
284
285 spawn("/srv/clip");
286
287 /*
288 * Start these synchronously so that mount_data() can be
289 * non-blocking.
290 */
291#ifdef CONFIG_START_BD
292 srv_start("/srv/ata_bd");
293 srv_start("/srv/gxe_bd");
294#else
295 (void) srv_start;
296#endif
297
298#ifdef CONFIG_MOUNT_DATA
299 mount_data();
300#else
301 (void) mount_data;
302#endif
303
304 getterm("term/vc0", "/app/bdsh");
305 getterm("term/vc1", "/app/bdsh");
306 getterm("term/vc2", "/app/bdsh");
307 getterm("term/vc3", "/app/bdsh");
308 getterm("term/vc4", "/app/bdsh");
309 getterm("term/vc5", "/app/bdsh");
310 getterm("term/vc6", "/app/klog");
311
312 return 0;
313}
314
315/** @}
316 */
Note: See TracBrowser for help on using the repository browser.