Re: [RFC 5/8] param: arch_get_boot_command_line()

From: Russell King
Date: Mon Dec 01 2008 - 08:18:57 EST


On Mon, Dec 01, 2008 at 11:26:01PM +1030, Rusty Russell wrote:
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -414,9 +414,11 @@ __early_param("mem=", early_mem);
>
> /*
> * Initial parsing of the command line.
> + * FIXME: Use generic early_param / core_param code here.
> */
> -static void __init parse_cmdline(char **cmdline_p, char *from)
> +static void __init parse_cmdline(void)
> {
> + const char *from = boot_command_line;
> char c = ' ', *to = command_line;
> int len = 0;
>
> @@ -448,7 +450,6 @@ static void __init parse_cmdline(char **
> *to++ = c;
> }
> *to = '\0';
> - *cmdline_p = command_line;
> }
>
> static void __init
> @@ -673,11 +674,24 @@ static int __init customize_machine(void
> }
> arch_initcall(customize_machine);
>
> -void __init setup_arch(char **cmdline_p)
> +void arch_get_boot_command_line(void)
> +{
> + struct machine_desc *mdesc;
> + const char *from;
> +
> + mdesc = setup_machine(machine_arch_type);
> + if (mdesc->cmdline)
> + from = mdesc->cmdline();
> + else
> + from = default_command_line;
> +
> + strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);

This is only half the story I'm afraid. It doesn't take account of the
fact that the command line can be passed from the boot loader via the
ATAG structures, which are only parsed after the machine specific
fixup has happened (which can also modify the ATAGs).

You're also not guaranteed to have an ATAG list before setup_arch() is
called - it might be a param_struct, and we convert that to an ATAG list
before ATAG parsing.

So there's quite a bit which needs to be done to get at the command line.
Basically, what's required is:

- convert param struct to tag list
- if no tag list, use default tag list
- run machine specific fixups which may set memory layout
- if memory layout has been set, kill off any memory atags to prevent it
being overwritten
- parse all atags which includes setting the command line if such a tag
is found

Then, and only then can you be sure that you have the right command line.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/