From patchwork Tue Mar 2 17:25:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 390508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF5F5C28E87 for ; Tue, 2 Mar 2021 20:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A829E601FA for ; Tue, 2 Mar 2021 20:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837057AbhCBUab (ORCPT ); Tue, 2 Mar 2021 15:30:31 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:44895 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352008AbhCBRvJ (ORCPT ); Tue, 2 Mar 2021 12:51:09 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXr0xnBz9v1C0; Tue, 2 Mar 2021 18:25:16 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id GmkJLeTlmTYY; Tue, 2 Mar 2021 18:25:16 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXq6QS8z9v1Bx; Tue, 2 Mar 2021 18:25:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9F8998B7B5; Tue, 2 Mar 2021 18:25:17 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id SpTJBwmTOVdC; Tue, 2 Mar 2021 18:25:17 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 633FD8B75F; Tue, 2 Mar 2021 18:25:17 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 32BC5674A2; Tue, 2 Mar 2021 17:25:17 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 1/7] cmdline: Add generic function to build command line. To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:17 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This code provides architectures with a way to build command line based on what is built in the kernel and what is handed over by the bootloader, based on selected compile-time options. Signed-off-by: Christophe Leroy --- include/linux/cmdline.h | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/linux/cmdline.h diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h new file mode 100644 index 000000000000..ae3610bb0ee2 --- /dev/null +++ b/include/linux/cmdline.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CMDLINE_H +#define _LINUX_CMDLINE_H + +static __always_inline size_t cmdline_strlen(const char *s) +{ + const char *sc; + + for (sc = s; *sc != '\0'; ++sc) + ; /* nothing */ + return sc - s; +} + +static __always_inline size_t cmdline_strlcat(char *dest, const char *src, size_t count) +{ + size_t dsize = cmdline_strlen(dest); + size_t len = cmdline_strlen(src); + size_t res = dsize + len; + + /* This would be a bug */ + if (dsize >= count) + return count; + + dest += dsize; + count -= dsize; + if (len >= count) + len = count - 1; + memcpy(dest, src, len); + dest[len] = 0; + return res; +} + +/* + * This function will append a builtin command line to the command + * line provided by the bootloader. Kconfig options can be used to alter + * the behavior of this builtin command line. + * @dest: The destination of the final appended/prepended string. + * @src: The starting string or NULL if there isn't one. Must not equal dest. + * @length: the length of dest buffer. + */ +static __always_inline void cmdline_build(char *dest, const char *src, size_t length) +{ + if (length <= 0) + return; + + dest[0] = 0; + +#ifdef CONFIG_CMDLINE + if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !src || !src[0]) { + cmdline_strlcat(dest, CONFIG_CMDLINE, length); + return; + } +#endif + if (dest != src) + cmdline_strlcat(dest, src, length); +#ifdef CONFIG_CMDLINE + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && sizeof(CONFIG_CMDLINE) > 1) + cmdline_strlcat(dest, " " CONFIG_CMDLINE, length); +#endif +} + +#endif /* _LINUX_CMDLINE_H */ From patchwork Tue Mar 2 17:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 390510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5B90C28E86 for ; Tue, 2 Mar 2021 20:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64E6964F21 for ; Tue, 2 Mar 2021 20:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837052AbhCBUa3 (ORCPT ); Tue, 2 Mar 2021 15:30:29 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:53420 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352000AbhCBRvF (ORCPT ); Tue, 2 Mar 2021 12:51:05 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXs0XHJz9v1C1; Tue, 2 Mar 2021 18:25:17 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 8AQXiv03Ce1i; Tue, 2 Mar 2021 18:25:17 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXr6pLxz9v1Bx; Tue, 2 Mar 2021 18:25:16 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A124F8B7B5; Tue, 2 Mar 2021 18:25:18 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 3ORhUvp-jb-p; Tue, 2 Mar 2021 18:25:18 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 65EAF8B75F; Tue, 2 Mar 2021 18:25:18 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 3E729674A2; Tue, 2 Mar 2021 17:25:18 +0000 (UTC) Message-Id: <3b4291271ce4af4941a771e5af5cbba3c8fa1b2a.1614705851.git.christophe.leroy@csgroup.eu> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 2/7] drivers: of: use cmdline building function To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:18 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch uses the new cmdline building function to concatenate the of provided cmdline with built-in parts based on compile-time options. Signed-off-by: Christophe Leroy --- drivers/of/fdt.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index dcc1dd96911a..cf2b95b8f298 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -1050,26 +1051,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) - strlcpy(data, p, min(l, COMMAND_LINE_SIZE)); + if (l <= 0) + p = NULL; - /* - * 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 */ + cmdline_build(data, p, COMMAND_LINE_SIZE); pr_debug("Command line is: %s\n", (char *)data); From patchwork Tue Mar 2 17:25:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 392312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DE19C433E0 for ; Tue, 2 Mar 2021 20:39:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 312F864F11 for ; Tue, 2 Mar 2021 20:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239320AbhCBUav (ORCPT ); Tue, 2 Mar 2021 15:30:51 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:13448 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352010AbhCBRvJ (ORCPT ); Tue, 2 Mar 2021 12:51:09 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXt3M4Jz9v1C2; Tue, 2 Mar 2021 18:25:18 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id S_DkUCnzN6bf; Tue, 2 Mar 2021 18:25:18 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXt1tPQz9v1Bx; Tue, 2 Mar 2021 18:25:18 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C2F178B7B5; Tue, 2 Mar 2021 18:25:19 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ycNTALV-gbj4; Tue, 2 Mar 2021 18:25:19 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6A34C8B75F; Tue, 2 Mar 2021 18:25:19 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 44BC5674A2; Tue, 2 Mar 2021 17:25:19 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 3/7] powerpc: convert to generic builtin command line To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:19 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This updates the powerpc code to use the new cmdline building function. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/prom_init.c | 35 +++++---------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index ccf77b985c8f..24157e526f80 100644 --- a/arch/powerpc/kernel/prom_init.c +++ b/arch/powerpc/kernel/prom_init.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -152,7 +153,7 @@ static struct prom_t __prombss prom; static unsigned long __prombss prom_entry; static char __prombss of_stdout_device[256]; -static char __prombss prom_scratch[256]; +static char __prombss prom_scratch[COMMAND_LINE_SIZE]; static unsigned long __prombss dt_header_start; static unsigned long __prombss dt_struct_start, dt_struct_end; @@ -304,26 +305,6 @@ static char __init *prom_strstr(const char *s1, const char *s2) return NULL; } -static size_t __init prom_strlcat(char *dest, const char *src, size_t count) -{ - size_t dsize = prom_strlen(dest); - size_t len = prom_strlen(src); - size_t res = dsize + len; - - /* This would be a bug */ - if (dsize >= count) - return count; - - dest += dsize; - count -= dsize; - if (len >= count) - len = count-1; - memcpy(dest, src, len); - dest[len] = 0; - return res; - -} - #ifdef CONFIG_PPC_PSERIES static int __init prom_strtobool(const char *s, bool *res) { @@ -768,19 +749,13 @@ static unsigned long prom_memparse(const char *ptr, const char **retptr) static void __init early_cmdline_parse(void) { const char *opt; - - char *p; int l = 0; - prom_cmd_line[0] = 0; - p = prom_cmd_line; - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0) - l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); + l = prom_getprop(prom.chosen, "bootargs", prom_scratch, + COMMAND_LINE_SIZE - 1); - if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || l <= 0 || p[0] == '\0') - prom_strlcat(prom_cmd_line, " " CONFIG_CMDLINE, - sizeof(prom_cmd_line)); + cmdline_build(prom_cmd_line, l > 0 ? prom_scratch : NULL, sizeof(prom_scratch)); prom_printf("command line: %s\n", prom_cmd_line); From patchwork Tue Mar 2 17:25:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 390507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 899BDC433DB for ; Tue, 2 Mar 2021 20:38:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3843364F2A for ; Tue, 2 Mar 2021 20:38:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837063AbhCBUan (ORCPT ); Tue, 2 Mar 2021 15:30:43 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:44261 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352011AbhCBRvJ (ORCPT ); Tue, 2 Mar 2021 12:51:09 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXv5h6Lz9v1C5; Tue, 2 Mar 2021 18:25:19 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id iMobo7Uj95lP; Tue, 2 Mar 2021 18:25:19 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXv07VPz9v1C4; Tue, 2 Mar 2021 18:25:19 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BB7A38B75F; Tue, 2 Mar 2021 18:25:20 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id oLcqukm6Bo_U; Tue, 2 Mar 2021 18:25:20 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 77FDD8B7B6; Tue, 2 Mar 2021 18:25:20 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 5247C674A2; Tue, 2 Mar 2021 17:25:20 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 4/7] cmdline: Add capability to prepend the command line To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:20 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patchs adds an option of prepend a text to the command line instead of appending it. Signed-off-by: Christophe Leroy --- include/linux/cmdline.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h index ae3610bb0ee2..144346051e01 100644 --- a/include/linux/cmdline.h +++ b/include/linux/cmdline.h @@ -31,7 +31,7 @@ static __always_inline size_t cmdline_strlcat(char *dest, const char *src, size_ } /* - * This function will append a builtin command line to the command + * This function will append or prepend a builtin command line to the command * line provided by the bootloader. Kconfig options can be used to alter * the behavior of this builtin command line. * @dest: The destination of the final appended/prepended string. @@ -50,6 +50,9 @@ static __always_inline void cmdline_build(char *dest, const char *src, size_t le cmdline_strlcat(dest, CONFIG_CMDLINE, length); return; } + + if (IS_ENABLED(CONFIG_CMDLINE_PREPEND) && sizeof(CONFIG_CMDLINE) > 1) + cmdline_strlcat(dest, CONFIG_CMDLINE " ", length); #endif if (dest != src) cmdline_strlcat(dest, src, length); From patchwork Tue Mar 2 17:25:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 392316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA249C28E85 for ; Tue, 2 Mar 2021 20:31:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 866DD601FA for ; Tue, 2 Mar 2021 20:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837032AbhCBUaP (ORCPT ); Tue, 2 Mar 2021 15:30:15 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:15489 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1580133AbhCBRa2 (ORCPT ); Tue, 2 Mar 2021 12:30:28 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXw1XPpz9v1C4; Tue, 2 Mar 2021 18:25:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id LhQkvn-K5PGS; Tue, 2 Mar 2021 18:25:20 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXw0jTRz9v1Bx; Tue, 2 Mar 2021 18:25:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D8B9B8B7B5; Tue, 2 Mar 2021 18:25:21 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id huFmz8x1Abk4; Tue, 2 Mar 2021 18:25:21 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7FD0C8B75F; Tue, 2 Mar 2021 18:25:21 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 5934E674A2; Tue, 2 Mar 2021 17:25:21 +0000 (UTC) Message-Id: <54fd814a0c7aad690fa3aceaab5f35cb930c681a.1614705851.git.christophe.leroy@csgroup.eu> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 5/7] powerpc: add capability to prepend default command line To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:21 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch activates the capability to prepend default arguments to the command line. Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 386ae12d8523..0ab406f14513 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -912,6 +912,12 @@ config CMDLINE_EXTEND The command-line arguments provided by the boot loader will be appended to the default kernel command string. +config CMDLINE_PREPEND + bool "Prepend bootloader kernel arguments" + help + The default kernel command string will be prepend to the + command-line arguments provided during boot. + config CMDLINE_FORCE bool "Always use the default kernel command string" help From patchwork Tue Mar 2 17:25:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 390511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C861C433E9 for ; Tue, 2 Mar 2021 20:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1662601FA for ; Tue, 2 Mar 2021 20:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837039AbhCBUaR (ORCPT ); Tue, 2 Mar 2021 15:30:17 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:11171 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1580134AbhCBRaa (ORCPT ); Tue, 2 Mar 2021 12:30:30 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXx1fpcz9v1C3; Tue, 2 Mar 2021 18:25:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id sT1ZG-RjsZzl; Tue, 2 Mar 2021 18:25:21 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXx0pQZz9v1Bx; Tue, 2 Mar 2021 18:25:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D91F38B7B5; Tue, 2 Mar 2021 18:25:22 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id J4vFCr8DsRjb; Tue, 2 Mar 2021 18:25:22 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 849C58B75F; Tue, 2 Mar 2021 18:25:22 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 5FB57674A2; Tue, 2 Mar 2021 17:25:22 +0000 (UTC) Message-Id: <2eb6fad3470256fff5c9f33cd876f344abb1628b.1614705851.git.christophe.leroy@csgroup.eu> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 6/7] cmdline: Gives architectures opportunity to use generically defined boot cmdline manipulation To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:22 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Most architectures have similar boot command line manipulation options. This patchs adds the definition in init/Kconfig, gated by CONFIG_HAVE_CMDLINE that the architectures can select to use them. In order to use this, a few architectures will have to change their CONFIG options: - riscv has to replace CMDLINE_FALLBACK by CMDLINE_FROM_BOOTLOADER - architectures using CONFIG_CMDLINE_OVERRIDE or CONFIG_CMDLINE_OVERWRITE have to replace them by CONFIG_CMDLINE_FORCE. Architectures also have to define CONFIG_DEFAULT_CMDLINE. Signed-off-by: Christophe Leroy Reported-by: kernel test robot --- init/Kconfig | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index 22946fe5ded9..a0f2ad9467df 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -117,6 +117,62 @@ config INIT_ENV_ARG_LIMIT Maximum of each of the number of arguments and environment variables passed to init from the kernel command line. +config HAVE_CMDLINE + bool + +config CMDLINE_BOOL + bool "Default bootloader kernel arguments" + depends on HAVE_CMDLINE + help + On some platforms, there is currently no way for the boot loader to + pass arguments to the kernel. For these platforms, you can supply + some command-line options at build time by entering them here. In + most cases you will need to specify the root device here. + +config CMDLINE + string "Initial kernel command string" + depends on CMDLINE_BOOL + default DEFAULT_CMDLINE + help + On some platforms, there is currently no way for the boot loader to + pass arguments to the kernel. For these platforms, you can supply + some command-line options at build time by entering them here. In + most cases you will need to specify the root device here. + +choice + prompt "Kernel command line type" if CMDLINE != "" + default CMDLINE_FROM_BOOTLOADER + help + Selects the way you want to use the default kernel arguments. + +config CMDLINE_FROM_BOOTLOADER + bool "Use bootloader kernel arguments if available" + help + Uses the command-line options passed by the boot loader. If + the boot loader doesn't provide any, the default kernel command + string provided in CMDLINE will be used. + +config CMDLINE_EXTEND + bool "Extend bootloader kernel arguments" + help + The default kernel command string will be appended to the + command-line arguments provided during boot. + +config CMDLINE_PREPEND + bool "Prepend bootloader kernel arguments" + help + The default kernel command string will be prepend to the + command-line arguments provided during boot. + +config CMDLINE_FORCE + bool "Always use the default kernel command string" + help + Always use the default kernel command string, even if the boot + loader passes other arguments to the kernel. + This is useful if you cannot or don't want to change the + command-line options your boot loader passes to the kernel. +endchoice + config COMPILE_TEST bool "Compile also drivers which will not load" depends on !UML && !S390 From patchwork Tue Mar 2 17:25:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 392318 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E96D6C41621 for ; Tue, 2 Mar 2021 20:31:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A724664F2A for ; Tue, 2 Mar 2021 20:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1837036AbhCBUaQ (ORCPT ); Tue, 2 Mar 2021 15:30:16 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:34960 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1580129AbhCBRa2 (ORCPT ); Tue, 2 Mar 2021 12:30:28 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DqkXy20Hsz9v1C6; Tue, 2 Mar 2021 18:25:22 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 1soGvYo9N__u; Tue, 2 Mar 2021 18:25:22 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DqkXy17Mvz9v1Bx; Tue, 2 Mar 2021 18:25:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D69FD8B7B5; Tue, 2 Mar 2021 18:25:23 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ng1sUe2tw1bh; Tue, 2 Mar 2021 18:25:23 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9C9818B75F; Tue, 2 Mar 2021 18:25:23 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 75D1F674A2; Tue, 2 Mar 2021 17:25:23 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 7/7] powerpc: use generic CMDLINE manipulations To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , danielwa@cisco.com, robh@kernel.org, daniel@gimpelevich.san-francisco.ca.us Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 2 Mar 2021 17:25:23 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch moves powerpc to the centraly defined CMDLINE options. Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 0ab406f14513..0e1736a2a621 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -195,6 +195,7 @@ config PPC select HAVE_CBPF_JIT if !PPC64 select HAVE_STACKPROTECTOR if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13) select HAVE_STACKPROTECTOR if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2) + select HAVE_CMDLINE select HAVE_CONTEXT_TRACKING if PPC64 select HAVE_DEBUG_KMEMLEAK select HAVE_DEBUG_STACKOVERFLOW @@ -886,47 +887,9 @@ config PPC_DENORMALISATION Add support for handling denormalisation of single precision values. Useful for bare metal only. If unsure say Y here. -config CMDLINE - string "Initial kernel command string" +config DEFAULT_CMDLINE + string default "" - help - On some platforms, there is currently no way for the boot loader to - pass arguments to the kernel. For these platforms, you can supply - some command-line options at build time by entering them here. In - most cases you will need to specify the root device here. - -choice - prompt "Kernel command line type" if CMDLINE != "" - default CMDLINE_FROM_BOOTLOADER - -config CMDLINE_FROM_BOOTLOADER - bool "Use bootloader kernel arguments if available" - help - Uses the command-line options passed by the boot loader. If - the boot loader doesn't provide any, the default kernel command - string provided in CMDLINE will be used. - -config CMDLINE_EXTEND - bool "Extend bootloader kernel arguments" - help - The command-line arguments provided by the boot loader will be - appended to the default kernel command string. - -config CMDLINE_PREPEND - bool "Prepend bootloader kernel arguments" - help - The default kernel command string will be prepend to the - command-line arguments provided during boot. - -config CMDLINE_FORCE - bool "Always use the default kernel command string" - help - Always use the default kernel command string, even if the boot - loader passes other arguments to the kernel. - This is useful if you cannot or don't want to change the - command-line options your boot loader passes to the kernel. - -endchoice config EXTRA_TARGETS string "Additional default image types"