[PATCH v3] LoongArch: Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER

Dong Zhihong posted 1 patch 2 years, 7 months ago
arch/loongarch/kernel/setup.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
[PATCH v3] LoongArch: Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER
Posted by Dong Zhihong 2 years, 7 months ago
Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and
CONFIG_CMDLINE_BOOTLOADER. The touched function is bootcmdline_init()`.
There's already code handling CONFIG_CMDLINE_FORCE, which replaces
`boot_command_line` with CONFIG_CMDLINE and immediately`goto out`. It'd be
similar way to handle CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER,
so some code is added after OF_FLATTREE part to handle them.

Signed-off-by: Dong Zhihong <donmor3000@hotmail.com>
---

v3 -> v2: Reworded the commit message again to make it imperative (Ruoyao)
v2 -> v1: Reworded the commit message so it's more imperative (Markus);
	Added `goto out` to FDT part (Huacai)

 arch/loongarch/kernel/setup.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index 78a00359bde3..3cafda1a409e 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -332,7 +332,24 @@ static void __init bootcmdline_init(char **cmdline_p)
 			strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
 
 		strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
+		goto out;
+	}
+#endif
+
+#ifdef CONFIG_CMDLINE
+	/*
+	 * If CONFIG_CMDLINE_BOOTLOADER is enabled then we use thei built-in
+	 * command line if no command line given, or we append given command
+	 * line to the built-in one if CONFIG_CMDLINE_EXTEND is enabled.
+	 */
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
+		strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+		strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
+		strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
 	}
+
+	if (IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && !boot_command_line[0])
+		strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 
 out:
-- 
2.25.1
Re: [PATCH v3] LoongArch: Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER
Posted by Huacai Chen 2 years, 7 months ago
On Tue, Jul 11, 2023 at 9:47 PM Dong Zhihong <donmor3000@hotmail.com> wrote:
>
> Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and
> CONFIG_CMDLINE_BOOTLOADER. The touched function is bootcmdline_init()`.
> There's already code handling CONFIG_CMDLINE_FORCE, which replaces
> `boot_command_line` with CONFIG_CMDLINE and immediately`goto out`. It'd be
> similar way to handle CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER,
> so some code is added after OF_FLATTREE part to handle them.
>
> Signed-off-by: Dong Zhihong <donmor3000@hotmail.com>
> ---
>
> v3 -> v2: Reworded the commit message again to make it imperative (Ruoyao)
> v2 -> v1: Reworded the commit message so it's more imperative (Markus);
>         Added `goto out` to FDT part (Huacai)
>
>  arch/loongarch/kernel/setup.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
> index 78a00359bde3..3cafda1a409e 100644
> --- a/arch/loongarch/kernel/setup.c
> +++ b/arch/loongarch/kernel/setup.c
> @@ -332,7 +332,24 @@ static void __init bootcmdline_init(char **cmdline_p)
>                         strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
>
>                 strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
> +               goto out;
> +       }
> +#endif
> +
> +#ifdef CONFIG_CMDLINE
> +       /*
> +        * If CONFIG_CMDLINE_BOOTLOADER is enabled then we use thei built-in
> +        * command line if no command line given, or we append given command
> +        * line to the built-in one if CONFIG_CMDLINE_EXTEND is enabled.
> +        */
> +       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
> +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> +               strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
> +               strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
You can simply the logic:
               strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
               strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
And then modify the comments because you are appending built-in parts
to bootloader parts.

>         }
> +
> +       if (IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && !boot_command_line[0])
> +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
This should be removed if you want to keep the exact meaning of
CONFIG_CMDLINE_BOOTLOADER.

Huacai

>  #endif
>
>  out:
> --
> 2.25.1
>
Re: [PATCH v3] LoongArch: Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER
Posted by ‎ donmor 2 years, 7 months ago
在 2023-07-11星期二的 22:26 +0800,Huacai Chen写道:

...
> +       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
> > +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> > +               strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
> > +               strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
> You can simply the logic:
>                strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
>                strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> And then modify the comments because you are appending built-in parts
> to bootloader parts.
> 
I think the command line retrieved from bootloader should be placed after the
built-in one so that it can override params in the latter.

> >         }
> > +
> > +       if (IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && !boot_command_line[0])
> > +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> This should be removed if you want to keep the exact meaning of
> CONFIG_CMDLINE_BOOTLOADER.
> 
> Huacai
> 
Do you mean 'IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && ' is not necessary? And I
think the rest of this part should be here, because CONFIG_CMDLINE_BOOTLOADER
won't append anything to boot_command_line unless it is empty, according to its
description.
Re: [PATCH v3] LoongArch: Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER
Posted by Huacai Chen 2 years, 7 months ago
On Tue, Jul 11, 2023 at 11:27 PM ‎ donmor <donmor3000@hotmail.com> wrote:
>
> 在 2023-07-11星期二的 22:26 +0800,Huacai Chen写道:
>
> ...
> > +       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
> > > +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> > > +               strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
> > > +               strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
> > You can simply the logic:
> >                strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
> >                strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> > And then modify the comments because you are appending built-in parts
> > to bootloader parts.
> >
> I think the command line retrieved from bootloader should be placed after the
> built-in one so that it can override params in the latter.
config CMDLINE_EXTEND
        bool "Use built-in to extend bootloader kernel arguments"

The fdt version also uses this logic, but you are using bootloader
parts to extend built-in parts.

>
> > >         }
> > > +
> > > +       if (IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && !boot_command_line[0])
> > > +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> > This should be removed if you want to keep the exact meaning of
> > CONFIG_CMDLINE_BOOTLOADER.
> >
> > Huacai
> >
> Do you mean 'IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && ' is not necessary? And I
> think the rest of this part should be here, because CONFIG_CMDLINE_BOOTLOADER
> won't append anything to boot_command_line unless it is empty, according to its
> description.

OK, you are right here.

Huacai
Re: [PATCH v3] LoongArch: Make CONFIG_CMDLINE work with CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER
Posted by ‎ donmor 2 years, 6 months ago
在 2023-07-12星期三的 09:19 +0800,Huacai Chen写道:
> On Tue, Jul 11, 2023 at 11:27 PM ‎ donmor <donmor3000@hotmail.com> wrote:
> > 在 2023-07-11星期二的 22:26 +0800,Huacai Chen写道:
> > 
> > ...
> > > +       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) {
> > > > +               strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> > > > +               strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
> > > > +               strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
> > > You can simply the logic:
> > >                strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
> > >                strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> > > And then modify the comments because you are appending built-in parts
> > > to bootloader parts.
> > > 
> > I think the command line retrieved from bootloader should be placed after the
> > built-in one so that it can override params in the latter.
> config CMDLINE_EXTEND
>         bool "Use built-in to extend bootloader kernel arguments"
> 
> The fdt version also uses this logic, but you are using bootloader
> parts to extend built-in parts.
> 
I see. So if there's a mistake in built-in, the kernel won't boot even if passed
the correct one... I'll correct it, anyway.