Kernel: Make "bootdev:" prompt friendlier.
authorWill Sowerbutts <will@sowerbutts.com>
Fri, 6 Jan 2017 19:23:43 +0000 (19:23 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Sun, 8 Jan 2017 23:05:11 +0000 (23:05 +0000)
This change runs the device drivers to initialise and report the
available device names to the user (where probing is possible) before
the user is asked to choose a boot device. We now also ask the user
to choose again if the selected device cannot be booted.

Kernel/include/panic.h
Kernel/start.c

index 4ec59f3..1cc842d 100644 (file)
@@ -24,7 +24,6 @@
 #define PANIC_VALIDBLK_INV     "validblk: invalid blk"
 #define PANIC_GETINO_BADT      "getinode: bad desc table"
 #define PANIC_GETINO_OFT       "getinode: bad OFT"
-#define PANIC_FMOUNT_NOPEN     "fmount: can't open filesystem"
 #define PANIC_CORRUPTI         "corrupt inode"
 #define PANIC_VOODOO           "psleep: voodoo"
 #define PANIC_GETPROC          "getproc: extra running"
index d6558d9..8cb7e0b 100644 (file)
@@ -65,8 +65,8 @@ void fstabinit(void)
       size differ due to memory models etc. We use uputp and we allow
       room for the pointers to be bigger than kernel */
 
-static uaddr_t progptr;
-static uaddr_t argptr;
+static uaddr_t progptr, old_progptr;
+static uaddr_t argptr, old_argptr;
 
 void add_argument(const char *s)
 {
@@ -162,7 +162,7 @@ static uint8_t system_param(char *p)
 {
        if (*p == 'r' && p[2] == 0) {
                if (p[1] == 'o') {
-                       ro = 1;
+                       ro = MS_RDONLY;
                        return 1;
                } else if (p[1] == 'w') {
                        ro = 0;
@@ -278,8 +278,10 @@ uint16_t get_root_dev(void)
 {
        uint16_t rd = BAD_ROOT_DEV;
 
-       if (cmdline && *cmdline)
+       if (cmdline && *cmdline){
                rd = bootdevice(cmdline);
+                cmdline=NULL;                   /* ignore cmdline if get_root_dev() is called again */
+        }
 
        while(rd == BAD_ROOT_DEV){
                kputs("bootdev: ");
@@ -359,27 +361,34 @@ void fuzix_main(void)
        __hard_ei();            /* Physical interrupts on */
        kputs("ok.\n");
 
-       /* get the root device */
-       root_dev = get_root_dev();
-
-       /* finish building argv */
-       complete_init();
-
        /* initialise hardware devices */
        device_init();
 
-       /* Mount the root device */
-       kprintf("Mounting root fs (root_dev=%d, r%c): ", root_dev,
-               ro ? 'o' : 'w');
+        while(true){
+            old_progptr = progptr;
+            old_argptr = argptr;
+            /* Get a root device to try */
+            root_dev = get_root_dev();
+            /* Mount the root device */
+            kprintf("Mounting root fs (root_dev=%d, r%c): ", root_dev, ro ? 'o' : 'w');
+            if(fmount(root_dev, NULLINODE, ro) == 0)
+                break;
+            kputs("failed\n");
+            /* reset potentially altered state before prompting the user for command line again */
+            progptr = old_progptr;
+            argptr = old_argptr;
+            ro = 0;
+        }
 
-       if (fmount(root_dev, NULLINODE, ro))
-               panic(PANIC_NOFILESYS);
        root = i_open(root_dev, ROOTINODE);
        if (!root)
                panic(PANIC_NOROOT);
 
        kputs("OK\n");
 
+       /* finish building argv */
+       complete_init();
+
        udata.u_cwd = i_ref(root);
        udata.u_root = i_ref(root);
        rdtime32(&udata.u_time);