[RFC PATCH] param: start_kernel_with_args()

Rusty Russell
2008-12-25T12:20:59Z

This is a cute corollary of the cleanup patches. IA64 could particularly
benefit I think.

Impact: cleanup, new API

This gives a nicer entry point for archs to start_kernel; they don't
have to use boot_command_line (though they can if they want).

A nice side effect is that archs which use this entry point don't have
a COMMAND_LINE_SIZE limit any more (and if you don't define it,
boot_command_line does not exist).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff --git a/include/linux/start_kernel.h b/include/linux/start_kernel.h
--- a/include/linux/start_kernel.h
+++ b/include/linux/start_kernel.h
@@ -7,6 +7,13 @@
/* Define the prototype for start_kernel here, rather than cluttering
up something else. */

+/*
+ * Command-line pointer must be writable, must be NUL-terminated, but
+ * has no length limit and may be __initdata.
+ */
+extern asmlinkage void __init start_kernel_with_args(char *cmdline);
+
+/* Old entry point: calls arch_get_boot_command_line(). */
extern asmlinkage void __init start_kernel(void);

#endif /* _LINUX_START_KERNEL_H */
diff --git a/init/main.c b/init/main.c
--- a/init/main.c
+++ b/init/main.c
@@ -119,8 +119,11 @@ void (*late_time_init)(void);
void (*late_time_init)(void);
extern void softirq_init(void);

+#ifdef COMMAND_LINE_SIZE
/* Untouched command line saved by arch-specific code. */
char __initdata boot_command_line[COMMAND_LINE_SIZE];
+#endif
+
/* Untouched saved command line (eg. for /proc) */
char *saved_command_line;

@@ -522,15 +525,22 @@ void __init __weak thread_info_cache_ini
{
}

+#ifdef COMMAND_LINE_SIZE
asmlinkage void __init start_kernel(void)
+{
+ arch_get_boot_command_line();
+ start_kernel_with_args(boot_command_line);
+}
+#endif
+
+asmlinkage void __init start_kernel_with_args(char *cmdline)
{
char *static_command_line;

printk(KERN_NOTICE);
printk(linux_banner);

- arch_get_boot_command_line();
- parse_args("Core and early params", boot_command_line,
+ parse_args("Core and early params", cmdline,
__start___core_param,
__stop___core_param - __start___core_param,
do_early_param, true);
@@ -579,10 +589,10 @@ asmlinkage void __init start_kernel(void
preempt_disable();
build_all_zonelists();
page_alloc_init();
- printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
+ printk(KERN_NOTICE "Kernel command line: %s\n", cmdline);
/* param parsing can keep pointers to the commandline. */
- static_command_line = alloc_bootmem(strlen(boot_command_line)+1);
- strcpy(static_command_line, boot_command_line);
+ static_command_line = alloc_bootmem(strlen(cmdline)+1);
+ strcpy(static_command_line, cmdline);
parse_args("Booting kernel", static_command_line, __start___param,
__stop___param - __start___param,
&unknown_bootoption, false);
@@ -684,7 +694,7 @@ asmlinkage void __init start_kernel(void

ftrace_init();

- saved_command_line = kstrdup(boot_command_line, GFP_KERNEL);
+ saved_command_line = kstrdup(cmdline, GFP_KERNEL);

/* Do the rest non-__init'ed, we're now alive */
rest_init();