1c2a2cf83497d6fbb7521f5f551dacbd47042fac
[lunaix-os.git] / lunaix-os / hal / term / console.c
1 #include <lunaix/device.h>
2 #include <lunaix/owloysius.h>
3 #include <lunaix/spike.h>
4 #include <lunaix/kcmd.h>
5 #include <lunaix/fs.h>
6 #include <lunaix/syslog.h>
7 #include <lunaix/kprintf.h>
8
9 #include <hal/term.h>
10
11 LOG_MODULE("console")
12
13 static void 
14 setup_default_tty()  
15 {
16     char* console_dev;
17     if(!kcmd_get_option("console", &console_dev)) {
18         FATAL("I am expecting a console!");
19         // should not reach
20     }
21
22     struct v_dnode* dn;
23     int err;
24
25     if ((err = vfs_walk(NULL, console_dev, &dn, NULL, 0))) {
26         FATAL("unable to set console: %s, err=%d", console_dev, err);
27         // should not reach
28     }
29
30     struct device* dev = resolve_device(dn->inode->data);
31     if (!dev) {
32         FATAL("not a device: %s", console_dev);
33         // should not reach
34     }
35
36     assert(device_addalias(NULL, dev_meta(dev), "tty"));
37     
38     if (!device_get_capability(dev, TERMIOS_CAP)) {
39         FATAL("not a terminal device: %s", console_dev);
40     }
41
42     INFO("system console: %s", console_dev);
43
44     sysconsole = dev;
45
46     kprintf_dump_logs();
47 }
48 owloysius_fetch_init(setup_default_tty, on_boot);