start: Avoid infinite loop when BOOTDEVICE is defined
authorRoberto E. Vargas Caballero <k0ga@shike2.com>
Tue, 13 Feb 2018 22:22:52 +0000 (22:22 +0000)
committerRoberto E. Vargas Caballero <k0ga@shike2.com>
Mon, 26 Feb 2018 18:59:08 +0000 (18:59 +0000)
When BOOTDEVICE is defined get_root_dev() was always returning
the same device entering in an infinite loop with the only
effect of scroll out all the previous messages.

Kernel/start.c

index 479e600..c1ee259 100644 (file)
@@ -301,7 +301,13 @@ uint16_t get_root_dev(void)
 
 inline uint16_t get_root_dev(void)
 {
-       return BOOTDEVICE;
+       static uint8_t first = 1;
+
+       if (first) {
+               first = 0;
+               return BOOTDEVICE;
+       }
+       return BAD_ROOT_DEV;
 }
 #endif
 
@@ -370,6 +376,8 @@ void fuzix_main(void)
             old_argptr = argptr;
             /* Get a root device to try */
             root_dev = get_root_dev();
+            if (root_dev == BAD_ROOT_DEV)
+                panic(PANIC_NOROOT);
             /* 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)