From: trini@kernel.crashing.org
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org
Subject: [patch 1/22] Add __early_param for all arches
Date: Wed, 24 Mar 2004 18:57:22 -0500 [thread overview]
Message-ID: <20040324235722.QDLK23486.fed1mtao04.cox.net@localhost.localdomain> (raw)
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.
_
next reply other threads:[~2004-03-24 23:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-24 23:57 trini [this message]
2004-03-25 3:55 ` Andrew Morton
2004-03-26 11:29 ` David Woodhouse
2004-03-26 21:03 ` Russell King
2004-03-26 21:15 ` David Woodhouse
2004-03-31 4:23 ` Rusty Russell
2004-03-31 16:13 ` Tom Rini
2004-04-01 1:51 ` Rusty Russell
2004-04-01 2:24 ` Tom Rini
2004-04-01 2:56 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040324235722.QDLK23486.fed1mtao04.cox.net@localhost.localdomain \
--to=trini@kernel.crashing.org \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®