Example /etc/userconf file: disable usb Example boot.cfg entry: menu=Disable usb and boot:userconf /etc/userconf;boot Index: sys/kern/subr_userconf.c =================================================================== RCS file: /cvsroot/src/sys/kern/subr_userconf.c,v retrieving revision 1.18 diff -u -r1.18 subr_userconf.c --- sys/kern/subr_userconf.c 11 Dec 2005 12:24:30 -0000 1.18 +++ sys/kern/subr_userconf.c 23 Oct 2008 20:15:49 -0000 @@ -45,6 +45,8 @@ #include #include +#include + #include extern struct cfdata cfdata[]; @@ -810,16 +812,47 @@ user_config(void) { char prompt[] = "uc> "; - +#ifdef BI_MODULE_USERCONF + int num; + struct btinfo_modulelist *bim; + struct bi_modulelist_entry *bme; + char *com, *buf, *end; +#endif + userconf_init(); printf("userconf: configure system autoconfiguration:\n"); - - while (1) { - printf(prompt); - if (getsn(userconf_cmdbuf, sizeof(userconf_cmdbuf)) > 0 && - userconf_parse(userconf_cmdbuf)) - break; +#ifdef BI_MODULE_USERCONF + if ((bim = lookup_bootinfo(BTINFO_MODULELIST)) != NULL) { + num = 0; + bme = (struct bi_modulelist_entry *)((uint8_t *)bim + + sizeof(struct btinfo_modulelist)); + for (; num < bim->num; num++, bme++) { + if (bme->type != BI_MODULE_USERCONF) + continue; + buf = (char *)(bme->base + KERNBASE); + end = buf + bme->len; + for (; buf < end; ) { + com = buf; + for (; buf < end && *buf != '\n'; buf++) + ; + if (*buf == '\n') { + *buf++ = '\0'; + printf("%s%s\n", prompt, com); + userconf_parse(com); + } + } + } + } else { +#endif /* BI_MODULE_USERCONF */ + while (1) { + printf(prompt); + if (getsn(userconf_cmdbuf, sizeof(userconf_cmdbuf)) > 0 && + userconf_parse(userconf_cmdbuf)) + break; + } +#ifdef BI_MODULE_USERCONF } +#endif /* BI_MODULE_USERCONF */ printf("Continuing...\n"); } Index: sys/arch/x86/include/bootinfo.h =================================================================== RCS file: /cvsroot/src/sys/arch/x86/include/bootinfo.h,v retrieving revision 1.14 diff -u -r1.14 bootinfo.h --- sys/arch/x86/include/bootinfo.h 9 Sep 2008 12:09:31 -0000 1.14 +++ sys/arch/x86/include/bootinfo.h 23 Oct 2008 20:15:49 -0000 @@ -172,6 +172,7 @@ }; #define BI_MODULE_NONE 0x00 #define BI_MODULE_ELF 0x01 +#define BI_MODULE_USERCONF 0x02 struct btinfo_modulelist { struct btinfo_common common; Index: sys/arch/i386/stand/boot/boot2.c =================================================================== RCS file: /cvsroot/src/sys/arch/i386/stand/boot/boot2.c,v retrieving revision 1.38 diff -u -r1.38 boot2.c --- sys/arch/i386/stand/boot/boot2.c 11 Oct 2008 11:06:19 -0000 1.38 +++ sys/arch/i386/stand/boot/boot2.c 23 Oct 2008 20:15:50 -0000 @@ -78,6 +78,7 @@ #include #include "devopen.h" #include "bootmod.h" +#include "bootinfo.h" #ifdef SUPPORT_PS2 #include @@ -118,7 +119,7 @@ void bootit(const char *, int, int); void print_banner(void); void boot2(int, u_int); - +void blob_load(char *, int); #ifndef SMALL void parsebootconf(const char *); void doboottypemenu(void); @@ -134,6 +135,7 @@ void command_modules(char *); void command_load(char *); void command_multiboot(char *); +void command_userconf(char *); const struct bootblk_command commands[] = { { "help", command_help }, @@ -146,6 +148,7 @@ { "modules", command_modules }, { "load", command_load }, { "multiboot", command_multiboot }, + { "userconf", command_userconf }, { NULL, NULL }, }; @@ -688,6 +691,7 @@ "modules {enabled|disabled}\n" "load {path_to_module}\n" "multiboot [xdNx:][filename] []\n" + "userconf {path_to_script}\n" "help|?\n" "quit\n"); } @@ -799,6 +803,18 @@ void command_load(char *arg) { + blob_load(arg, BI_MODULE_ELF); +} + +void +command_userconf(char *arg) +{ + blob_load(arg, BI_MODULE_USERCONF); +} + +void +blob_load(char *arg, int type) +{ boot_module_t *bm, *bmp; size_t len; char *str; @@ -816,6 +832,7 @@ memcpy(str, arg, len); bm->bm_path = str; bm->bm_next = NULL; + bm->bm_type = type; if (boot_modules == NULL) boot_modules = bm; else { Index: sys/arch/i386/stand/lib/bootmod.h =================================================================== RCS file: /cvsroot/src/sys/arch/i386/stand/lib/bootmod.h,v retrieving revision 1.3 diff -u -r1.3 bootmod.h --- sys/arch/i386/stand/lib/bootmod.h 5 May 2008 00:12:49 -0000 1.3 +++ sys/arch/i386/stand/lib/bootmod.h 23 Oct 2008 20:15:50 -0000 @@ -32,6 +32,7 @@ typedef struct boot_module { char *bm_path; ssize_t bm_len; + int bm_type; struct boot_module *bm_next; } boot_module_t; Index: sys/arch/i386/stand/lib/exec.c =================================================================== RCS file: /cvsroot/src/sys/arch/i386/stand/lib/exec.c,v retrieving revision 1.33 diff -u -r1.33 exec.c --- sys/arch/i386/stand/lib/exec.c 11 Oct 2008 11:06:20 -0000 1.33 +++ sys/arch/i386/stand/lib/exec.c 23 Oct 2008 20:15:51 -0000 @@ -133,7 +133,7 @@ static uint32_t image_end; static char module_base[64] = "/"; -static void module_init(void); +static void module_init(int *); static int common_load_kernel(const char *file, u_long *basemem, u_long *extmem, @@ -239,7 +239,6 @@ if (common_load_kernel(file, &basemem, &extmem, loadaddr, floppy, marks)) goto out; - boot_argv[0] = boothowto; boot_argv[1] = 0; boot_argv[2] = vtophys(bootinfo); /* old cyl offset */ boot_argv[3] = marks[MARK_END]; @@ -248,12 +247,13 @@ /* pull in any modules if necessary */ if (boot_modules_enabled) { - module_init(); + module_init(&boothowto); if (btinfo_modulelist) { BI_ADD(btinfo_modulelist, BTINFO_MODULELIST, btinfo_modulelist_size); } } + boot_argv[0] = boothowto; #ifdef DEBUG printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY], @@ -321,7 +321,7 @@ } static void -module_init(void) +module_init(int *boothowto) { struct bi_modulelist_entry *bi; struct stat st; @@ -412,7 +412,20 @@ strncpy(bi->path, bm->bm_path, sizeof(bi->path) - 1); bi->base = image_end; bi->len = len; - bi->type = BI_MODULE_ELF; + bi->type = bm->bm_type; + switch(bi->type) { + case BI_MODULE_ELF: + printf(" (ELF module)"); + break; + case BI_MODULE_USERCONF: + if (boothowto != NULL) + *boothowto |= RB_USERCONF; + printf(" (userconf script)"); + break; + default: + printf(" (unknown type)"); + break; + } printf(" \n"); } if (len > 0) @@ -453,7 +466,7 @@ /* pull in any modules if necessary */ if (boot_modules_enabled) { - module_init(); + module_init(NULL); if (btinfo_modulelist) { mbm = alloc(sizeof(struct multiboot_module) * btinfo_modulelist->num);