Changes in uspace/app/init/init.c [f019cc07:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/init/init.c
rf019cc07 rffa2c8ef 37 37 #include <stdio.h> 38 38 #include <unistd.h> 39 #include <ipc/ipc.h>40 39 #include <vfs/vfs.h> 41 40 #include <bool.h> … … 46 45 #include <malloc.h> 47 46 #include <macros.h> 48 #include <str ing.h>47 #include <str.h> 49 48 #include <devmap.h> 50 #include < config.h>49 #include <str_error.h> 51 50 #include "init.h" 52 51 52 #define ROOT_DEVICE "bd/initrd" 53 #define ROOT_MOUNT_POINT "/" 54 55 #define DEVFS_FS_TYPE "devfs" 56 #define DEVFS_MOUNT_POINT "/dev" 57 58 #define TMPFS_FS_TYPE "tmpfs" 59 #define TMPFS_MOUNT_POINT "/tmp" 60 61 #define DATA_FS_TYPE "fat" 62 #define DATA_DEVICE "bd/ata1disk0" 63 #define DATA_MOUNT_POINT "/data" 64 65 #define SRV_CONSOLE "/srv/console" 66 #define APP_GETTERM "/app/getterm" 67 53 68 static void info_print(void) 54 69 { 55 printf(NAME ": HelenOS init\n"); 70 printf("%s: HelenOS init\n", NAME); 71 } 72 73 static bool mount_report(const char *desc, const char *mntpt, 74 const char *fstype, const char *dev, int rc) 75 { 76 switch (rc) { 77 case EOK: 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); 83 break; 84 case EBUSY: 85 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt); 86 return false; 87 case ELIMIT: 88 printf("%s: %s limit exceeded\n", NAME, desc); 89 return false; 90 case ENOENT: 91 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype); 92 return false; 93 default: 94 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt, 95 str_error(rc)); 96 return false; 97 } 98 99 return true; 56 100 } 57 101 58 102 static bool mount_root(const char *fstype) 59 103 { 60 char *opts = ""; 61 const char *root_dev = "initrd"; 104 const char *opts = ""; 62 105 63 106 if (str_cmp(fstype, "tmpfs") == 0) 64 107 opts = "restore"; 65 108 66 int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING); 67 68 switch (rc) { 69 case EOK: 70 printf(NAME ": Root filesystem mounted, %s at %s\n", 71 fstype, root_dev); 72 break; 73 case EBUSY: 74 printf(NAME ": Root filesystem already mounted\n"); 75 return false; 76 case ELIMIT: 77 printf(NAME ": Unable to mount root filesystem\n"); 78 return false; 79 case ENOENT: 80 printf(NAME ": Unknown filesystem type (%s)\n", fstype); 81 return false; 82 default: 83 printf(NAME ": Error mounting root filesystem (%d)\n", rc); 84 return false; 85 } 86 87 return true; 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); 88 113 } 89 114 90 115 static bool mount_devfs(void) 91 116 { 92 char null[MAX_DEVICE_NAME]; 93 int null_id = devmap_null_create(); 94 95 if (null_id == -1) { 96 printf(NAME ": Unable to create null device\n"); 97 return false; 98 } 99 100 snprintf(null, MAX_DEVICE_NAME, "null%d", null_id); 101 int rc = mount("devfs", "/dev", null, "", IPC_FLAG_BLOCKING); 102 103 switch (rc) { 104 case EOK: 105 printf(NAME ": Device filesystem mounted\n"); 106 break; 107 case EBUSY: 108 printf(NAME ": Device filesystem already mounted\n"); 109 devmap_null_destroy(null_id); 110 return false; 111 case ELIMIT: 112 printf(NAME ": Unable to mount device filesystem\n"); 113 devmap_null_destroy(null_id); 114 return false; 115 case ENOENT: 116 printf(NAME ": Unknown filesystem type (devfs)\n"); 117 devmap_null_destroy(null_id); 118 return false; 119 default: 120 printf(NAME ": Error mounting device filesystem (%d)\n", rc); 121 devmap_null_destroy(null_id); 122 return false; 123 } 124 125 return true; 126 } 127 128 static void spawn(char *fname) 129 { 130 char *argv[2]; 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); 121 } 122 123 static void spawn(const char *fname) 124 { 125 int rc; 131 126 struct stat s; 132 127 … … 134 129 return; 135 130 136 printf(NAME ": Spawning %s\n", fname); 137 138 argv[0] = fname; 139 argv[1] = NULL; 140 141 if (!task_spawn(fname, argv)) 142 printf(NAME ": Error spawning %s\n", fname); 143 } 144 145 static void srv_start(char *fname) 146 { 147 char *argv[2]; 131 printf("%s: Spawning %s\n", NAME, fname); 132 rc = task_spawnl(NULL, fname, fname, NULL); 133 if (rc != EOK) { 134 printf("%s: Error spawning %s (%s)\n", NAME, fname, 135 str_error(rc)); 136 } 137 } 138 139 static void srv_start(const char *fname) 140 { 148 141 task_id_t id; 149 142 task_exit_t texit; … … 154 147 return; 155 148 156 printf(NAME ": Starting %s\n", fname); 157 158 argv[0] = fname; 159 argv[1] = NULL; 160 161 id = task_spawn(fname, argv); 149 printf("%s: Starting %s\n", NAME, fname); 150 rc = task_spawnl(&id, fname, fname, NULL); 162 151 if (!id) { 163 printf(NAME ": Error spawning %s\n", fname); 164 return; 165 } 166 152 printf("%s: Error spawning %s (%s)\n", NAME, fname, 153 str_error(rc)); 154 return; 155 } 156 167 157 rc = task_wait(id, &texit, &retval); 168 158 if (rc != EOK) { 169 printf(NAME ": Error waiting for %s\n", fname); 170 return; 171 } 172 173 if (texit != TASK_EXIT_NORMAL || retval != 0) { 174 printf(NAME ": Server %s failed to start (returned %d)\n", 159 printf("%s: Error waiting for %s (%s(\n", NAME, fname, 160 str_error(rc)); 161 return; 162 } 163 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, 175 172 fname, retval); 176 173 } 177 174 } 178 175 179 static void getvc(char *dev, char *app) 180 { 181 char *argv[4]; 182 char vc[MAX_DEVICE_NAME]; 176 static void console(const char *dev) 177 { 178 char hid_in[DEVMAP_NAME_MAXLEN]; 183 179 int rc; 184 180 185 snprintf(vc, MAX_DEVICE_NAME, "/dev/%s", dev); 186 187 printf(NAME ": Spawning getvc on %s\n", vc); 188 189 dev_handle_t handle; 181 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 182 183 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in); 184 185 /* Wait for the input device to be ready */ 186 devmap_handle_t handle; 190 187 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING); 191 192 if (rc == EOK) { 193 argv[0] = "/app/getvc"; 194 argv[1] = vc; 195 argv[2] = app; 196 argv[3] = NULL; 197 198 if (!task_spawn("/app/getvc", argv)) 199 printf(NAME ": Error spawning getvc on %s\n", vc); 188 if (rc != EOK) { 189 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in, 190 str_error(rc)); 191 return; 192 } 193 194 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL); 195 if (rc != EOK) { 196 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE, 197 hid_in, str_error(rc)); 198 } 199 } 200 201 static void getterm(const char *dev, const char *app, bool wmsg) 202 { 203 char term[DEVMAP_NAME_MAXLEN]; 204 int rc; 205 206 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 207 208 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app); 209 210 /* Wait for the terminal device to be ready */ 211 devmap_handle_t handle; 212 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING); 213 if (rc != EOK) { 214 printf("%s: Error waiting on %s (%s)\n", NAME, term, 215 str_error(rc)); 216 return; 217 } 218 219 if (wmsg) { 220 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term, 221 app, NULL); 222 if (rc != EOK) { 223 printf("%s: Error spawning %s -w %s %s (%s)\n", NAME, 224 APP_GETTERM, term, app, str_error(rc)); 225 } 200 226 } else { 201 printf(NAME ": Error waiting on %s\n", vc); 202 } 203 } 204 205 static void mount_data(void) 206 { 207 int rc; 208 209 printf("Trying to mount disk0 on /data... "); 210 fflush(stdout); 211 212 rc = mount("fat", "/data", "disk0", "wtcache", 0); 213 if (rc == EOK) 214 printf("OK\n"); 215 else 216 printf("Failed\n"); 227 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app, 228 NULL); 229 if (rc != EOK) { 230 printf("%s: Error spawning %s %s %s (%s)\n", NAME, 231 APP_GETTERM, term, app, str_error(rc)); 232 } 233 } 234 } 235 236 static bool mount_tmpfs(void) 237 { 238 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0); 239 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT, 240 TMPFS_FS_TYPE, NULL, rc); 241 } 242 243 static bool mount_data(void) 244 { 245 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0); 246 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE, 247 DATA_DEVICE, rc); 217 248 } 218 249 … … 222 253 223 254 if (!mount_root(STRING(RDFMT))) { 224 printf( NAME ": Exiting\n");255 printf("%s: Exiting\n", NAME); 225 256 return -1; 226 257 } 227 258 259 /* Make sure tmpfs is running. */ 260 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) { 261 spawn("/srv/tmpfs"); 262 } 263 228 264 spawn("/srv/devfs"); 265 spawn("/srv/taskmon"); 229 266 230 267 if (!mount_devfs()) { 231 printf( NAME ": Exiting\n");268 printf("%s: Exiting\n", NAME); 232 269 return -2; 233 270 } 271 272 mount_tmpfs(); 273 274 spawn("/srv/apic"); 275 spawn("/srv/i8259"); 276 spawn("/srv/fhc"); 277 spawn("/srv/obio"); 278 srv_start("/srv/cuda_adb"); 279 srv_start("/srv/i8042"); 280 srv_start("/srv/s3c24ser"); 281 srv_start("/srv/adb_ms"); 282 srv_start("/srv/char_ms"); 283 srv_start("/srv/s3c24ts"); 234 284 235 285 spawn("/srv/fb"); 236 286 spawn("/srv/kbd"); 237 spawn("/srv/console");238 spawn("/srv/fhc");239 spawn("/srv/ obio");240 287 console("hid_in/kbd"); 288 289 spawn("/srv/clip"); 290 241 291 /* 242 292 * Start these synchronously so that mount_data() can be … … 249 299 (void) srv_start; 250 300 #endif 251 301 252 302 #ifdef CONFIG_MOUNT_DATA 253 303 mount_data(); … … 255 305 (void) mount_data; 256 306 #endif 257 258 get vc("vc0", "/app/bdsh");259 get vc("vc1", "/app/bdsh");260 get vc("vc2", "/app/bdsh");261 get vc("vc3", "/app/bdsh");262 get vc("vc4", "/app/bdsh");263 get vc("vc5", "/app/bdsh");264 get vc("vc6", "/app/klog");307 308 getterm("term/vc0", "/app/bdsh", true); 309 getterm("term/vc1", "/app/bdsh", false); 310 getterm("term/vc2", "/app/bdsh", false); 311 getterm("term/vc3", "/app/bdsh", false); 312 getterm("term/vc4", "/app/bdsh", false); 313 getterm("term/vc5", "/app/bdsh", false); 314 getterm("term/vc6", "/app/klog", false); 265 315 266 316 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.