CC: Russell King , Paul Mackerras , Geert Uytterhoeven , Andi Kleen , davidm@hpl.hp.com, ralf@linux-mips.org, matthew@wil.cx, grundler@parisc-linux.org [ CC'ing of arch maintainers where I've made non-trivial changes ] Hello. The following is outcome of talking with David Woodhouse about the need in various parts of the kernel to parse the command line very early and set some options based on what we read. The result is __early_param("arg", fn) based very heavily on the macro of the same name in the arm kernel. The following is the core of these changes, adding the macro, struct and externs to , the parser to init/main.c and converting console= to this format. As a follow on to this thread are patches against all arches (vs 2.6.5-rc2) to use the global define of saved_command_line, add the appropriate bits to arch/$(ARCH)/kernel/vmlinux.lds.S and in some cases, convert params from the old arch-specific variant to the new __early_param way. --- 25-akpm/include/linux/init.h | 14 +++++++++++ 25-akpm/init/main.c | 53 ++++++++++++++++++++++++++++++++++++++++++- 25-akpm/kernel/printk.c | 2 - 3 files changed, 67 insertions(+), 2 deletions(-) diff -puN include/linux/init.h~early-param-core include/linux/init.h --- 25/include/linux/init.h~early-param-core Thu Mar 25 15:34:23 2004 +++ 25-akpm/include/linux/init.h Thu Mar 25 15:34:23 2004 @@ -66,6 +66,20 @@ typedef void (*exitcall_t)(void); extern initcall_t __con_initcall_start, __con_initcall_end; extern initcall_t __security_initcall_start, __security_initcall_end; + +/* + * Early command line parameters. + */ +struct early_params { + const char *arg; + int (*fn)(char *p); +}; +extern struct early_params __early_begin, __early_end; +extern void parse_early_options(char **cmdline_p); + +#define __early_param(name,fn) \ +static struct early_params __early_##fn __attribute_used__ \ +__attribute__((__section__("__early_param"))) = { name, fn } #endif #ifndef MODULE diff -puN init/main.c~early-param-core init/main.c --- 25/init/main.c~early-param-core Thu Mar 25 15:34:23 2004 +++ 25-akpm/init/main.c Thu Mar 25 15:34:23 2004 @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -111,6 +112,10 @@ extern void time_init(void); void (*late_time_init)(void); extern void softirq_init(void); +/* Stuff for the command line. */ +char saved_command_line[COMMAND_LINE_SIZE]; /* For /proc */ +static char tmp_command_line[COMMAND_LINE_SIZE]; /* Parsed. */ + static char *execute_command; /* Setup configured maximum number of CPUs to activate */ @@ -396,13 +401,59 @@ static void noinline rest_init(void) } /* + * Initial parsing of the command line. We destructivly + * scan the pointer, and take out any params for which we have + * an early handler for. + */ +void __init parse_early_options(char **cmdline_p) +{ + char *from = *cmdline_p; /* Original. */ + char c = ' ', *to = tmp_command_line; /* Parsed. */ + int len = 0; + + /* Save it, if we need to. */ + if (*cmdline_p != saved_command_line) + memcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE); + saved_command_line[COMMAND_LINE_SIZE - 1] = '\0'; + + for (;;) { + if (c == ' ') { + struct early_params *p; + + for (p = &__early_begin; p < &__early_end; p++) { + int len = strlen(p->arg); + + if (memcmp(from, p->arg, len) == 0) { + if (to != *cmdline_p) + to -= 1; + from += len; + p->fn(from); + + while (*from != ' ' && *from != '\0') + from++; + break; + } + } + } + c = *from++; + if (!c) + break; + if (COMMAND_LINE_SIZE <= ++len) + break; + *to++ = c; + } + + *to = '\0'; + *cmdline_p = tmp_command_line; +} + +/* * Activate the first processor. */ asmlinkage void __init start_kernel(void) { char * command_line; - extern char saved_command_line[]; extern struct kernel_param __start___param[], __stop___param[]; /* * Interrupts are still disabled. Do necessary setups, then diff -puN kernel/printk.c~early-param-core kernel/printk.c --- 25/kernel/printk.c~early-param-core Thu Mar 25 15:34:23 2004 +++ 25-akpm/kernel/printk.c Thu Mar 25 15:34:23 2004 @@ -149,7 +149,7 @@ static int __init console_setup(char *st return 1; } -__setup("console=", console_setup); +__early_param("console=", console_setup); /** * add_preferred_console - add a device to the list of preferred consoles. _