Module Name: src Committed By: uebayasi Date: Thu May 26 04:25:28 UTC 2011
Modified Files: src/share/man/man5: boot.cfg.5 src/share/man/man8/man8.i386: boot.8 src/sys/arch/i386/stand/boot: boot2.c src/sys/arch/i386/stand/lib: bootmenu.c exec.c libi386.h src/sys/arch/i386/stand/pxeboot: main.c src/sys/arch/x86/include: bootinfo.h cpu.h src/sys/arch/x86/x86: x86_machdep.c src/sys/kern: init_main.c subr_userconf.c src/sys/sys: userconf.h Log Message: Support userconf(4) command in boot(8)/boot.cfg(5) on i386/amd64. >From jmmv@, no objections seen in the proposed thread: http://mail-index.netbsd.org/tech-kern/2009/01/22/msg004081.html To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/share/man/man5/boot.cfg.5 cvs rdiff -u -r1.56 -r1.57 src/share/man/man8/man8.i386/boot.8 cvs rdiff -u -r1.53 -r1.54 src/sys/arch/i386/stand/boot/boot2.c cvs rdiff -u -r1.8 -r1.9 src/sys/arch/i386/stand/lib/bootmenu.c cvs rdiff -u -r1.46 -r1.47 src/sys/arch/i386/stand/lib/exec.c cvs rdiff -u -r1.35 -r1.36 src/sys/arch/i386/stand/lib/libi386.h cvs rdiff -u -r1.28 -r1.29 src/sys/arch/i386/stand/pxeboot/main.c cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x86/include/bootinfo.h cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/include/cpu.h cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/x86/x86_machdep.c cvs rdiff -u -r1.429 -r1.430 src/sys/kern/init_main.c cvs rdiff -u -r1.22 -r1.23 src/sys/kern/subr_userconf.c cvs rdiff -u -r1.5 -r1.6 src/sys/sys/userconf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man5/boot.cfg.5 diff -u src/share/man/man5/boot.cfg.5:1.21 src/share/man/man5/boot.cfg.5:1.22 --- src/share/man/man5/boot.cfg.5:1.21 Thu Oct 28 14:29:18 2010 +++ src/share/man/man5/boot.cfg.5 Thu May 26 04:25:26 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: boot.cfg.5,v 1.21 2010/10/28 14:29:18 jruoho Exp $ +.\" $NetBSD: boot.cfg.5,v 1.22 2011/05/26 04:25:26 uebayasi Exp $ .\" .\" Copyright (c) 2007 Stephen Borrill .\" All rights reserved. @@ -25,7 +25,7 @@ .\" INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 28, 2010 +.Dd May 26, 2011 .Dt BOOT.CFG 5 .Os .Sh NAME @@ -143,6 +143,10 @@ immediately. If the timeout value is negative or is not a number, there will be no time limit for the user to choose an option. +.It Sy userconf +Passes a +.Xr userconf 4 +command to the kernel at boot time . .El .Sh EXAMPLES Here is an example @@ -165,6 +169,7 @@ clear=1 timeout=-1 default=1 +userconf disable ehci* # Always load ramdisk module load=/miniroot.kmod .Ed Index: src/share/man/man8/man8.i386/boot.8 diff -u src/share/man/man8/man8.i386/boot.8:1.56 src/share/man/man8/man8.i386/boot.8:1.57 --- src/share/man/man8/man8.i386/boot.8:1.56 Thu Jan 13 10:03:29 2011 +++ src/share/man/man8/man8.i386/boot.8 Thu May 26 04:25:26 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: boot.8,v 1.56 2011/01/13 10:03:29 jym Exp $ +.\" $NetBSD: boot.8,v 1.57 2011/05/26 04:25:26 uebayasi Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)boot_i386.8 8.2 (Berkeley) 4/19/94 .\" -.Dd November 7, 2010 +.Dd May 26, 2011 .Dt BOOT 8 i386 .Os .Sh NAME @@ -558,6 +558,15 @@ .El .It Ic quit Reboot the system. +.It Ic userconf Va command +Pass the +.Va command +to +.Xr userconf 4 +at boot time . +These commands are processed before the interactive +.Xr userconf 4 +shell is executed, if requested . .El .Pp In an emergency, the bootstrap methods described in the Index: src/sys/arch/i386/stand/boot/boot2.c diff -u src/sys/arch/i386/stand/boot/boot2.c:1.53 src/sys/arch/i386/stand/boot/boot2.c:1.54 --- src/sys/arch/i386/stand/boot/boot2.c:1.53 Fri Mar 18 18:24:09 2011 +++ src/sys/arch/i386/stand/boot/boot2.c Thu May 26 04:25:27 2011 @@ -1,7 +1,7 @@ -/* $NetBSD: boot2.c,v 1.53 2011/03/18 18:24:09 jakllsch Exp $ */ +/* $NetBSD: boot2.c,v 1.54 2011/05/26 04:25:27 uebayasi Exp $ */ /*- - * Copyright (c) 2008 The NetBSD Foundation, Inc. + * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -136,6 +136,7 @@ { "multiboot", command_multiboot }, { "vesa", command_vesa }, { "splash", splash_add }, + { "userconf", userconf_add }, { NULL, NULL }, }; @@ -395,6 +396,7 @@ "modules {on|off|enabled|disabled}\n" "load {path_to_module}\n" "multiboot [xdNx:][filename] [<args>]\n" + "userconf {command}\n" "help|?\n" "quit\n"); } Index: src/sys/arch/i386/stand/lib/bootmenu.c diff -u src/sys/arch/i386/stand/lib/bootmenu.c:1.8 src/sys/arch/i386/stand/lib/bootmenu.c:1.9 --- src/sys/arch/i386/stand/lib/bootmenu.c:1.8 Mon Sep 14 10:42:42 2009 +++ src/sys/arch/i386/stand/lib/bootmenu.c Thu May 26 04:25:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: bootmenu.c,v 1.8 2009/09/14 10:42:42 jmcneill Exp $ */ +/* $NetBSD: bootmenu.c,v 1.9 2011/05/26 04:25:27 uebayasi Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -232,6 +232,8 @@ } } else if (!strncmp(key, "clear", 5)) { bootconf.clear = !!atoi(value); + } else if (!strncmp(key, "userconf", 8)) { + userconf_add(value); } } switch (bootconf.menuformat) { Index: src/sys/arch/i386/stand/lib/exec.c diff -u src/sys/arch/i386/stand/lib/exec.c:1.46 src/sys/arch/i386/stand/lib/exec.c:1.47 --- src/sys/arch/i386/stand/lib/exec.c:1.46 Sun Feb 6 23:16:05 2011 +++ src/sys/arch/i386/stand/lib/exec.c Thu May 26 04:25:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.46 2011/02/06 23:16:05 jmcneill Exp $ */ +/* $NetBSD: exec.c,v 1.47 2011/05/26 04:25:27 uebayasi Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -126,6 +126,13 @@ bool boot_modules_enabled = true; bool kernel_loaded; +typedef struct userconf_command { + char *uc_text; + size_t uc_len; + struct userconf_command *uc_next; +} userconf_command_t; +userconf_command_t *userconf_commands = NULL; + static struct btinfo_framebuffer btinfo_framebuffer; static struct btinfo_modulelist *btinfo_modulelist; @@ -134,9 +141,14 @@ static char module_base[64] = "/"; static int howto; +static struct btinfo_userconfcommands *btinfo_userconfcommands = NULL; +static size_t btinfo_userconfcommands_size = 0; + static void module_init(const char *); static void module_add_common(char *, uint8_t); +static void userconf_init(void); + void framebuffer_configure(struct btinfo_framebuffer *fb) { @@ -191,6 +203,46 @@ } } +void +userconf_add(char *cmd) +{ + userconf_command_t *uc; + size_t len; + char *text; + + while (*cmd == ' ' || *cmd == '\t') + ++cmd; + + uc = alloc(sizeof(*uc)); + if (uc == NULL) { + printf("couldn't allocate command\n"); + return; + } + + len = strlen(cmd) + 1; + text = alloc(len); + if (text == NULL) { + dealloc(uc, sizeof(*uc)); + printf("couldn't allocate command\n"); + return; + } + memcpy(text, cmd, len); + + uc->uc_text = text; + uc->uc_len = len; + uc->uc_next = NULL; + + if (userconf_commands == NULL) + userconf_commands = uc; + else { + userconf_command_t *ucp; + for (ucp = userconf_commands; ucp->uc_next != NULL; + ucp = ucp->uc_next) + ; + ucp->uc_next = uc; + } +} + static int common_load_kernel(const char *file, u_long *basemem, u_long *extmem, physaddr_t loadaddr, int floppy, u_long marks[MARK_MAX]) @@ -319,6 +371,11 @@ } } + userconf_init(); + if (btinfo_userconfcommands != NULL) + BI_ADD(btinfo_userconfcommands, BTINFO_USERCONFCOMMANDS, + btinfo_userconfcommands_size); + #ifdef DEBUG printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY], marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]); @@ -543,6 +600,44 @@ } } +static void +userconf_init(void) +{ + size_t count, len; + userconf_command_t *uc; + char *buf; + off_t off; + + /* Calculate the userconf commands list size */ + count = 0; + for (uc = userconf_commands; uc != NULL; uc = uc->uc_next) + count++; + len = sizeof(btinfo_userconfcommands) + + count * sizeof(struct bi_userconfcommand); + + /* Allocate the userconf commands list */ + btinfo_userconfcommands = alloc(len); + if (btinfo_userconfcommands == NULL) { + printf("WARNING: couldn't allocate userconf commands list\n"); + return; + } + memset(btinfo_userconfcommands, 0, len); + btinfo_userconfcommands_size = len; + + /* Fill in btinfo structure */ + buf = (char *)btinfo_userconfcommands; + off = sizeof(*btinfo_userconfcommands); + btinfo_userconfcommands->num = 0; + for (uc = userconf_commands; uc != NULL; uc = uc->uc_next) { + struct bi_userconfcommand *bi; + bi = (struct bi_userconfcommand *)(buf + off); + strncpy(bi->text, uc->uc_text, sizeof(bi->text) - 1); + + off += sizeof(*bi); + btinfo_userconfcommands->num++; + } +} + int exec_multiboot(const char *file, char *args) { Index: src/sys/arch/i386/stand/lib/libi386.h diff -u src/sys/arch/i386/stand/lib/libi386.h:1.35 src/sys/arch/i386/stand/lib/libi386.h:1.36 --- src/sys/arch/i386/stand/lib/libi386.h:1.35 Mon Feb 21 00:39:54 2011 +++ src/sys/arch/i386/stand/lib/libi386.h Thu May 26 04:25:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: libi386.h,v 1.35 2011/02/21 00:39:54 dyoung Exp $ */ +/* $NetBSD: libi386.h,v 1.36 2011/05/26 04:25:27 uebayasi Exp $ */ /* * Copyright (c) 1996 @@ -138,6 +138,7 @@ void module_add(char *); void splash_add(char *); +void userconf_add(char *); struct btinfo_framebuffer; void framebuffer_configure(struct btinfo_framebuffer *); Index: src/sys/arch/i386/stand/pxeboot/main.c diff -u src/sys/arch/i386/stand/pxeboot/main.c:1.28 src/sys/arch/i386/stand/pxeboot/main.c:1.29 --- src/sys/arch/i386/stand/pxeboot/main.c:1.28 Fri Mar 18 18:21:38 2011 +++ src/sys/arch/i386/stand/pxeboot/main.c Thu May 26 04:25:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.28 2011/03/18 18:21:38 jakllsch Exp $ */ +/* $NetBSD: main.c,v 1.29 2011/05/26 04:25:27 uebayasi Exp $ */ /* * Copyright (c) 1996 @@ -76,6 +76,7 @@ { "multiboot", command_multiboot }, { "load", module_add }, { "vesa", command_vesa }, + { "userconf", userconf_add }, { NULL, NULL }, }; @@ -201,6 +202,7 @@ "multiboot [filename] [<args>]\n" "modules {on|off|enabled|disabled}\n" "load {path_to_module}\n" + "userconf {command}\n" "help|?\n" "quit\n"); } Index: src/sys/arch/x86/include/bootinfo.h diff -u src/sys/arch/x86/include/bootinfo.h:1.17 src/sys/arch/x86/include/bootinfo.h:1.18 --- src/sys/arch/x86/include/bootinfo.h:1.17 Sun Feb 6 23:14:04 2011 +++ src/sys/arch/x86/include/bootinfo.h Thu May 26 04:25:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: bootinfo.h,v 1.17 2011/02/06 23:14:04 jmcneill Exp $ */ +/* $NetBSD: bootinfo.h,v 1.18 2011/05/26 04:25:28 uebayasi Exp $ */ /* * Copyright (c) 1997 @@ -37,6 +37,7 @@ #define BTINFO_BOOTWEDGE 10 #define BTINFO_MODULELIST 11 #define BTINFO_FRAMEBUFFER 12 +#define BTINFO_USERCONFCOMMANDS 13 #ifndef _LOCORE @@ -200,6 +201,16 @@ uint8_t reserved[14]; }; +struct bi_userconfcommand { + char text[80]; +}; + +struct btinfo_userconfcommands { + struct btinfo_common common; + int num; + /* bi_userconfcommand list follows */ +}; + #endif /* _LOCORE */ #ifdef _KERNEL Index: src/sys/arch/x86/include/cpu.h diff -u src/sys/arch/x86/include/cpu.h:1.32 src/sys/arch/x86/include/cpu.h:1.33 --- src/sys/arch/x86/include/cpu.h:1.32 Wed Apr 13 06:29:30 2011 +++ src/sys/arch/x86/include/cpu.h Thu May 26 04:25:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.32 2011/04/13 06:29:30 mrg Exp $ */ +/* $NetBSD: cpu.h,v 1.33 2011/05/26 04:25:28 uebayasi Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -439,6 +439,8 @@ #include <machine/psl.h> /* Must be after struct cpu_info declaration */ +#define __HAVE_USERCONF_BOOTINFO + #endif /* _KERNEL || __KMEMUSER */ /* Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.46 src/sys/arch/x86/x86/x86_machdep.c:1.47 --- src/sys/arch/x86/x86/x86_machdep.c:1.46 Mon Mar 21 22:25:13 2011 +++ src/sys/arch/x86/x86/x86_machdep.c Thu May 26 04:25:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.46 2011/03/21 22:25:13 rmind Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.47 2011/05/26 04:25:28 uebayasi Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.46 2011/03/21 22:25:13 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.47 2011/05/26 04:25:28 uebayasi Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -50,6 +50,7 @@ #include <sys/module.h> #include <sys/sysctl.h> #include <sys/extent.h> +#include <sys/userconf.h> #include <x86/cpuvar.h> #include <x86/cputypes.h> @@ -178,6 +179,26 @@ #endif /* MODULAR */ void +userconf_bootinfo(void) +{ + struct btinfo_userconfcommands *biuc; + struct bi_userconfcommand *bi, *bimax; + + biuc = lookup_bootinfo(BTINFO_USERCONFCOMMANDS); + if (biuc == NULL) { + aprint_debug("No bootinfo commands at boot\n"); + return; + } + + bi = (struct bi_userconfcommand *)((uint8_t *)biuc + sizeof(*biuc)); + bimax = bi + biuc->num; + for (; bi < bimax; bi++) { + aprint_debug("Processing userconf command: %s\n", bi->text); + userconf_parse(bi->text); + } +} + +void cpu_need_resched(struct cpu_info *ci, int flags) { struct cpu_info *cur; Index: src/sys/kern/init_main.c diff -u src/sys/kern/init_main.c:1.429 src/sys/kern/init_main.c:1.430 --- src/sys/kern/init_main.c:1.429 Thu May 19 03:07:29 2011 +++ src/sys/kern/init_main.c Thu May 26 04:25:26 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.429 2011/05/19 03:07:29 rmind Exp $ */ +/* $NetBSD: init_main.c,v 1.430 2011/05/26 04:25:26 uebayasi Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.429 2011/05/19 03:07:29 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.430 2011/05/26 04:25:26 uebayasi Exp $"); #include "opt_ddb.h" #include "opt_ipsec.h" @@ -729,8 +729,9 @@ #endif #ifdef USERCONF + userconf_init(); if (boothowto & RB_USERCONF) - user_config(); + userconf_prompt(); #endif if ((boothowto & (AB_SILENT|AB_VERBOSE)) == AB_SILENT) { Index: src/sys/kern/subr_userconf.c diff -u src/sys/kern/subr_userconf.c:1.22 src/sys/kern/subr_userconf.c:1.23 --- src/sys/kern/subr_userconf.c:1.22 Tue May 24 16:41:23 2011 +++ src/sys/kern/subr_userconf.c Thu May 26 04:25:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_userconf.c,v 1.22 2011/05/24 16:41:23 joerg Exp $ */ +/* $NetBSD: subr_userconf.c,v 1.23 2011/05/26 04:25:27 uebayasi Exp $ */ /* * Copyright (c) 1996 Mats O Jansson <m...@stacken.kth.se> @@ -29,7 +29,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_userconf.c,v 1.22 2011/05/24 16:41:23 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_userconf.c,v 1.23 2011/05/26 04:25:27 uebayasi Exp $"); #include "opt_userconf.h" @@ -37,6 +37,7 @@ #include <sys/systm.h> #include <sys/device.h> #include <sys/time.h> +#include <sys/userconf.h> #include <dev/cons.h> @@ -81,7 +82,7 @@ "", "", }; -static void +void userconf_init(void) { int i; @@ -93,6 +94,10 @@ userconf_maxdev = i - 1; userconf_totdev = i - 1; + +#ifdef __HAVE_USERCONF_BOOTINFO + userconf_bootinfo(); +#endif } static int @@ -681,7 +686,7 @@ } #endif /* 0 */ -static int +int userconf_parse(char *cmd) { char *c, *v; @@ -797,14 +802,11 @@ return(0); } -extern void user_config(void); - void -user_config(void) +userconf_prompt(void) { const char prompt[] = "uc> "; - userconf_init(); printf("userconf: configure system autoconfiguration:\n"); while (1) { Index: src/sys/sys/userconf.h diff -u src/sys/sys/userconf.h:1.5 src/sys/sys/userconf.h:1.6 --- src/sys/sys/userconf.h:1.5 Mon Apr 28 20:24:11 2008 +++ src/sys/sys/userconf.h Thu May 26 04:25:27 2011 @@ -1,7 +1,7 @@ -/* $NetBSD: userconf.h,v 1.5 2008/04/28 20:24:11 martin Exp $ */ +/* $NetBSD: userconf.h,v 1.6 2011/05/26 04:25:27 uebayasi Exp $ */ /*- - * Copyright (c) 2001 The NetBSD Foundation, Inc. + * Copyright (c) 2001, 2009 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,6 +29,14 @@ #ifndef _SYS_USERCONF_H_ #define _SYS_USERCONF_H_ -void user_config(void); +#include <sys/cpu.h> + +void userconf_init(void); +void userconf_prompt(void); +int userconf_parse(char *); + +#ifdef __HAVE_USERCONF_BOOTINFO +void userconf_bootinfo(void); +#endif #endif /* !_SYS_USERCONF_H_ */