linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Walker <danielwa@cisco.com>
To: Will Deacon <will@kernel.org>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Rob Herring <robh@kernel.org>,
	Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>,
	Andrew Morton <akpm@linux-foundation.org>,
	x86@kernel.org, linux-mips@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>
Cc: xe-linux-external@cisco.com, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] of: allow sending a NULL value to early_init_dt_scan_chosen
Date: Thu, 15 Apr 2021 21:09:18 -0700	[thread overview]
Message-ID: <20210416040924.2882771-8-danielwa@cisco.com> (raw)
In-Reply-To: <20210416040924.2882771-1-danielwa@cisco.com>

It's possible that an architecture may want to populate
boot_command_line before calling the device tree code.
Currently, early_init_dt_scan_chosen won't accept a NULL
in the data parameter and it returns immediately if you
send one.

I changed early_init_dt_scan_nodes() to send a NULL into
early_init_dt_scan_chosen() , then I made
early_init_dt_scan_chosen() to do the initrd checking, and
the rng-seed checking and skip all the command line related
code.

Given lots of changes to the command line, I think it makes sense
to allow the initrd code and rng-seed code to be run without
forcing the command line handling. I'm also submitting changes
to arm64 which populate boot_command_line much early and this
device tree code overwrites boot_command_line in that case.

This code depends on all architecture to have a NULL
boot_command_line at boot up when this function runs, unless
it's already populated.

This code was boot tested on powerpc 32bit, x86, and arm64.

Cc: xe-linux-external@cisco.com
Signed-off-by: Daniel Walker <danielwa@cisco.com>
---
 drivers/of/fdt.c | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index adb26aff481d..a1fda952ce60 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1052,36 +1052,38 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
 
 	pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
-	if (depth != 1 || !data ||
-	    (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
+	if (depth != 1 || (strcmp(uname, "chosen") != 0
+				&& strcmp(uname, "chosen@0") != 0))
 		return 0;
 
 	early_init_dt_check_for_initrd(node);
 
-	/* Retrieve command line */
-	p = of_get_flat_dt_prop(node, "bootargs", &l);
-	if (p != NULL && l > 0)
-		strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
+	if (data) {
+		/* Retrieve command line */
+		p = of_get_flat_dt_prop(node, "bootargs", &l);
+		if (p != NULL && l > 0)
+			strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
-	/*
-	 * CONFIG_CMDLINE is meant to be a default in case nothing else
-	 * managed to set the command line, unless CONFIG_CMDLINE_FORCE
-	 * is set in which case we override whatever was found earlier.
-	 */
+		/*
+		 * CONFIG_CMDLINE is meant to be a default in case nothing else
+		 * managed to set the command line, unless CONFIG_CMDLINE_FORCE
+		 * is set in which case we override whatever was found earlier.
+		 */
 #ifdef CONFIG_CMDLINE
 #if defined(CONFIG_CMDLINE_EXTEND)
-	strlcat(data, " ", COMMAND_LINE_SIZE);
-	strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+		strlcat(data, " ", COMMAND_LINE_SIZE);
+		strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #elif defined(CONFIG_CMDLINE_FORCE)
-	strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
-#else
-	/* No arguments from boot loader, use kernel's  cmdl*/
-	if (!((char *)data)[0])
 		strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+#else
+		/* No arguments from boot loader, use kernel's  cmdl*/
+		if (!((char *)data)[0])
+			strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
 
-	pr_debug("Command line is: %s\n", (char *)data);
+		pr_debug("Command line is: %s\n", (char *)data);
+	}
 
 	rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l);
 	if (rng_seed && l > 0) {
@@ -1202,7 +1204,11 @@ void __init early_init_dt_scan_nodes(void)
 	int rc = 0;
 
 	/* Retrieve various information from the /chosen node */
-	rc = of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
+	if (boot_command_line[0])
+		rc = of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
+	else
+		rc = of_scan_flat_dt(early_init_dt_scan_chosen,
+					boot_command_line);
 	if (!rc)
 		pr_warn("No chosen node found, continuing without\n");
 
-- 
2.25.1


  parent reply	other threads:[~2021-04-16  4:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16  4:09 [PATCH 0/8] generic command line v4 Daniel Walker
2021-04-16  4:09 ` [PATCH 1/8] CMDLINE: add generic builtin command line Daniel Walker
2021-04-16  4:09 ` [PATCH 2/8] scripts: insert-sys-cert: add command line insert capability Daniel Walker
2021-04-16  4:09 ` [PATCH 3/8] scripts: insert-sys-cert: change name to insert-symbol Daniel Walker
2021-04-16  4:09 ` [PATCH 4/8] CMDLINE: mips: convert to generic builtin command line Daniel Walker
2021-04-16  4:09 ` [PATCH 5/8] drivers: firmware: efi: libstub: enable generic commandline Daniel Walker
2021-04-16  4:09 ` [PATCH 6/8] CMDLINE: x86: convert to generic builtin command line Daniel Walker
2021-04-16  4:09 ` Daniel Walker [this message]
2021-04-16  4:09 ` [PATCH 8/8] CMDLINE: arm64: " Daniel Walker
2022-09-22 20:45 ` [PATCH 0/8] generic command line v4 Sean Anderson
2022-09-22 20:53   ` Daniel Walker
2022-09-22 21:03     ` Sean Anderson
2022-09-22 21:10       ` Daniel Walker
2022-09-22 21:15         ` Daniel Gimpelevich
2022-09-26 22:52           ` Rob Herring
2022-09-26 23:03             ` Daniel Walker
2022-09-26 22:59           ` Daniel Walker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416040924.2882771-8-danielwa@cisco.com \
    --to=danielwa@cisco.com \
    --cc=akpm@linux-foundation.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=daniel@gimpelevich.san-francisco.ca.us \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=robh+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=xe-linux-external@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).