From 7b79ebc6c76842485f63f4dcd31925833533a558 Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Fri, 6 Jan 2017 19:23:43 +0000 Subject: [PATCH] Kernel: Make "bootdev:" prompt friendlier. 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 | 1 - Kernel/start.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Kernel/include/panic.h b/Kernel/include/panic.h index 4ec59f34..1cc842d0 100644 --- a/Kernel/include/panic.h +++ b/Kernel/include/panic.h @@ -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" diff --git a/Kernel/start.c b/Kernel/start.c index d6558d9c..8cb7e0bc 100644 --- a/Kernel/start.c +++ b/Kernel/start.c @@ -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); -- 2.34.1