[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>
|
---|
[594303b] | 48 | #include <string.h>
|
---|
[36b8100a] | 49 | #include <devmap.h>
|
---|
[860271d4] | 50 | #include "init.h"
|
---|
| 51 |
|
---|
[47a350f] | 52 | #define DEVFS_MOUNT_POINT "/dev"
|
---|
| 53 |
|
---|
| 54 | #define SRV_CONSOLE "/srv/console"
|
---|
[df747bd8] | 55 | #define APP_GETTERM "/app/getterm"
|
---|
[47a350f] | 56 |
|
---|
[36b8100a] | 57 | static void info_print(void)
|
---|
| 58 | {
|
---|
| 59 | printf(NAME ": HelenOS init\n");
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | static bool mount_root(const char *fstype)
|
---|
[860271d4] | 63 | {
|
---|
[594303b] | 64 | char *opts = "";
|
---|
[1313ee9] | 65 | const char *root_dev = "bd/initrd";
|
---|
[860271d4] | 66 |
|
---|
[594303b] | 67 | if (str_cmp(fstype, "tmpfs") == 0)
|
---|
| 68 | opts = "restore";
|
---|
[f49cf64] | 69 |
|
---|
| 70 | int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING);
|
---|
| 71 |
|
---|
| 72 | switch (rc) {
|
---|
| 73 | case EOK:
|
---|
| 74 | printf(NAME ": Root filesystem mounted, %s at %s\n",
|
---|
| 75 | fstype, root_dev);
|
---|
| 76 | break;
|
---|
| 77 | case EBUSY:
|
---|
| 78 | printf(NAME ": Root filesystem already mounted\n");
|
---|
| 79 | return false;
|
---|
| 80 | case ELIMIT:
|
---|
| 81 | printf(NAME ": Unable to mount root filesystem\n");
|
---|
| 82 | return false;
|
---|
| 83 | case ENOENT:
|
---|
| 84 | printf(NAME ": Unknown filesystem type (%s)\n", fstype);
|
---|
| 85 | return false;
|
---|
| 86 | default:
|
---|
| 87 | printf(NAME ": Error mounting root filesystem (%d)\n", rc);
|
---|
| 88 | return false;
|
---|
[860271d4] | 89 | }
|
---|
| 90 |
|
---|
| 91 | return true;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[a095d20] | 94 | static bool mount_devfs(void)
|
---|
| 95 | {
|
---|
[210e50a] | 96 | int rc = mount("devfs", DEVFS_MOUNT_POINT, "", "", IPC_FLAG_BLOCKING);
|
---|
[f49cf64] | 97 |
|
---|
| 98 | switch (rc) {
|
---|
| 99 | case EOK:
|
---|
| 100 | printf(NAME ": Device filesystem mounted\n");
|
---|
| 101 | break;
|
---|
| 102 | case EBUSY:
|
---|
| 103 | printf(NAME ": Device filesystem already mounted\n");
|
---|
[3b3e776] | 104 |
|
---|
[f49cf64] | 105 | return false;
|
---|
| 106 | case ELIMIT:
|
---|
| 107 | printf(NAME ": Unable to mount device filesystem\n");
|
---|
[3b3e776] | 108 |
|
---|
[f49cf64] | 109 | return false;
|
---|
| 110 | case ENOENT:
|
---|
| 111 | printf(NAME ": Unknown filesystem type (devfs)\n");
|
---|
[3b3e776] | 112 |
|
---|
[f49cf64] | 113 | return false;
|
---|
| 114 | default:
|
---|
| 115 | printf(NAME ": Error mounting device filesystem (%d)\n", rc);
|
---|
[3b3e776] | 116 |
|
---|
[f49cf64] | 117 | return false;
|
---|
[a095d20] | 118 | }
|
---|
| 119 |
|
---|
| 120 | return true;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[860271d4] | 123 | static void spawn(char *fname)
|
---|
| 124 | {
|
---|
[c98e6ee] | 125 | char *argv[2];
|
---|
[1757ffce] | 126 | struct stat s;
|
---|
| 127 |
|
---|
| 128 | if (stat(fname, &s) == ENOENT)
|
---|
| 129 | return;
|
---|
[c91c9fb] | 130 |
|
---|
[860271d4] | 131 | printf(NAME ": Spawning %s\n", fname);
|
---|
[c91c9fb] | 132 |
|
---|
[c98e6ee] | 133 | argv[0] = fname;
|
---|
| 134 | argv[1] = NULL;
|
---|
[c91c9fb] | 135 |
|
---|
[566f4cfb] | 136 | if (!task_spawn(fname, argv))
|
---|
[c91c9fb] | 137 | printf(NAME ": Error spawning %s\n", fname);
|
---|
[b27a97bb] | 138 | }
|
---|
| 139 |
|
---|
[95bc57c] | 140 | static void srv_start(char *fname)
|
---|
| 141 | {
|
---|
| 142 | char *argv[2];
|
---|
| 143 | task_id_t id;
|
---|
| 144 | task_exit_t texit;
|
---|
| 145 | int rc, retval;
|
---|
[1757ffce] | 146 | struct stat s;
|
---|
| 147 |
|
---|
| 148 | if (stat(fname, &s) == ENOENT)
|
---|
| 149 | return;
|
---|
[95bc57c] | 150 |
|
---|
| 151 | printf(NAME ": Starting %s\n", fname);
|
---|
| 152 |
|
---|
| 153 | argv[0] = fname;
|
---|
| 154 | argv[1] = NULL;
|
---|
| 155 |
|
---|
| 156 | id = task_spawn(fname, argv);
|
---|
| 157 | if (!id) {
|
---|
| 158 | printf(NAME ": Error spawning %s\n", fname);
|
---|
| 159 | return;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | rc = task_wait(id, &texit, &retval);
|
---|
| 163 | if (rc != EOK) {
|
---|
| 164 | printf(NAME ": Error waiting for %s\n", fname);
|
---|
| 165 | return;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
[1313ee9] | 168 | if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
|
---|
[95bc57c] | 169 | printf(NAME ": Server %s failed to start (returned %d)\n",
|
---|
| 170 | fname, retval);
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[47a350f] | 174 | static void console(char *dev)
|
---|
| 175 | {
|
---|
| 176 | char *argv[3];
|
---|
[28be7fa] | 177 | char hid_in[DEVMAP_NAME_MAXLEN];
|
---|
[47a350f] | 178 | int rc;
|
---|
| 179 |
|
---|
[28be7fa] | 180 | snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
|
---|
[47a350f] | 181 |
|
---|
| 182 | printf(NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);
|
---|
| 183 |
|
---|
| 184 | /* Wait for the input device to be ready */
|
---|
| 185 | dev_handle_t handle;
|
---|
| 186 | rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
|
---|
| 187 |
|
---|
| 188 | if (rc == EOK) {
|
---|
| 189 | argv[0] = SRV_CONSOLE;
|
---|
| 190 | argv[1] = hid_in;
|
---|
| 191 | argv[2] = NULL;
|
---|
| 192 |
|
---|
| 193 | if (!task_spawn(SRV_CONSOLE, argv))
|
---|
| 194 | printf(NAME ": Error spawning %s with %s\n", SRV_CONSOLE, hid_in);
|
---|
| 195 | } else
|
---|
| 196 | printf(NAME ": Error waiting on %s\n", hid_in);
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[df747bd8] | 199 | static void getterm(char *dev, char *app)
|
---|
[36b8100a] | 200 | {
|
---|
| 201 | char *argv[4];
|
---|
[28be7fa] | 202 | char term[DEVMAP_NAME_MAXLEN];
|
---|
[62140db] | 203 | int rc;
|
---|
[36b8100a] | 204 |
|
---|
[28be7fa] | 205 | snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
|
---|
[36b8100a] | 206 |
|
---|
[c26eb39] | 207 | printf(NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);
|
---|
[36b8100a] | 208 |
|
---|
[47a350f] | 209 | /* Wait for the terminal device to be ready */
|
---|
[36b8100a] | 210 | dev_handle_t handle;
|
---|
[62140db] | 211 | rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
|
---|
[36b8100a] | 212 |
|
---|
[62140db] | 213 | if (rc == EOK) {
|
---|
[df747bd8] | 214 | argv[0] = APP_GETTERM;
|
---|
| 215 | argv[1] = term;
|
---|
[36b8100a] | 216 | argv[2] = app;
|
---|
| 217 | argv[3] = NULL;
|
---|
| 218 |
|
---|
[df747bd8] | 219 | if (!task_spawn(APP_GETTERM, argv))
|
---|
[c26eb39] | 220 | printf(NAME ": Error spawning %s with %s %s\n", APP_GETTERM,
|
---|
| 221 | term, app);
|
---|
[47a350f] | 222 | } else
|
---|
[df747bd8] | 223 | printf(NAME ": Error waiting on %s\n", term);
|
---|
[36b8100a] | 224 | }
|
---|
| 225 |
|
---|
[03333bc] | 226 | static void mount_scratch(void)
|
---|
| 227 | {
|
---|
| 228 | int rc;
|
---|
| 229 |
|
---|
| 230 | printf("Trying to mount null/0 on /scratch... ");
|
---|
| 231 | fflush(stdout);
|
---|
| 232 |
|
---|
| 233 | rc = mount("tmpfs", "/scratch", "null/0", "", 0);
|
---|
| 234 | if (rc == EOK)
|
---|
| 235 | printf("OK\n");
|
---|
| 236 | else
|
---|
| 237 | printf("Failed\n");
|
---|
[36b8100a] | 238 | }
|
---|
| 239 |
|
---|
[f019cc07] | 240 | static void mount_data(void)
|
---|
[00fe6bb] | 241 | {
|
---|
| 242 | int rc;
|
---|
| 243 |
|
---|
[1313ee9] | 244 | printf("Trying to mount bd/disk0 on /data... ");
|
---|
[00fe6bb] | 245 | fflush(stdout);
|
---|
| 246 |
|
---|
[1313ee9] | 247 | rc = mount("fat", "/data", "bd/disk0", "wtcache", 0);
|
---|
[00fe6bb] | 248 | if (rc == EOK)
|
---|
| 249 | printf("OK\n");
|
---|
| 250 | else
|
---|
| 251 | printf("Failed\n");
|
---|
| 252 | }
|
---|
| 253 |
|
---|
[5106e98] | 254 | int main(int argc, char *argv[])
|
---|
| 255 | {
|
---|
[860271d4] | 256 | info_print();
|
---|
| 257 |
|
---|
[36b8100a] | 258 | if (!mount_root(STRING(RDFMT))) {
|
---|
[860271d4] | 259 | printf(NAME ": Exiting\n");
|
---|
| 260 | return -1;
|
---|
| 261 | }
|
---|
[03333bc] | 262 |
|
---|
| 263 | /* Make sure tmpfs is running. */
|
---|
| 264 | if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
|
---|
| 265 | spawn("/srv/tmpfs");
|
---|
| 266 | }
|
---|
[860271d4] | 267 |
|
---|
[a095d20] | 268 | spawn("/srv/devfs");
|
---|
[a074b4f] | 269 | spawn("/srv/taskmon");
|
---|
[a095d20] | 270 |
|
---|
| 271 | if (!mount_devfs()) {
|
---|
[62140db] | 272 | printf(NAME ": Exiting\n");
|
---|
[a095d20] | 273 | return -2;
|
---|
| 274 | }
|
---|
[03333bc] | 275 |
|
---|
| 276 | mount_scratch();
|
---|
[a095d20] | 277 |
|
---|
[3e5a814] | 278 | spawn("/srv/fhc");
|
---|
[7a28812] | 279 | spawn("/srv/obio");
|
---|
[3a2f8aa] | 280 | srv_start("/srv/cuda_adb");
|
---|
[9f51afc] | 281 | srv_start("/srv/i8042");
|
---|
[b73c26d] | 282 | srv_start("/srv/adb_ms");
|
---|
| 283 | srv_start("/srv/char_ms");
|
---|
[bb2dbf8] | 284 |
|
---|
[de9c5cb] | 285 | spawn("/srv/fb");
|
---|
| 286 | spawn("/srv/kbd");
|
---|
[47a350f] | 287 | console("hid_in/kbd");
|
---|
| 288 |
|
---|
[fb623e2] | 289 | spawn("/srv/clip");
|
---|
[95bc57c] | 290 |
|
---|
| 291 | /*
|
---|
| 292 | * Start these synchronously so that mount_data() can be
|
---|
| 293 | * non-blocking.
|
---|
| 294 | */
|
---|
[1641eb0] | 295 | #ifdef CONFIG_START_BD
|
---|
[95bc57c] | 296 | srv_start("/srv/ata_bd");
|
---|
| 297 | srv_start("/srv/gxe_bd");
|
---|
[f019cc07] | 298 | #else
|
---|
| 299 | (void) srv_start;
|
---|
| 300 | #endif
|
---|
| 301 |
|
---|
[1641eb0] | 302 | #ifdef CONFIG_MOUNT_DATA
|
---|
[f49cf64] | 303 | mount_data();
|
---|
[f019cc07] | 304 | #else
|
---|
| 305 | (void) mount_data;
|
---|
[1641eb0] | 306 | #endif
|
---|
| 307 |
|
---|
[b73c26d] | 308 | getterm("term/vc0", "/app/bdsh");
|
---|
[df747bd8] | 309 | getterm("term/vc1", "/app/bdsh");
|
---|
| 310 | getterm("term/vc2", "/app/bdsh");
|
---|
| 311 | getterm("term/vc3", "/app/bdsh");
|
---|
| 312 | getterm("term/vc4", "/app/bdsh");
|
---|
| 313 | getterm("term/vc5", "/app/bdsh");
|
---|
[b73c26d] | 314 | getterm("term/vc6", "/app/klog");
|
---|
| 315 |
|
---|
[cb0ea39] | 316 | usleep(1000000);
|
---|
[08d9c4e6] | 317 | //spawn("/srv/dd");
|
---|
| 318 |
|
---|
| 319 | srv_start("/srv/devman");
|
---|
[cb0ea39] | 320 |
|
---|
[3eddaff] | 321 | return 0;
|
---|
| 322 | }
|
---|
[b2951e2] | 323 |
|
---|
| 324 | /** @}
|
---|
| 325 | */
|
---|