All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] early command-line parsing
@ 2002-11-20 18:40 Dave Hansen
  2002-11-20 21:00 ` David Woodhouse
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Hansen @ 2002-11-20 18:40 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: David Woodhouse

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]

We need a way to parse command-line options before setup_arch() for 
early printk.  On x86, the only thing that is needed to get an early 
serial console is:
console_setup("ttyS0,115200");
serial8250_console_init();

So, in addition to this patch, all you need to get early printk on x86 
is serial8250_console_init() in i386's setup_arch() and a 
console=ttyS0,speed on the kernel command line.

Are there any architectures that can't even do a memcpy before 
setup_arch()?
-- 
Dave Hansen
haveblue@us.ibm.com

[-- Attachment #2: early_setup-2.5.48-2.patch --]
[-- Type: text/plain, Size: 3117 bytes --]

diff -ru linux-2.5.48-clean/include/linux/init.h linux-2.5.48-early_setup/include/linux/init.h
--- linux-2.5.48-clean/include/linux/init.h	Tue Nov 19 13:53:09 2002
+++ linux-2.5.48-early_setup/include/linux/init.h	Tue Nov 19 12:02:45 2002
@@ -90,17 +90,21 @@
  * Used for kernel command line parameter setup
  */
 struct kernel_param {
+	int order;
 	const char *str;
 	int (*setup_func)(char *);
 };
 
 extern struct kernel_param __setup_start, __setup_end;
 
-#define __setup(str, fn)						\
+#define __early_setup(str, fn)	__raw_setup(0, str, fn)
+#define __setup(str, fn)	__raw_setup(1, str, fn)
+
+#define __raw_setup(order, str, fn)					\
 	static char __setup_str_##fn[] __initdata = str;		\
 	static struct kernel_param __setup_##fn				\
 		 __attribute__((unused,__section__ (".init.setup")))	\
-		= { __setup_str_##fn, fn }
+		= { order, __setup_str_##fn, fn }
 
 #endif /* __ASSEMBLY__ */
 
diff -ru linux-2.5.48-clean/init/main.c linux-2.5.48-early_setup/init/main.c
--- linux-2.5.48-clean/init/main.c	Tue Nov 19 13:53:09 2002
+++ linux-2.5.48-early_setup/init/main.c	Wed Nov 20 10:29:03 2002
@@ -36,6 +36,7 @@
 
 #include <asm/io.h>
 #include <asm/bugs.h>
+#include <asm/setup.h>
 
 #if defined(CONFIG_ARCH_S390)
 #include <asm/s390mach.h>
@@ -136,15 +137,17 @@
 
 __setup("profile=", profile_setup);
 
-static int __init checksetup(char *line)
+static int __init checksetup(int run_number, char *line) 
 {
 	struct kernel_param *p;
 
 	p = &__setup_start;
 	do {
 		int n = strlen(p->str);
-		if (!strncmp(line,p->str,n)) {
-			if (p->setup_func(line+n))
+		if(strncmp(linux, p->str, n)) {
+			if (p->order == run_number)
+				return (p->setup_func(line+n) != 0);
+			else if (p->order < run_number)
 				return 1;
 		}
 		p++;
@@ -230,7 +233,7 @@
  * This routine also checks for options meant for the kernel.
  * These options are not given to init - they are for internal kernel use only.
  */
-static void __init parse_options(char *line)
+static void __init parse_options(int setup_order, char *line)
 {
 	char *next,*quote;
 	int args, envs;
@@ -266,7 +269,7 @@
 			args = 0;
 			continue;
 		}
-		if (checksetup(line))
+		if (checksetup(setup_order, line))
 			continue;
 		
 		/*
@@ -386,6 +389,10 @@
  * Interrupts are still disabled. Do necessary setups, then
  * enable them
  */
+	memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
+	command_line = saved_command_line;
+
+	parse_options(0, command_line);
 	lock_kernel();
 	printk(linux_banner);
 	setup_arch(&command_line);
@@ -393,7 +400,7 @@
 	build_all_zonelists();
 	page_alloc_init();
 	printk("Kernel command line: %s\n", saved_command_line);
-	parse_options(command_line);
+	parse_options(1, command_line);
 	trap_init();
 	extable_init();
 	rcu_init();
diff -ru linux-2.5.48-clean/kernel/printk.c linux-2.5.48-early_setup/kernel/printk.c
--- linux-2.5.48-clean/kernel/printk.c	Sun Nov 10 19:28:32 2002
+++ linux-2.5.48-early_setup/kernel/printk.c	Wed Nov 20 10:30:05 2002
@@ -149,7 +149,7 @@
 	return 1;
 }
 
-__setup("console=", console_setup);
+__early_setup("console=", console_setup);
 
 /*
  * Commands to do_syslog:

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] early command-line parsing
  2002-11-20 18:40 [RFC][PATCH] early command-line parsing Dave Hansen
@ 2002-11-20 21:00 ` David Woodhouse
  2002-11-20 21:56   ` Dave Hansen
  0 siblings, 1 reply; 3+ messages in thread
From: David Woodhouse @ 2002-11-20 21:00 UTC (permalink / raw)
  To: Dave Hansen; +Cc: Linux Kernel Mailing List


Not all architectures have asm/setup.h. And not all have the command line 
somewhere convenient before setup_arch runs, although that could perhaps be 
changed.

I wonder if calling checksetup(0, ...) should be called from setup_arch as 
soon as the command line is available, rather than in start_kernel().

--
dwmw2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] early command-line parsing
  2002-11-20 21:00 ` David Woodhouse
@ 2002-11-20 21:56   ` Dave Hansen
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Hansen @ 2002-11-20 21:56 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Linux Kernel Mailing List

David Woodhouse wrote:
> Not all architectures have asm/setup.h. And not all have the command line 
> somewhere convenient before setup_arch runs, although that could perhaps be 
> changed.
> 
> I wonder if calling checksetup(0, ...) should be called from setup_arch as 
> soon as the command line is available, rather than in start_kernel().

11 of the 18 architectures that I looked at do some form of their own 
command-line parsing.  There is a lot of arch code that could be saved 
if they could use the __setup mechanisms for this.
	
As far as the architectures that don't have the command-line 
available, we could do something like this:
void start_kernel(void)
{
         char * command_line;
         extern char saved_command_line[];

	get_command_line_arch(&saved_command_line);
	strcpy(command_line, saved_command_line);
	checksetup(0, ...)
	...
}

The weird ones like sparc could do their prom_getcmdline() in 
get_command_line_arch();

Use of command line in setup_arch:
---------------------------------
alpha	does parsing in setup_arch
  	modifies read command line, in case of INSTALL

arm	has its own command-line parsing function

cris	doesn't use a command line

i386	has its own parse_cmdline_early
	can use command line before setup_arch

ia64	the only thing that happens before the strcopy is unw_init

m68k	does its own parsing
	can modify the cmd line in m68k_parse_bootinfo(), which is
  	  early in setup_arch()

mips	many per-arch setups first
	next after those is cmdline copy

ppc+64	does a bit of its own parsing for the debuggers

s390+x	does its own parsing for mem=, and others

sh	has own early printk
	does its own parsing

sparc	get cmdline from prom call
and 64	does own parsing in boot_flags_init()
	
um	cmdline copy happens after paging_init() in setup_arch

v850	does cmdline copy, first thing

x86_64	does its own parsing for early_printk, and in
	  parse_cmdline_early
-- 
Dave Hansen
haveblue@us.ibm.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-11-20 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-20 18:40 [RFC][PATCH] early command-line parsing Dave Hansen
2002-11-20 21:00 ` David Woodhouse
2002-11-20 21:56   ` Dave Hansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.