[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>
|
---|
| 39 | #include <vfs/vfs.h>
|
---|
| 40 | #include <bool.h>
|
---|
| 41 | #include <errno.h>
|
---|
| 42 | #include <fcntl.h>
|
---|
[1757ffce] | 43 | #include <sys/stat.h>
|
---|
[860271d4] | 44 | #include <task.h>
|
---|
| 45 | #include <malloc.h>
|
---|
[c91c9fb] | 46 | #include <macros.h>
|
---|
[19f857a] | 47 | #include <str.h>
|
---|
[36b8100a] | 48 | #include <devmap.h>
|
---|
[d9fae235] | 49 | #include <str_error.h>
|
---|
[860271d4] | 50 | #include "init.h"
|
---|
| 51 |
|
---|
[d9fae235] | 52 | #define ROOT_DEVICE "bd/initrd"
|
---|
| 53 | #define ROOT_MOUNT_POINT "/"
|
---|
| 54 |
|
---|
| 55 | #define DEVFS_FS_TYPE "devfs"
|
---|
[47a350f] | 56 | #define DEVFS_MOUNT_POINT "/dev"
|
---|
| 57 |
|
---|
[1ab0852] | 58 | #define TMPFS_FS_TYPE "tmpfs"
|
---|
| 59 | #define TMPFS_MOUNT_POINT "/tmp"
|
---|
[d9fae235] | 60 |
|
---|
| 61 | #define DATA_FS_TYPE "fat"
|
---|
[e092dc5] | 62 | #define DATA_DEVICE "bd/ata1disk0"
|
---|
[d9fae235] | 63 | #define DATA_MOUNT_POINT "/data"
|
---|
| 64 |
|
---|
[47a350f] | 65 | #define SRV_CONSOLE "/srv/console"
|
---|
[df747bd8] | 66 | #define APP_GETTERM "/app/getterm"
|
---|
[47a350f] | 67 |
|
---|
[36b8100a] | 68 | static void info_print(void)
|
---|
| 69 | {
|
---|
[d9fae235] | 70 | printf("%s: HelenOS init\n", NAME);
|
---|
[36b8100a] | 71 | }
|
---|
| 72 |
|
---|
[d9fae235] | 73 | static bool mount_report(const char *desc, const char *mntpt,
|
---|
| 74 | const char *fstype, const char *dev, int rc)
|
---|
[860271d4] | 75 | {
|
---|
[f49cf64] | 76 | switch (rc) {
|
---|
| 77 | case EOK:
|
---|
[d9fae235] | 78 | if (dev != NULL)
|
---|
| 79 | printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
|
---|
| 80 | fstype, dev);
|
---|
| 81 | else
|
---|
| 82 | printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
|
---|
[f49cf64] | 83 | break;
|
---|
| 84 | case EBUSY:
|
---|
[d9fae235] | 85 | printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
|
---|
[f49cf64] | 86 | return false;
|
---|
| 87 | case ELIMIT:
|
---|
[d9fae235] | 88 | printf("%s: %s limit exceeded\n", NAME, desc);
|
---|
[f49cf64] | 89 | return false;
|
---|
| 90 | case ENOENT:
|
---|
[d9fae235] | 91 | printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
|
---|
[f49cf64] | 92 | return false;
|
---|
| 93 | default:
|
---|
[d9fae235] | 94 | printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
|
---|
| 95 | str_error(rc));
|
---|
[f49cf64] | 96 | return false;
|
---|
[860271d4] | 97 | }
|
---|
| 98 |
|
---|
| 99 | return true;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[d9fae235] | 102 | static bool mount_root(const char *fstype)
|
---|
[a095d20] | 103 | {
|
---|
[d9fae235] | 104 | const char *opts = "";
|
---|
[f49cf64] | 105 |
|
---|
[d9fae235] | 106 | if (str_cmp(fstype, "tmpfs") == 0)
|
---|
| 107 | opts = "restore";
|
---|
[a095d20] | 108 |
|
---|
[d9fae235] | 109 | int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
|
---|
| 110 | IPC_FLAG_BLOCKING);
|
---|
| 111 | return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
|
---|
| 112 | ROOT_DEVICE, rc);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | static bool mount_devfs(void)
|
---|
| 116 | {
|
---|
| 117 | int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
|
---|
| 118 | IPC_FLAG_BLOCKING);
|
---|
| 119 | return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
|
---|
| 120 | NULL, rc);
|
---|
[a095d20] | 121 | }
|
---|
| 122 |
|
---|
[a000878c] | 123 | static void spawn(const char *fname)
|
---|
[860271d4] | 124 | {
|
---|
[0485135] | 125 | int rc;
|
---|
[1757ffce] | 126 | struct stat s;
|
---|
| 127 |
|
---|
| 128 | if (stat(fname, &s) == ENOENT)
|
---|
| 129 | return;
|
---|
[c91c9fb] | 130 |
|
---|
[d9fae235] | 131 | printf("%s: Spawning %s\n", NAME, fname);
|
---|
[0485135] | 132 | rc = task_spawnl(NULL, fname, fname, NULL);
|
---|
| 133 | if (rc != EOK) {
|
---|
[d9fae235] | 134 | printf("%s: Error spawning %s (%s)\n", NAME, fname,
|
---|
[0485135] | 135 | str_error(rc));
|
---|
| 136 | }
|
---|
[b27a97bb] | 137 | }
|
---|
| 138 |
|
---|
[a000878c] | 139 | static void srv_start(const char *fname)
|
---|
[95bc57c] | 140 | {
|
---|
| 141 | task_id_t id;
|
---|
| 142 | task_exit_t texit;
|
---|
| 143 | int rc, retval;
|
---|
[1757ffce] | 144 | struct stat s;
|
---|
| 145 |
|
---|
| 146 | if (stat(fname, &s) == ENOENT)
|
---|
| 147 | return;
|
---|
[95bc57c] | 148 |
|
---|
[d9fae235] | 149 | printf("%s: Starting %s\n", NAME, fname);
|
---|
[0485135] | 150 | rc = task_spawnl(&id, fname, fname, NULL);
|
---|
[95bc57c] | 151 | if (!id) {
|
---|
[d9fae235] | 152 | printf("%s: Error spawning %s (%s)\n", NAME, fname,
|
---|
[0485135] | 153 | str_error(rc));
|
---|
[95bc57c] | 154 | return;
|
---|
| 155 | }
|
---|
[d9fae235] | 156 |
|
---|
[95bc57c] | 157 | rc = task_wait(id, &texit, &retval);
|
---|
| 158 | if (rc != EOK) {
|
---|
[d9fae235] | 159 | printf("%s: Error waiting for %s (%s(\n", NAME, fname,
|
---|
[0485135] | 160 | str_error(rc));
|
---|
[95bc57c] | 161 | return;
|
---|
| 162 | }
|
---|
[d9fae235] | 163 |
|
---|
[0485135] | 164 | if (texit != TASK_EXIT_NORMAL) {
|
---|
| 165 | printf("%s: Server %s failed to start (unexpectedly "
|
---|
| 166 | "terminated)\n", NAME, fname);
|
---|
| 167 | return;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | if (retval != 0) {
|
---|
| 171 | printf("%s: Server %s failed to start (exit code %d)\n", NAME,
|
---|
| 172 | fname, retval);
|
---|
[95bc57c] | 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[a000878c] | 176 | static void console(const char *dev)
|
---|
[47a350f] | 177 | {
|
---|
[79ae36dd] | 178 | printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, dev);
|
---|
[47a350f] | 179 |
|
---|
| 180 | /* Wait for the input device to be ready */
|
---|
[991f645] | 181 | devmap_handle_t handle;
|
---|
[79ae36dd] | 182 | int rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
|
---|
[0485135] | 183 | if (rc != EOK) {
|
---|
[79ae36dd] | 184 | printf("%s: Error waiting on %s (%s)\n", NAME, dev,
|
---|
[d9fae235] | 185 | str_error(rc));
|
---|
[0485135] | 186 | return;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[79ae36dd] | 189 | rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, dev, NULL);
|
---|
[0485135] | 190 | if (rc != EOK) {
|
---|
| 191 | printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
|
---|
[79ae36dd] | 192 | dev, str_error(rc));
|
---|
[0485135] | 193 | }
|
---|
[47a350f] | 194 | }
|
---|
| 195 |
|
---|
[4deb8b5] | 196 | static void getterm(const char *dev, const char *app, bool wmsg)
|
---|
[36b8100a] | 197 | {
|
---|
[28be7fa] | 198 | char term[DEVMAP_NAME_MAXLEN];
|
---|
[62140db] | 199 | int rc;
|
---|
[36b8100a] | 200 |
|
---|
[28be7fa] | 201 | snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
|
---|
[36b8100a] | 202 |
|
---|
[d9fae235] | 203 | printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
|
---|
[36b8100a] | 204 |
|
---|
[47a350f] | 205 | /* Wait for the terminal device to be ready */
|
---|
[991f645] | 206 | devmap_handle_t handle;
|
---|
[62140db] | 207 | rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
|
---|
[0485135] | 208 | if (rc != EOK) {
|
---|
[d9fae235] | 209 | printf("%s: Error waiting on %s (%s)\n", NAME, term,
|
---|
| 210 | str_error(rc));
|
---|
[0485135] | 211 | return;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[4deb8b5] | 214 | if (wmsg) {
|
---|
| 215 | rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
|
---|
| 216 | app, NULL);
|
---|
| 217 | if (rc != EOK) {
|
---|
| 218 | printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
|
---|
| 219 | APP_GETTERM, term, app, str_error(rc));
|
---|
| 220 | }
|
---|
| 221 | } else {
|
---|
| 222 | rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
|
---|
| 223 | NULL);
|
---|
| 224 | if (rc != EOK) {
|
---|
| 225 | printf("%s: Error spawning %s %s %s (%s)\n", NAME,
|
---|
| 226 | APP_GETTERM, term, app, str_error(rc));
|
---|
| 227 | }
|
---|
[0485135] | 228 | }
|
---|
[36b8100a] | 229 | }
|
---|
| 230 |
|
---|
[1ab0852] | 231 | static bool mount_tmpfs(void)
|
---|
[03333bc] | 232 | {
|
---|
[1ab0852] | 233 | int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0);
|
---|
| 234 | return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
|
---|
| 235 | TMPFS_FS_TYPE, NULL, rc);
|
---|
[03333bc] | 236 | }
|
---|
| 237 |
|
---|
[d9fae235] | 238 | static bool mount_data(void)
|
---|
[00fe6bb] | 239 | {
|
---|
[d9fae235] | 240 | int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
|
---|
| 241 | return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
|
---|
| 242 | DATA_DEVICE, rc);
|
---|
[00fe6bb] | 243 | }
|
---|
| 244 |
|
---|
[5106e98] | 245 | int main(int argc, char *argv[])
|
---|
| 246 | {
|
---|
[860271d4] | 247 | info_print();
|
---|
| 248 |
|
---|
[36b8100a] | 249 | if (!mount_root(STRING(RDFMT))) {
|
---|
[d9fae235] | 250 | printf("%s: Exiting\n", NAME);
|
---|
[860271d4] | 251 | return -1;
|
---|
| 252 | }
|
---|
[d9fae235] | 253 |
|
---|
[03333bc] | 254 | /* Make sure tmpfs is running. */
|
---|
| 255 | if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
|
---|
| 256 | spawn("/srv/tmpfs");
|
---|
| 257 | }
|
---|
[860271d4] | 258 |
|
---|
[a095d20] | 259 | spawn("/srv/devfs");
|
---|
[a074b4f] | 260 | spawn("/srv/taskmon");
|
---|
[a095d20] | 261 |
|
---|
| 262 | if (!mount_devfs()) {
|
---|
[d9fae235] | 263 | printf("%s: Exiting\n", NAME);
|
---|
[a095d20] | 264 | return -2;
|
---|
| 265 | }
|
---|
[d9fae235] | 266 |
|
---|
[1ab0852] | 267 | mount_tmpfs();
|
---|
[a095d20] | 268 |
|
---|
[3acb285a] | 269 | spawn("/srv/devman");
|
---|
[acc7ce4] | 270 | spawn("/srv/apic");
|
---|
| 271 | spawn("/srv/i8259");
|
---|
[bb2dbf8] | 272 | spawn("/srv/obio");
|
---|
[3a2f8aa] | 273 | srv_start("/srv/cuda_adb");
|
---|
[9f51afc] | 274 | srv_start("/srv/i8042");
|
---|
[a9b5b5f] | 275 | srv_start("/srv/s3c24ser");
|
---|
[527298a] | 276 | srv_start("/srv/s3c24ts");
|
---|
[d9fae235] | 277 |
|
---|
[de9c5cb] | 278 | spawn("/srv/fb");
|
---|
[5f88293] | 279 | spawn("/srv/input");
|
---|
[1875a0c] | 280 | console("hid/input");
|
---|
[47a350f] | 281 |
|
---|
[fb623e2] | 282 | spawn("/srv/clip");
|
---|
[d9fae235] | 283 |
|
---|
[95bc57c] | 284 | /*
|
---|
| 285 | * Start these synchronously so that mount_data() can be
|
---|
| 286 | * non-blocking.
|
---|
| 287 | */
|
---|
[1641eb0] | 288 | #ifdef CONFIG_START_BD
|
---|
[95bc57c] | 289 | srv_start("/srv/ata_bd");
|
---|
| 290 | srv_start("/srv/gxe_bd");
|
---|
[f019cc07] | 291 | #else
|
---|
| 292 | (void) srv_start;
|
---|
| 293 | #endif
|
---|
[d9fae235] | 294 |
|
---|
[1641eb0] | 295 | #ifdef CONFIG_MOUNT_DATA
|
---|
[18b5228b] | 296 | /* Make sure fat is running. */
|
---|
| 297 | if (str_cmp(STRING(RDFMT), "fat") != 0) {
|
---|
| 298 | spawn("/srv/fat");
|
---|
| 299 | }
|
---|
[f49cf64] | 300 | mount_data();
|
---|
[f019cc07] | 301 | #else
|
---|
| 302 | (void) mount_data;
|
---|
[1641eb0] | 303 | #endif
|
---|
[d9fae235] | 304 |
|
---|
[4deb8b5] | 305 | getterm("term/vc0", "/app/bdsh", true);
|
---|
| 306 | getterm("term/vc1", "/app/bdsh", false);
|
---|
| 307 | getterm("term/vc2", "/app/bdsh", false);
|
---|
| 308 | getterm("term/vc3", "/app/bdsh", false);
|
---|
| 309 | getterm("term/vc4", "/app/bdsh", false);
|
---|
| 310 | getterm("term/vc5", "/app/bdsh", false);
|
---|
| 311 | getterm("term/vc6", "/app/klog", false);
|
---|
[d9fae235] | 312 |
|
---|
[3eddaff] | 313 | return 0;
|
---|
| 314 | }
|
---|
[b2951e2] | 315 |
|
---|
| 316 | /** @}
|
---|
| 317 | */
|
---|