[patch 1/22] Add __early_param for all arches

trini_at_kernel.crashing.org
Date: 03/25/04

  • Next message: Pavel Machek: "swsusp with highmem, testing wanted"
    To: linux-kernel@vger.kernel.org
    Date:	Wed, 24 Mar 2004 18:57:22 -0500
    
    

    CC: Russell King <rmk@arm.linux.org.uk>, Paul Mackerras <paulus@samba.org>, Geert Uytterhoeven <geert@linux-m68k.org>, Andi Kleen <ak@suse.de>, 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 <linux/init.h>, 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.

    ---
     linux-2.6-early_setup-trini/include/linux/init.h |   14 ++++++
     linux-2.6-early_setup-trini/init/main.c          |   53 ++++++++++++++++++++++-
     linux-2.6-early_setup-trini/kernel/printk.c      |    2 
     3 files changed, 67 insertions(+), 2 deletions(-)
    diff -puN include/linux/init.h~core include/linux/init.h
    --- linux-2.6-early_setup/include/linux/init.h~core	2004-03-24 16:15:04.645141825 -0700
    +++ linux-2.6-early_setup-trini/include/linux/init.h	2004-03-24 16:15:04.651140474 -0700
    @@ -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~core init/main.c
    --- linux-2.6-early_setup/init/main.c~core	2004-03-24 16:15:04.647141375 -0700
    +++ linux-2.6-early_setup-trini/init/main.c	2004-03-24 16:15:04.652140249 -0700
    @@ -43,6 +43,7 @@
     #include <linux/efi.h>
     #include <linux/unistd.h>
     
    +#include <asm/setup.h>
     #include <asm/io.h>
     #include <asm/bugs.h>
     
    @@ -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~core kernel/printk.c
    --- linux-2.6-early_setup/kernel/printk.c~core	2004-03-24 16:15:04.649140924 -0700
    +++ linux-2.6-early_setup-trini/kernel/printk.c	2004-03-24 16:15:04.653140024 -0700
    @@ -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.
    _
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Pavel Machek: "swsusp with highmem, testing wanted"

    Relevant Pages

    • [PATCH] kbuild: fix modpost when used with O=
      ... Return a pointer to a static buffer. ... +get_next_line(unsigned long *pos, void *file, unsigned long size) ... diff -Nru a/scripts/sumversion.c b/scripts/sumversion.c ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [PATCH] vmalloc might sleep
      ... diff -u -p -r1.2 vmalloc.c ... void *vmalloc_32 ... War is real, war is primarily not about defeat or ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [PATCH 2.6.14-rc2] fix incorrect mm->hiwater_vm and mm->hiwater_rss
      ... diff -ru a/kernel/exit.c b/kernel/exit.c ... -void update_mem_hiwater(struct task_struct *tsk) ... +void update_mem_hiwater ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • kbuild: Fix warnings in binoffset.c
      ... # This is a BitKeeper generated diff -Nru style patch. ... # fix warnings in scripts/binoffset.c ... +void search_pattern ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [PATCH] kern.ident + uname -i
      ... I send you this diff in order that I may gather some concensus on ... objections I'll probably commit it, since it's not a major thing, ... retrieving revision 1.51 ... typedef void; ...
      (freebsd-hackers)