source: mainline/uspace/app/init/init.c@ 33dbbd2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 33dbbd2 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
RevLine 
[3eddaff]1/*
[df4ed85]2 * Copyright (c) 2005 Martin Decky
[3eddaff]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
[b2951e2]29/** @addtogroup init Init
[c91c9fb]30 * @brief Init process for user space environment configuration.
[b2951e2]31 * @{
[c91c9fb]32 */
[b2951e2]33/**
34 * @file
35 */
36
[00c4994]37#include <stdio.h>
[860271d4]38#include <unistd.h>
[c91c9fb]39#include <ipc/ipc.h>
[860271d4]40#include <vfs/vfs.h>
41#include <bool.h>
42#include <errno.h>
43#include <fcntl.h>
[1757ffce]44#include <sys/stat.h>
[860271d4]45#include <task.h>
46#include <malloc.h>
[c91c9fb]47#include <macros.h>
[19f857a]48#include <str.h>
[36b8100a]49#include <devmap.h>
[d9fae235]50#include <str_error.h>
[860271d4]51#include "init.h"
52
[d9fae235]53#define ROOT_DEVICE "bd/initrd"
54#define ROOT_MOUNT_POINT "/"
55
56#define DEVFS_FS_TYPE "devfs"
[47a350f]57#define DEVFS_MOUNT_POINT "/dev"
58
[d9fae235]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
[47a350f]66#define SRV_CONSOLE "/srv/console"
[df747bd8]67#define APP_GETTERM "/app/getterm"
[47a350f]68
[36b8100a]69static void info_print(void)
70{
[d9fae235]71 printf("%s: HelenOS init\n", NAME);
[36b8100a]72}
73
[d9fae235]74static bool mount_report(const char *desc, const char *mntpt,
75 const char *fstype, const char *dev, int rc)
[860271d4]76{
[f49cf64]77 switch (rc) {
78 case EOK:
[d9fae235]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);
[f49cf64]84 break;
85 case EBUSY:
[d9fae235]86 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
[f49cf64]87 return false;
88 case ELIMIT:
[d9fae235]89 printf("%s: %s limit exceeded\n", NAME, desc);
[f49cf64]90 return false;
91 case ENOENT:
[d9fae235]92 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
[f49cf64]93 return false;
94 default:
[d9fae235]95 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
96 str_error(rc));
[f49cf64]97 return false;
[860271d4]98 }
99
100 return true;
101}
102
[d9fae235]103static bool mount_root(const char *fstype)
[a095d20]104{
[d9fae235]105 const char *opts = "";
[f49cf64]106
[d9fae235]107 if (str_cmp(fstype, "tmpfs") == 0)
108 opts = "restore";
[a095d20]109
[d9fae235]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);
[a095d20]122}
123
[a000878c]124static void spawn(const char *fname)
[860271d4]125{
[a000878c]126 const char *argv[2];
[1757ffce]127 struct stat s;
128
129 if (stat(fname, &s) == ENOENT)
130 return;
[c91c9fb]131
[d9fae235]132 printf("%s: Spawning %s\n", NAME, fname);
[c91c9fb]133
[c98e6ee]134 argv[0] = fname;
135 argv[1] = NULL;
[c91c9fb]136
[d9fae235]137 int err;
138 if (!task_spawn(fname, argv, &err))
139 printf("%s: Error spawning %s (%s)\n", NAME, fname,
140 str_error(err));
[b27a97bb]141}
142
[a000878c]143static void srv_start(const char *fname)
[95bc57c]144{
[a000878c]145 const char *argv[2];
[95bc57c]146 task_id_t id;
147 task_exit_t texit;
148 int rc, retval;
[1757ffce]149 struct stat s;
150
151 if (stat(fname, &s) == ENOENT)
152 return;
[95bc57c]153
[d9fae235]154 printf("%s: Starting %s\n", NAME, fname);
[95bc57c]155
156 argv[0] = fname;
157 argv[1] = NULL;
158
[d9fae235]159 id = task_spawn(fname, argv, &retval);
[95bc57c]160 if (!id) {
[d9fae235]161 printf("%s: Error spawning %s (%s)\n", NAME, fname,
162 str_error(retval));
[95bc57c]163 return;
164 }
[d9fae235]165
[95bc57c]166 rc = task_wait(id, &texit, &retval);
167 if (rc != EOK) {
[d9fae235]168 printf("%s: Error waiting for %s (%s(\n", NAME, fname,
169 str_error(retval));
[95bc57c]170 return;
171 }
[d9fae235]172
[1313ee9]173 if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
[d9fae235]174 printf("%s: Server %s failed to start (%s)\n", NAME,
175 fname, str_error(retval));
[95bc57c]176 }
177}
178
[a000878c]179static void console(const char *dev)
[47a350f]180{
[a000878c]181 const char *argv[3];
[28be7fa]182 char hid_in[DEVMAP_NAME_MAXLEN];
[47a350f]183 int rc;
184
[28be7fa]185 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
[47a350f]186
[d9fae235]187 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
[47a350f]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
[d9fae235]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));
[47a350f]201 } else
[d9fae235]202 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
203 str_error(rc));
[47a350f]204}
205
[a000878c]206static void getterm(const char *dev, const char *app)
[36b8100a]207{
[a000878c]208 const char *argv[4];
[28be7fa]209 char term[DEVMAP_NAME_MAXLEN];
[62140db]210 int rc;
[36b8100a]211
[28be7fa]212 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
[36b8100a]213
[d9fae235]214 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
[36b8100a]215
[47a350f]216 /* Wait for the terminal device to be ready */
[36b8100a]217 dev_handle_t handle;
[62140db]218 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
[36b8100a]219
[62140db]220 if (rc == EOK) {
[df747bd8]221 argv[0] = APP_GETTERM;
222 argv[1] = term;
[36b8100a]223 argv[2] = app;
224 argv[3] = NULL;
225
[d9fae235]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));
[47a350f]229 } else
[d9fae235]230 printf("%s: Error waiting on %s (%s)\n", NAME, term,
231 str_error(rc));
[36b8100a]232}
233
[d9fae235]234static bool mount_scratch(void)
[03333bc]235{
[d9fae235]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);
[03333bc]239}
240
[d9fae235]241static bool mount_data(void)
[00fe6bb]242{
[d9fae235]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);
[00fe6bb]246}
247
[5106e98]248int main(int argc, char *argv[])
249{
[860271d4]250 info_print();
251
[36b8100a]252 if (!mount_root(STRING(RDFMT))) {
[d9fae235]253 printf("%s: Exiting\n", NAME);
[860271d4]254 return -1;
255 }
[d9fae235]256
[03333bc]257 /* Make sure tmpfs is running. */
258 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
259 spawn("/srv/tmpfs");
260 }
[860271d4]261
[a095d20]262 spawn("/srv/devfs");
[a074b4f]263 spawn("/srv/taskmon");
[a095d20]264
265 if (!mount_devfs()) {
[d9fae235]266 printf("%s: Exiting\n", NAME);
[a095d20]267 return -2;
268 }
[d9fae235]269
[03333bc]270 mount_scratch();
[a095d20]271
[bb2dbf8]272 spawn("/srv/fhc");
273 spawn("/srv/obio");
[3a2f8aa]274 srv_start("/srv/cuda_adb");
[9f51afc]275 srv_start("/srv/i8042");
[a9b5b5f]276 srv_start("/srv/s3c24ser");
[b73c26d]277 srv_start("/srv/adb_ms");
278 srv_start("/srv/char_ms");
[527298a]279 srv_start("/srv/s3c24ts");
[d9fae235]280
[de9c5cb]281 spawn("/srv/fb");
282 spawn("/srv/kbd");
[47a350f]283 console("hid_in/kbd");
284
[fb623e2]285 spawn("/srv/clip");
[d9fae235]286
[95bc57c]287 /*
288 * Start these synchronously so that mount_data() can be
289 * non-blocking.
290 */
[1641eb0]291#ifdef CONFIG_START_BD
[95bc57c]292 srv_start("/srv/ata_bd");
293 srv_start("/srv/gxe_bd");
[f019cc07]294#else
295 (void) srv_start;
296#endif
[d9fae235]297
[1641eb0]298#ifdef CONFIG_MOUNT_DATA
[f49cf64]299 mount_data();
[f019cc07]300#else
301 (void) mount_data;
[1641eb0]302#endif
[d9fae235]303
[b73c26d]304 getterm("term/vc0", "/app/bdsh");
[df747bd8]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");
[b73c26d]310 getterm("term/vc6", "/app/klog");
[d9fae235]311
[3eddaff]312 return 0;
313}
[b2951e2]314
315/** @}
316 */
Note: See TracBrowser for help on using the repository browser.