diff mbox series

arch: riscv: support kernel command line forcing when no DTB passed

Message ID alpine.DEB.2.21.9999.1812171913510.29609@viisi.sifive.com (mailing list archive)
State New, archived
Headers show
Series arch: riscv: support kernel command line forcing when no DTB passed | expand

Commit Message

Paul Walmsley Dec. 18, 2018, 3:15 a.m. UTC
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 <palmer@sifive.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-riscv@lists.infradead.org
Cc: linux-kernel@vger.kernel.org (open list)
Signed-off-by: Paul Walmsley <paul.walmsley@sifive.com>
Signed-off-by: Paul Walmsley <paul@pwsan.com>
---

Applies on v4.20-rc7.

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

Comments

Christoph Hellwig Jan. 15, 2019, 3:44 p.m. UTC | #1
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 <hch@lst.de>

I just wish all this command line magic could be moved to common
code somewhere instead of being reinvented badly in every port..
Andreas Schwab Feb. 5, 2019, 5:43 p.m. UTC | #2
On Dez 17 2018, Paul Walmsley <paul.walmsley@sifive.com> 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.
Paul Walmsley Feb. 19, 2019, 9:19 p.m. UTC | #3
On Tue, 5 Feb 2019, Andreas Schwab wrote:

> On Dez 17 2018, Paul Walmsley <paul.walmsley@sifive.com> 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
diff mbox series

Patch

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)