source: mainline/uspace/app/init/init.c@ a05f2af

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a05f2af was a05f2af, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

init: Fix frame buffer enabled build

  • Property mode set to 100644
File size: 10.1 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>
[6d5e378]39#include <stdarg.h>
[860271d4]40#include <vfs/vfs.h>
[3e6a98c5]41#include <stdbool.h>
[860271d4]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>
[15f3c3f]49#include <loc.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
[15f3c3f]56#define LOCFS_FS_TYPE "locfs"
57#define LOCFS_MOUNT_POINT "/loc"
[47a350f]58
[1ab0852]59#define TMPFS_FS_TYPE "tmpfs"
60#define TMPFS_MOUNT_POINT "/tmp"
[d9fae235]61
62#define DATA_FS_TYPE "fat"
[e092dc5]63#define DATA_DEVICE "bd/ata1disk0"
[d9fae235]64#define DATA_MOUNT_POINT "/data"
65
[47a350f]66#define SRV_CONSOLE "/srv/console"
[df747bd8]67#define APP_GETTERM "/app/getterm"
[47a350f]68
[6d5e378]69#define SRV_COMPOSITOR "/srv/compositor"
70
71#define HID_INPUT "hid/input"
72#define HID_OUTPUT "hid/output"
73#define HID_COMPOSITOR_SERVER ":0"
74
75#define srv_start(path, ...) \
76 srv_startl(path, path, ##__VA_ARGS__, NULL)
77
[53d6ac3d]78/** Print banner */
[36b8100a]79static void info_print(void)
80{
[d9fae235]81 printf("%s: HelenOS init\n", NAME);
[36b8100a]82}
83
[53d6ac3d]84/** Report mount operation success */
[d9fae235]85static bool mount_report(const char *desc, const char *mntpt,
86 const char *fstype, const char *dev, int rc)
[860271d4]87{
[f49cf64]88 switch (rc) {
89 case EOK:
[d9fae235]90 if (dev != NULL)
91 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
92 fstype, dev);
93 else
94 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
[f49cf64]95 break;
96 case EBUSY:
[d9fae235]97 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
[f49cf64]98 return false;
99 case ELIMIT:
[d9fae235]100 printf("%s: %s limit exceeded\n", NAME, desc);
[f49cf64]101 return false;
102 case ENOENT:
[d9fae235]103 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
[f49cf64]104 return false;
105 default:
[d9fae235]106 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
107 str_error(rc));
[f49cf64]108 return false;
[860271d4]109 }
110
111 return true;
112}
113
[53d6ac3d]114/** Mount root filesystem
115 *
116 * The operation blocks until the root filesystem
117 * server is ready for mounting.
118 *
119 * @param[in] fstype Root filesystem type.
120 *
121 * @return True on success.
122 * @return False on failure.
123 *
124 */
[d9fae235]125static bool mount_root(const char *fstype)
[a095d20]126{
[d9fae235]127 const char *opts = "";
[f49cf64]128
[d9fae235]129 if (str_cmp(fstype, "tmpfs") == 0)
130 opts = "restore";
[a095d20]131
[d9fae235]132 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
[4979403]133 IPC_FLAG_BLOCKING, 0);
[d9fae235]134 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
135 ROOT_DEVICE, rc);
136}
137
[53d6ac3d]138/** Mount locfs filesystem
139 *
140 * The operation blocks until the locfs filesystem
141 * server is ready for mounting.
142 *
143 * @return True on success.
144 * @return False on failure.
145 *
146 */
[15f3c3f]147static bool mount_locfs(void)
[d9fae235]148{
[15f3c3f]149 int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
[4979403]150 IPC_FLAG_BLOCKING, 0);
[15f3c3f]151 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
152 LOCFS_FS_TYPE, NULL, rc);
[a095d20]153}
154
[6d5e378]155static int srv_startl(const char *path, ...)
[860271d4]156{
[1757ffce]157 struct stat s;
[6d5e378]158 if (stat(path, &s) == ENOENT) {
159 printf("%s: Unable to stat %s\n", NAME, path);
160 return ENOENT;
161 }
[1757ffce]162
[6d5e378]163 printf("%s: Starting %s\n", NAME, path);
164
165 va_list ap;
166 const char *arg;
167 int cnt = 0;
168
169 va_start(ap, path);
170 do {
171 arg = va_arg(ap, const char *);
172 cnt++;
173 } while (arg != NULL);
174 va_end(ap);
175
176 va_start(ap, path);
177 task_id_t id;
178 int rc = task_spawn(&id, path, cnt, ap);
179 va_end(ap);
[c91c9fb]180
[0485135]181 if (rc != EOK) {
[6d5e378]182 printf("%s: Error spawning %s (%s)\n", NAME, path,
[0485135]183 str_error(rc));
[6d5e378]184 return rc;
[0485135]185 }
[95bc57c]186
187 if (!id) {
[6d5e378]188 printf("%s: Error spawning %s (invalid task id)\n", NAME,
189 path);
190 return EINVAL;
[95bc57c]191 }
[d9fae235]192
[6d5e378]193 task_exit_t texit;
194 int retval;
[95bc57c]195 rc = task_wait(id, &texit, &retval);
196 if (rc != EOK) {
[6d5e378]197 printf("%s: Error waiting for %s (%s)\n", NAME, path,
[0485135]198 str_error(rc));
[6d5e378]199 return rc;
[95bc57c]200 }
[d9fae235]201
[0485135]202 if (texit != TASK_EXIT_NORMAL) {
203 printf("%s: Server %s failed to start (unexpectedly "
[6d5e378]204 "terminated)\n", NAME, path);
205 return EINVAL;
[0485135]206 }
[6d5e378]207
208 if (retval != 0)
[0485135]209 printf("%s: Server %s failed to start (exit code %d)\n", NAME,
[6d5e378]210 path, retval);
211
212 return retval;
[95bc57c]213}
214
[6d5e378]215static int console(const char *isvc, const char *osvc)
[47a350f]216{
[15f3c3f]217 /* Wait for the input service to be ready */
218 service_id_t service_id;
[7c014d1]219 int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
[0485135]220 if (rc != EOK) {
[7c014d1]221 printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
[d9fae235]222 str_error(rc));
[6d5e378]223 return rc;
[0485135]224 }
225
[6d5e378]226 /* Wait for the output service to be ready */
227 rc = loc_service_get_id(osvc, &service_id, IPC_FLAG_BLOCKING);
[0485135]228 if (rc != EOK) {
[6d5e378]229 printf("%s: Error waiting on %s (%s)\n", NAME, osvc,
[7c014d1]230 str_error(rc));
[6d5e378]231 return rc;
232 }
233
234 return srv_start(SRV_CONSOLE, isvc, osvc);
235}
236
237static int compositor(const char *isvc, const char *name)
238{
239 /* Wait for the input service to be ready */
240 service_id_t service_id;
241 int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
242 if (rc != EOK) {
243 printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
244 str_error(rc));
245 return rc;
[7c014d1]246 }
247
[6d5e378]248 return srv_start(SRV_COMPOSITOR, isvc, name);
249}
250
251static int gui_start(const char *app, const char *srv_name)
252{
253 char winreg[50];
254 snprintf(winreg, sizeof(winreg), "%s%s%s", "comp", srv_name, "/winreg");
255
256 printf("%s: Spawning %s %s\n", NAME, app, winreg);
257
258 task_id_t id;
259 int rc = task_spawnl(&id, app, app, winreg, NULL);
[7c014d1]260 if (rc != EOK) {
[6d5e378]261 printf("%s: Error spawning %s %s (%s)\n", NAME, app,
262 winreg, str_error(rc));
263 return -1;
[0485135]264 }
[6d5e378]265
266 task_exit_t texit;
267 int retval;
268 rc = task_wait(id, &texit, &retval);
269 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
270 printf("%s: Error retrieving retval from %s (%s)\n", NAME,
271 app, str_error(rc));
272 return -1;
[0485135]273 }
[6d5e378]274
275 return retval;
[47a350f]276}
277
[15f3c3f]278static void getterm(const char *svc, const char *app, bool wmsg)
[36b8100a]279{
[15f3c3f]280 char term[LOC_NAME_MAXLEN];
281 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc);
[36b8100a]282
[d9fae235]283 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
[36b8100a]284
[15f3c3f]285 /* Wait for the terminal service to be ready */
286 service_id_t service_id;
[6d5e378]287 int rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
[0485135]288 if (rc != EOK) {
[d9fae235]289 printf("%s: Error waiting on %s (%s)\n", NAME, term,
290 str_error(rc));
[0485135]291 return;
292 }
293
[4deb8b5]294 if (wmsg) {
295 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
296 app, NULL);
297 if (rc != EOK) {
298 printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
299 APP_GETTERM, term, app, str_error(rc));
300 }
301 } else {
302 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
303 NULL);
304 if (rc != EOK) {
305 printf("%s: Error spawning %s %s %s (%s)\n", NAME,
306 APP_GETTERM, term, app, str_error(rc));
307 }
[0485135]308 }
[36b8100a]309}
310
[1ab0852]311static bool mount_tmpfs(void)
[03333bc]312{
[4979403]313 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
[1ab0852]314 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
315 TMPFS_FS_TYPE, NULL, rc);
[03333bc]316}
317
[d9fae235]318static bool mount_data(void)
[00fe6bb]319{
[4979403]320 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0, 0);
[d9fae235]321 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
322 DATA_DEVICE, rc);
[00fe6bb]323}
324
[5106e98]325int main(int argc, char *argv[])
326{
[860271d4]327 info_print();
328
[36b8100a]329 if (!mount_root(STRING(RDFMT))) {
[d9fae235]330 printf("%s: Exiting\n", NAME);
[6d5e378]331 return 1;
[860271d4]332 }
[d9fae235]333
[03333bc]334 /* Make sure tmpfs is running. */
[6d5e378]335 if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
336 srv_start("/srv/tmpfs");
[860271d4]337
[6d5e378]338 srv_start("/srv/locfs");
339 srv_start("/srv/taskmon");
[a095d20]340
[15f3c3f]341 if (!mount_locfs()) {
[d9fae235]342 printf("%s: Exiting\n", NAME);
[6d5e378]343 return 2;
[a095d20]344 }
[d9fae235]345
[1ab0852]346 mount_tmpfs();
[a095d20]347
[6d5e378]348 srv_start("/srv/devman");
349 srv_start("/srv/apic");
350 srv_start("/srv/i8259");
351 srv_start("/srv/obio");
[3a2f8aa]352 srv_start("/srv/cuda_adb");
[f7cbc6f]353 srv_start("/srv/s3c24xx_uart");
354 srv_start("/srv/s3c24xx_ts");
[d9fae235]355
[6d5e378]356 srv_start("/srv/loopip");
357 srv_start("/srv/ethip");
358 srv_start("/srv/inetsrv");
359 srv_start("/srv/tcp");
360 srv_start("/srv/udp");
[00d7e1b]361
[6d5e378]362 srv_start("/srv/clipboard");
363 srv_start("/srv/remcons");
[d9fae235]364
[95bc57c]365 /*
366 * Start these synchronously so that mount_data() can be
367 * non-blocking.
368 */
[1641eb0]369#ifdef CONFIG_START_BD
[95bc57c]370 srv_start("/srv/ata_bd");
371 srv_start("/srv/gxe_bd");
[f019cc07]372#endif
[d9fae235]373
[1641eb0]374#ifdef CONFIG_MOUNT_DATA
[1bfae13]375 /* Make sure fat is running. */
[6d5e378]376 if (str_cmp(STRING(RDFMT), "fat") != 0)
[1bfae13]377 srv_start("/srv/fat");
[6d5e378]378
[f49cf64]379 mount_data();
[f019cc07]380#else
381 (void) mount_data;
[1641eb0]382#endif
[d9fae235]383
[6d5e378]384 srv_start("/srv/input", HID_INPUT);
385 srv_start("/srv/output", HID_OUTPUT);
386
387 int rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
388 if (rc == EOK) {
389 gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER);
390 gui_start("/app/vterm", HID_COMPOSITOR_SERVER);
391 } else {
392 rc = console(HID_INPUT, HID_OUTPUT);
393 if (rc == EOK) {
[a05f2af]394#ifndef CONFIG_VC_COUNT
395#define CONFIG_VC_COUNT 6
396#endif
[03362fbd]397 switch((unsigned)CONFIG_VC_COUNT) {
398 default:
399 case 6: getterm("term/vc5", "/app/bdsh", false);
400 case 5: getterm("term/vc4", "/app/bdsh", false);
401 case 4: getterm("term/vc3", "/app/bdsh", false);
402 case 3: getterm("term/vc2", "/app/bdsh", false);
403 case 2: getterm("term/vc1", "/app/bdsh", false);
404 case 1: getterm("term/vc0", "/app/bdsh", true);
405 }
[a27d1c5]406#ifdef CONFIG_KERNEL_LOG_VC_6
[6d5e378]407 getterm("term/vc6", "/app/klog", false);
[a27d1c5]408#endif
[6d5e378]409 }
410 }
[22dfd38]411 srv_start("/srv/hound");
[d9fae235]412
[3eddaff]413 return 0;
414}
[b2951e2]415
416/** @}
417 */
Note: See TracBrowser for help on using the repository browser.