From: Matthew Dillon Date: Wed, 1 Sep 2010 07:41:14 +0000 (-0700) Subject: boot system and buildkernel - Additional work X-Git-Tag: v2.9.0~308 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/fc350ba1838006aa2ca8fe90455d3fc4a1f48f37 boot system and buildkernel - Additional work * Make boot work. Note however that dloader does not preload the kernel+modules so basically all you get here is the kernel and acpi with the current menu system setup. The dloader way (for the moment) is: cd kernel loadall boot * Fix console=. dloader was not mirroring the variable to the environment. Also do the same for currdev, loaddev, and bootfile. (kernelname and module_path were already mirrored). * Fix non-numeric menus. 'a' (kernel.alt), 'b' (kernel.bak), and 'R' (reboot). * Space now halts the countdown. * Add the boot-without ACPI option back into dloader.menu. * Move the handling of the kernelname kenv variable out of machine specific code and into kern/init_main.c --- diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c index 0ba83c31c8..018a91fb6c 100644 --- a/sys/boot/common/module.c +++ b/sys/boot/common/module.c @@ -578,7 +578,7 @@ file_lookup(const char *path, const char *name, int namelen, char **extlist) if (len > extlen) extlen = len; } - result = malloc(pathlen + namelen + extlen + 2); + result = malloc(pathlen + namelen + extlen + 2 + 7 + 1); if (result == NULL) return (NULL); bcopy(path, result, pathlen); @@ -589,8 +589,15 @@ file_lookup(const char *path, const char *name, int namelen, char **extlist) cp += namelen; for (cpp = extlist; *cpp; cpp++) { strcpy(cp, *cpp); - if (rel_stat(result, &st) == 0 && S_ISREG(st.st_mode)) { - return result; + if (rel_stat(result, &st) == 0) { + if (S_ISREG(st.st_mode)) { + return result; + } else if (S_ISDIR(st.st_mode)) { + strcat(result, "/kernel"); + if (rel_stat(result, &st) == 0 && S_ISREG(st.st_mode)) { + return result; + } + } } } free(result); @@ -634,10 +641,21 @@ file_search(const char *name, char **extlist) if (*name == 0) return(strdup(name)); + /* + * Qualified name. If it is a directory tag on + * a "/kernel" to it. + */ if (file_havepath(name)) { /* Qualified, so just see if it exists */ - if (rel_stat(name, &sb) == 0) - return(strdup(name)); + if (rel_stat(name, &sb) == 0) { + if (S_ISDIR(sb.st_mode)) { + result = malloc(strlen(name) + 7 + 1); + sprintf(result, "%s/kernel", name); + return(result); + } else { + return(strdup(name)); + } + } return(NULL); } moduledir_rebuild(); diff --git a/sys/boot/dloader/cmds.c b/sys/boot/dloader/cmds.c index 3fb37bda8d..658f9e717e 100644 --- a/sys/boot/dloader/cmds.c +++ b/sys/boot/dloader/cmds.c @@ -117,9 +117,17 @@ command_local(int ac, char **av) else dvar_unset(name); + /* + * These variable have to mirror to kenv because libstand or + * other consumers may have hooks into them. + */ if (strchr(name, '.') || strcmp(name, "kernelname") == 0 || - strcmp(name, "module_path") == 0) { + strcmp(name, "module_path") == 0 || + strcmp(name, "console") == 0 || + strcmp(name, "currdev") == 0 || + strcmp(name, "loaddev") == 0 || + strcmp(name, "bootfile") == 0) { if (*data) setenv(name, data, 1); else @@ -240,13 +248,18 @@ static int command_menuitem(int ac, char **av) { char namebuf[32]; + char *cp; if (ac != 3) { sprintf(command_errbuf, "Bad menuitem syntax"); return (CMD_ERROR); } - curitem = strtol(av[1], NULL, 0); - snprintf(namebuf, sizeof(namebuf), "menu_%d", curitem); + curitem = (unsigned char)av[1][0]; + if (curitem == 0) { + sprintf(command_errbuf, "Bad menuitem syntax"); + return (CMD_ERROR); + } + snprintf(namebuf, sizeof(namebuf), "menu_%c", curitem); dvar_set(namebuf, &av[2], 1); curadd = 0; @@ -264,7 +277,11 @@ command_menuadd(int ac, char **av) if (ac == 1) return(CMD_OK); - snprintf(namebuf, sizeof(namebuf), "item_%d_%d", curitem, curadd); + if (curitem == 0) { + sprintf(command_errbuf, "Missing menuitem for menuadd"); + return(CMD_ERROR); + } + snprintf(namebuf, sizeof(namebuf), "item_%c_%d", curitem, curadd); dvar_set(namebuf, &av[1], ac - 1); ++curadd; return (CMD_OK); @@ -283,6 +300,7 @@ command_menu(int ac, char **av) char *cp; int c; int res; + int counting = 1; menu_display(); if ((cp = getenv("autoboot_delay")) != NULL) @@ -302,6 +320,14 @@ command_menu(int ac, char **av) c = '1'; break; } + if (c == ' ') { + if (counting) { + printf("\rCountdown halted by " + "space "); + } + counting = 0; + continue; + } if (c == 0x1b) { setenv("autoboot_delay", "NO", 1); return(CMD_OK); @@ -313,16 +339,18 @@ command_menu(int ac, char **av) } /* else ignore char */ } - t = time(NULL); - if (time_last == t) - continue; - time_last = t; - printf("\rBooting in %d second%s... ", - (int)(time_target - t), - ((time_target - t) == 1 ? "" : "s")); - if ((int)(time_target - t) <= 0) { - c = '1'; - break; + if (counting) { + t = time(NULL); + if (time_last == t) + continue; + time_last = t; + printf("\rBooting in %d second%s... ", + (int)(time_target - t), + ((time_target - t) == 1 ? "" : "s")); + if ((int)(time_target - t) <= 0) { + c = '1'; + break; + } } } res = menu_execute(c); diff --git a/sys/boot/dloader/dloader.menu b/sys/boot/dloader/dloader.menu index 953b3e0904..caf5599c4e 100644 --- a/sys/boot/dloader/dloader.menu +++ b/sys/boot/dloader/dloader.menu @@ -93,10 +93,12 @@ menuadd loadall menuadd boot menuadd set autoboot_delay=NO -menuitem 6 "Boot DragonFly using kernel.alt" -menuadd cd ${base}kernel.alt +menuitem 6 "Boot DragonFly without ACPI driver" +menuadd cd ${base}kernel menuadd optinclude loader.conf menuadd optinclude loader.conf.local +menuadd set hint.acpi.0.disabled=1 +menuadd set loader.acpi_disabled_by_user=1 menuadd lunsetif acpi_load hint.acpi.0.disabled menuadd lunsetif ehci_load hint.ehci.0.disabled menuadd lunsetif ahci_load hint.ahci.disabled @@ -115,8 +117,11 @@ menuadd loadall menuadd boot menuadd set autoboot_delay=NO -menuitem 8 "Boot Backup kernel kernel.bak" -menuadd cd ${base}kernel.bak +menuitem 9 "Escape to loader prompt (also ESC)" +menuadd set autoboot_delay=NO + +menuitem a "Boot Backup kernel kernel.alt" +menuadd cd ${base}kernel.alt menuadd optinclude loader.conf menuadd optinclude loader.conf.local menuadd lunsetif acpi_load hint.acpi.0.disabled @@ -126,7 +131,15 @@ menuadd loadall menuadd boot menuadd set autoboot_delay=NO -menuitem 9 "Escape to loader prompt (also ESC)" +menuitem b "Boot Backup kernel kernel.bak" +menuadd cd ${base}kernel.bak +menuadd optinclude loader.conf +menuadd optinclude loader.conf.local +menuadd lunsetif acpi_load hint.acpi.0.disabled +menuadd lunsetif ehci_load hint.ehci.0.disabled +menuadd lunsetif ahci_load hint.ahci.disabled +menuadd loadall +menuadd boot menuadd set autoboot_delay=NO menuitem R "Reboot" diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index b62ea10ab8..ea8744c539 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -514,6 +514,14 @@ start_init(void *dummy, struct trapframe *frame) struct lwp *lp; struct mount *mp; struct vnode *vp; + char *env; + + /* + * This is passed in by the bootloader + */ + env = kgetenv("kernelname"); + if (env != NULL) + strlcpy(kernelname, env, sizeof(kernelname)); /* * The MP lock is not held on entry. We release it before diff --git a/sys/platform/pc64/x86_64/machdep.c b/sys/platform/pc64/x86_64/machdep.c index 311ddc5322..378c5e0e0a 100644 --- a/sys/platform/pc64/x86_64/machdep.c +++ b/sys/platform/pc64/x86_64/machdep.c @@ -1639,7 +1639,6 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) #endif struct mdglobaldata *gd; u_int64_t msr; - char *env; #if JG /* @@ -1846,9 +1845,6 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) thread0.td_pcb->pcb_cr3 = KPML4phys; thread0.td_pcb->pcb_ext = 0; lwp0.lwp_md.md_regs = &proc0_tf; - env = kgetenv("kernelname"); - if (env != NULL) - strlcpy(kernelname, env, sizeof(kernelname)); /* Location of kernel stack for locore */ return ((u_int64_t)thread0.td_pcb);