2018-12-18 03:16:18

by Paul Walmsley

[permalink] [raw]
Subject: [PATCH] arch: riscv: support kernel command line forcing when no DTB passed


CONFIG_CMDLINE_FORCE doesn't work on RISC-V when no DTB is passed into
the kernel. This is because the code that forces the kernel command
line only runs if a valid DTB is present at boot. During debugging,
it's useful to have the ability to force kernel command lines even
when no DTB is present. This patch adds support for doing so.

Cc: Palmer Dabbelt <[email protected]>
Cc: Albert Ou <[email protected]>
Cc: [email protected]
Cc: [email protected] (open list)
Signed-off-by: Paul Walmsley <[email protected]>
Signed-off-by: Paul Walmsley <[email protected]>
---

Applies on v4.20-rc7.

arch/riscv/kernel/setup.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 2c290e6aaa6e..e6b962ff39b1 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -171,7 +171,14 @@ asmlinkage void __init setup_vm(void)

void __init parse_dtb(unsigned int hartid, void *dtb)
{
- early_init_dt_scan(__va(dtb));
+ if (!early_init_dt_scan(__va(dtb)))
+ return;
+
+ pr_err("No DTB passed to the kernel\n");
+#ifdef CONFIG_CMDLINE_FORCE
+ strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+ pr_info("Forcing kernel command line to: %s\n", boot_command_line);
+#endif
}

static void __init setup_bootmem(void)
--
2.20.0



2019-01-15 16:46:52

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] arch: riscv: support kernel command line forcing when no DTB passed

On Mon, Dec 17, 2018 at 07:15:12PM -0800, Paul Walmsley wrote:
>
> CONFIG_CMDLINE_FORCE doesn't work on RISC-V when no DTB is passed into
> the kernel. This is because the code that forces the kernel command
> line only runs if a valid DTB is present at boot. During debugging,
> it's useful to have the ability to force kernel command lines even
> when no DTB is present. This patch adds support for doing so.

This looks fine to me:

Reviewed-by: Christoph Hellwig <[email protected]>

I just wish all this command line magic could be moved to common
code somewhere instead of being reinvented badly in every port..

2019-02-05 18:00:26

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] arch: riscv: support kernel command line forcing when no DTB passed

On Dez 17 2018, Paul Walmsley <[email protected]> wrote:

> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 2c290e6aaa6e..e6b962ff39b1 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -171,7 +171,14 @@ asmlinkage void __init setup_vm(void)
>
> void __init parse_dtb(unsigned int hartid, void *dtb)
> {
> - early_init_dt_scan(__va(dtb));
> + if (!early_init_dt_scan(__va(dtb)))
> + return;
> +
> + pr_err("No DTB passed to the kernel\n");

Isn't that backwards? early_init_dt_scan returns true if it found a
DTB.

Andreas.

--
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

2019-02-07 14:45:14

by Andreas Schwab

[permalink] [raw]
Subject: [PATCH] arch: riscv: fix logic error in parse_dtb

The function early_init_dt_scan returns true if a DTB was detected.

Fixes: 8fd6e05c7463 ("arch: riscv: support kernel command line forcing when no DTB passed")
Signed-off-by: Andreas Schwab <[email protected]>
---
arch/riscv/kernel/setup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 45e9a2f053dc..84f19ca6d88b 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -140,7 +140,7 @@ asmlinkage void __init setup_vm(void)

void __init parse_dtb(unsigned int hartid, void *dtb)
{
- if (!early_init_dt_scan(__va(dtb)))
+ if (early_init_dt_scan(__va(dtb)))
return;

pr_err("No DTB passed to the kernel\n");
--
2.20.1

--
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

2019-02-07 22:49:48

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH] arch: riscv: fix logic error in parse_dtb

On 2/7/19 6:44 AM, Andreas Schwab wrote:
> The function early_init_dt_scan returns true if a DTB was detected.
>
> Fixes: 8fd6e05c7463 ("arch: riscv: support kernel command line forcing when no DTB passed")
> Signed-off-by: Andreas Schwab <[email protected]>
> ---
> arch/riscv/kernel/setup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 45e9a2f053dc..84f19ca6d88b 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -140,7 +140,7 @@ asmlinkage void __init setup_vm(void)
>
> void __init parse_dtb(unsigned int hartid, void *dtb)
> {
> - if (!early_init_dt_scan(__va(dtb)))
> + if (early_init_dt_scan(__va(dtb)))
> return;
>
> pr_err("No DTB passed to the kernel\n");
>

Good catch. I was surprised to see "No DTB passed.." message with rc5.

Reviewed-by: Atish Patra <[email protected]>

Regards,
Atish

2019-02-19 21:21:38

by Paul Walmsley

[permalink] [raw]
Subject: Re: [PATCH] arch: riscv: support kernel command line forcing when no DTB passed



On Tue, 5 Feb 2019, Andreas Schwab wrote:

> On Dez 17 2018, Paul Walmsley <[email protected]> wrote:
>
> > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> > index 2c290e6aaa6e..e6b962ff39b1 100644
> > --- a/arch/riscv/kernel/setup.c
> > +++ b/arch/riscv/kernel/setup.c
> > @@ -171,7 +171,14 @@ asmlinkage void __init setup_vm(void)
> >
> > void __init parse_dtb(unsigned int hartid, void *dtb)
> > {
> > - early_init_dt_scan(__va(dtb));
> > + if (!early_init_dt_scan(__va(dtb)))
> > + return;
> > +
> > + pr_err("No DTB passed to the kernel\n");
>
> Isn't that backwards? early_init_dt_scan returns true if it found a
> DTB.

Yes, it's backwards. Thanks for the catch. Looks like I sent an older
version of the patch.

- Paul

2019-02-19 21:22:27

by Paul Walmsley

[permalink] [raw]
Subject: Re: [PATCH] arch: riscv: fix logic error in parse_dtb



On Thu, 7 Feb 2019, Andreas Schwab wrote:

> The function early_init_dt_scan returns true if a DTB was detected.
>
> Fixes: 8fd6e05c7463 ("arch: riscv: support kernel command line forcing when no DTB passed")
> Signed-off-by: Andreas Schwab <[email protected]>
> ---
> arch/riscv/kernel/setup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 45e9a2f053dc..84f19ca6d88b 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -140,7 +140,7 @@ asmlinkage void __init setup_vm(void)
>
> void __init parse_dtb(unsigned int hartid, void *dtb)
> {
> - if (!early_init_dt_scan(__va(dtb)))
> + if (early_init_dt_scan(__va(dtb)))
> return;
>
> pr_err("No DTB passed to the kernel\n");
> --
> 2.20.1

Reviewed-by: Paul Walmsley <[email protected]>
Tested-by: Paul Walmsley <[email protected]> # FU540 HiFive-U BBL

- Paul