Re: [PATCH V2] x86: Allow built-in command line to work in early kernel init

From: Yinghai Lu
Date: Tue May 12 2015 - 19:41:30 EST


On Tue, May 12, 2015 at 11:42 AM, Matthew Garrett
<matthew.garrett@xxxxxxxxxx> wrote:
> Ok, maybe something more like this? It even gets rid of some of the
> #ifdefs in setup.c.
>
> diff --git a/arch/x86/boot/cmdline.c b/arch/x86/boot/cmdline.c
> index 625d21b..9ddffd0 100644
> --- a/arch/x86/boot/cmdline.c
> +++ b/arch/x86/boot/cmdline.c
> @@ -12,8 +12,15 @@
> * Simple command-line parser for early boot.
> */
>
> +#include <asm/cmdline_append.h>
> #include "boot.h"
>
> +#ifdef CONFIG_CMDLINE_BOOL
> +static char builtin_cmdline[] = CONFIG_CMDLINE;
> +#else
> +static char *builtin_cmdline;
> +#endif
> +
> static inline int myisspace(u8 c)
> {
> return c <= ' '; /* Close enough approximation */
> @@ -156,3 +163,38 @@ int __cmdline_find_option_bool(unsigned long
> cmdline_ptr, const char *option)
>
> return 0; /* Buffer overrun */
> }
> +
> +int __cmdline_init(unsigned long cmdline_ptr, struct boot_params *params)
> +{
> + addr_t cptr;
> + int i = 0;
> +
> + if (!builtin_cmdline)
> + return 0;
> +
> + if (!cmdline_ptr)
> + return -1; /* No command line */
> +
> + set_fs(cmdline_ptr >> 4);
> + cptr = cmdline_ptr & 0xf;
> +
> + if (append_cmdline) {
> + while (cptr < 0x10000) {
> + char c = rdfs8(cptr);
> + if (!c) {
> + wrfs8(' ', cptr++);
> + break;
> + }
> + cptr++;
> + }
> + }
> +
> + while (builtin_cmdline[i] && cptr < 0xffff)
> + wrfs8(builtin_cmdline[i++], cptr++);
> +
> + wrfs8('\0', cptr);
> +
> + params->setup_flags |= SETUP_CMDLINE_APPENDED;
> +
> + return 0;
> +}

You can not assume that you can use buffer after cmd_line from bootloader
blindly.

Thanks

Yinghai
--
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/