From patchwork Thu Oct 4 12:31:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Kossifidis X-Patchwork-Id: 978849 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ics.forth.gr Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42QstS2pxmz9s55 for ; Thu, 4 Oct 2018 22:40:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727256AbeJDTdh (ORCPT ); Thu, 4 Oct 2018 15:33:37 -0400 Received: from mailgate-4.ics.forth.gr ([139.91.1.7]:22917 "EHLO mailgate-4.ics.forth.gr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727209AbeJDTdh (ORCPT ); Thu, 4 Oct 2018 15:33:37 -0400 X-Greylist: delayed 523 seconds by postgrey-1.27 at vger.kernel.org; Thu, 04 Oct 2018 15:33:35 EDT Received: from av1.ics.forth.gr (av3in.ics.forth.gr. [139.91.1.77]) by mailgate-4.ics.forth.gr (8.14.5/ICS-FORTH/V10-1.9-GATE-OUT) with ESMTP id w94CVKAJ084441; Thu, 4 Oct 2018 15:31:22 +0300 (EEST) X-AuditID: 8b5b9d4d-903ff70000000e62-30-5bb60818e459 Received: from enigma.ics.forth.gr (enigma.ics.forth.gr [139.91.1.35]) by av1.ics.forth.gr (SMTP Outbound / FORTH / ICS) with SMTP id A6.2A.03682.81806BB5; Thu, 4 Oct 2018 15:31:20 +0300 (EEST) Received: from trampakoulas.ics.forth.gr (trampakoulas.ics.forth.gr [139.91.92.59]) (authenticated bits=0) by enigma.ics.forth.gr (8.15.1//ICS-FORTH/V10.5.0C-EXTNULL-SSL-SASL) with ESMTPSA id w94CVHCd022886 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 4 Oct 2018 15:31:20 +0300 X-ICS-AUTH-INFO: Authenticated user: mick@ics.forth.gr at ics.forth.gr From: Nick Kossifidis To: devicetree@vger.kernel.org Cc: robh+dt@kernel.org, frowand.list@gmail.com, linux-riscv@lists.infradead.org, palmer@sifive.com, Nick Kossifidis Subject: [PATCH] OF: Handle CMDLINE when /chosen node is not present Date: Thu, 4 Oct 2018 15:31:10 +0300 Message-Id: <20181004123110.8487-1-mick@ics.forth.gr> X-Mailer: git-send-email 2.16.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGJMWRmVeSWpSXmKPExsXSHc2orCvBsS3aYN1WM4v5R86xWsx885/N YtvnFjaL5nfn2C02T1jAatG69wi7A5vHzll32T0ebrrE5LFpVSebx+Yl9R6Xmq+ze3zeJBfA FsVlk5Kak1mWWqRvl8CV8af7CVvBKemKqfu2Mjcw7hbrYuTkkBAwkeh4+4yxi5GLQ0jgCKPE oosXWCGcPUwSrx+1MENUuUncvr+TFcRmE9CUmH/pIAuILSIgJ3Hz6102EJtZYCajxPNXHiC2 sICLxJ7/r8HqWQRUJT4vWs4OYvMKmEpsPfOFFWKmvMSv55+ZJzByL2BkWMUokFhmrJeZXKyX ll9UkqGXXrSJERwac313MJ5bYH+IUYCDUYmHt+Pdlmgh1sSy4srcQ4wSHMxKIrxH/22NFuJN SaysSi3Kjy8qzUktPsQozcGiJM57+EV4kJBAemJJanZqakFqEUyWiYNTqoExWHcL64vj5im/ di1f/2a+SNaDhI9f5i+M1pY0aMw6lb6A9YfqZYW4htacQ4V3uyYVcZm31j+cy7ufx83qY7nD 36NHNrtMnXnS1/Rp5MN/J+Xda/dl8pXOKvl5b7VD5uIZuy+Ymk94cdt83d20h70T6hcpbS25 U9Zet/7ERWkVmQ9n+rLzT/VsUWIpzkg01GIuKk4EAF8npYkJAgAA Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The /chosen node is optional so we should handle CMDLINE regardless the presence of /chosen/bootargs. Move handling of CMDLINE in early_init_dt_scan() instead. Signed-off-by: Nick Kossifidis --- drivers/of/fdt.c | 69 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 800ad252c..868464b0b 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -31,6 +31,14 @@ #include "of_private.h" +#ifdef CONFIG_CMDLINE +#ifdef CONFIG_CMDLINE_FORCE +static const char fixed_cmdline[] __initconst = CONFIG_CMDLINE; +#else +static char builtin_cmdline[] __initdata = CONFIG_CMDLINE; +#endif +#endif + /* * of_fdt_limit_memory - limit the number of regions in the /memory node * @limit: maximum entries @@ -1088,28 +1096,10 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, /* Retrieve command line */ p = of_get_flat_dt_prop(node, "bootargs", &l); - if (p != NULL && l > 0) + if (p != NULL && l > 0) { strlcpy(data, p, min((int)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. - */ -#ifdef CONFIG_CMDLINE -#if defined(CONFIG_CMDLINE_EXTEND) - 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); -#endif -#endif /* CONFIG_CMDLINE */ - - pr_debug("Command line is: %s\n", (char*)data); + pr_debug("Got bootargs: %s\n", (char *) data); + } /* break now */ return 1; @@ -1240,6 +1230,43 @@ bool __init early_init_dt_scan(void *params) return false; early_init_dt_scan_nodes(); + + /* + * The /chosen node normaly contains the bootargs element + * that includes the kernel's command line parameters. + * However the presence of /chosen is not mandatory so + * in case we didn't get a command line when scanning + * nodes above, we should provide one here before we + * return, if possible. + * + * The built-in command line can be used as a default + * command line in case we received nothing from the + * device tree/bootloader. It can also be used for + * extending or replacing the received command line. + */ +#ifdef CONFIG_CMDLINE +#if defined(CONFIG_CMDLINE_EXTEND) + /* + * Order of parameters shouldn't matter for most cases, + * so prepending or appending the built-in command line + * shouldn't make a difference. In cases where it does + * it's up to the user to configure the kernel and/or + * the bootloader properly. + */ + if (builtin_cmdline[0]) { + strlcat(boot_command_line, " ", COMMAND_LINE_SIZE); + strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); + } +#elif defined(CONFIG_CMDLINE_FORCE) + if (fixed_cmdline[0]) + strlcpy(boot_command_line, fixed_cmdline, COMMAND_LINE_SIZE); +#else + /* No arguments from boot loader, use kernel's cmdline */ + if (!boot_command_line[0] && builtin_cmdline[0]) + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); +#endif +#endif /* CONFIG_CMDLINE */ + return true; }