From patchwork Thu Mar 4 04:47:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel Walker (danielwa)" X-Patchwork-Id: 12115437 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 8DACEC433DB for ; Thu, 4 Mar 2021 04:58:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EC3764EC0 for ; Thu, 4 Mar 2021 04:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234094AbhCDE57 (ORCPT ); Wed, 3 Mar 2021 23:57:59 -0500 Received: from rcdn-iport-3.cisco.com ([173.37.86.74]:26213 "EHLO rcdn-iport-3.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234075AbhCDE5x (ORCPT ); Wed, 3 Mar 2021 23:57:53 -0500 X-Greylist: delayed 540 seconds by postgrey-1.27 at vger.kernel.org; Wed, 03 Mar 2021 23:57:52 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=6395; q=dns/txt; s=iport; t=1614833872; x=1616043472; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=nvJpEND9kOGoIR+3S0EgBmAZax9IS2XBul8csiRffVQ=; b=RDRO0Wkx/DUuzFRwT2OtqcHI2gNl/OjlxkmBmYuK66aH9WRJ8ruSWgwG s03+DpfuOfP2+Rco6bF3KcNfrhZ6SKcUZK11yY+scFdjAyLfz2gIfBGmw EO3br9c5uLLWEVcADM2Ja/Lv+Q0oh7g2Rq6ViY/9otHqw+3n6qUi8v65s w=; X-IronPort-AV: E=Sophos;i="5.81,221,1610409600"; d="scan'208";a="843437001" Received: from alln-core-8.cisco.com ([173.36.13.141]) by rcdn-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 04 Mar 2021 04:48:10 +0000 Received: from zorba.cisco.com ([10.24.7.178]) by alln-core-8.cisco.com (8.15.2/8.15.2) with ESMTP id 1244m4Wv015988; Thu, 4 Mar 2021 04:48:07 GMT From: Daniel Walker To: Will Deacon , Christophe Leroy , ob Herring , Daniel Gimpelevich , Andrew Morton , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: xe-linux-external@cisco.com, Ruslan Bilovol , linux-kernel@vger.kernel.org Subject: [PATCH 1/5] CMDLINE: add generic builtin command line Date: Wed, 3 Mar 2021 20:47:58 -0800 Message-Id: <20210304044803.812204-1-danielwa@cisco.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.24.7.178, [10.24.7.178] X-Outbound-Node: alln-core-8.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This code allows architectures to use a generic builtin command line. The state of the builtin command line options across architecture is diverse. On x86 and mips they have pretty much the same code and the code prepends the builtin command line onto the boot loader provided one. On powerpc there is only a builtin override and nothing else. The code in this commit unifies the code into a generic header file under the CONFIG_GENERIC_CMDLINE option. When this option is enabled the architecture can call the cmdline_add_builtin() to add the builtin command line. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Bilovol Signed-off-by: Daniel Walker --- include/linux/cmdline.h | 75 +++++++++++++++++++++++++++++++++++++++++ init/Kconfig | 68 +++++++++++++++++++++++++++++++++++++ 2 files changed, 143 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..f44011d1a9ee --- /dev/null +++ b/include/linux/cmdline.h @@ -0,0 +1,75 @@ +#ifndef _LINUX_CMDLINE_H +#define _LINUX_CMDLINE_H + +/* + * + * Copyright (C) 2006,2021. Cisco Systems, Inc. + * + * Generic Append/Prepend cmdline support. + */ + +#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL) + +#ifndef CONFIG_CMDLINE_OVERRIDE +/* + * 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 + * @src: The starting string or NULL if there isn't one. + * @tmp: temporary space used for prepending + * @length: the maximum length of the strings above. + */ +static inline void +__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long length, + size_t (*strlcpy)(char *dest, const char *src, size_t size), + size_t (*strlcat)(char *dest, const char *src, size_t count) + ) +{ + if (src != dest && src != NULL) { + strlcpy(dest, " ", length); + strlcat(dest, src, length); + } + + if (sizeof(CONFIG_CMDLINE_APPEND) > 1) + strlcat(dest, " " CONFIG_CMDLINE_APPEND, length); + + if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) { + strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length); + strlcat(tmp, dest, length); + strlcpy(dest, tmp, length); + } +} + +#define cmdline_add_builtin_custom(dest, src, length, label, strlcpy, strlcat) \ +{ \ + if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) { \ + static label char cmdline_tmp_space[length]; \ + __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, strlcpy, strlcat); \ + } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { \ + __cmdline_add_builtin(dest, src, NULL, length, strlcpy, strlcat); \ + } \ +} +#define cmdline_add_builtin(dest, src, length) \ + cmdline_add_builtin_custom(dest, src, length, __initdata, &strlcpy, &strlcat) +#else +#define cmdline_add_builtin(dest, src, length) \ +{ \ + strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, \ + length); \ +} +#endif /* !CONFIG_CMDLINE_OVERRIDE */ + +#else +#define cmdline_add_builtin_custom(dest, src, length, label, strlcpy, strlcat) { \ + if (src != NULL) \ + strlcpy(dest, src, length); \ +} + +#define cmdline_add_builtin(dest, src, length) { \ + cmdline_add_builtin_custom(dest, src, length, strlcpy, strlcat); \ +} +#endif /* CONFIG_GENERIC_CMDLINE */ + + +#endif /* _LINUX_CMDLINE_H */ diff --git a/init/Kconfig b/init/Kconfig index 29ad68325028..28363ab07cd4 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2032,6 +2032,74 @@ config PROFILING config TRACEPOINTS bool +config GENERIC_CMDLINE + bool + +if GENERIC_CMDLINE + +config CMDLINE_BOOL + bool "Built-in kernel command line" + help + Allow for specifying boot arguments to the kernel at + build time. On some systems (e.g. embedded ones), it is + necessary or convenient to provide some or all of the + kernel boot arguments with the kernel itself (that is, + to not rely on the boot loader to provide them.) + + To compile command line arguments into the kernel, + set this option to 'Y', then fill in the + the boot arguments in CONFIG_CMDLINE. + + Systems with fully functional boot loaders (i.e. non-embedded) + should leave this option set to 'N'. + +config CMDLINE_APPEND + string "Built-in kernel command string append" + depends on CMDLINE_BOOL + default "" + help + Enter arguments here that should be compiled into the kernel + image and used at boot time. If the boot loader provides a + command line at boot time, this string is appended to it to + form the full kernel command line, when the system boots. + + However, you can use the CONFIG_CMDLINE_OVERRIDE option to + change this behavior. + + In most cases, the command line (whether built-in or provided + by the boot loader) should specify the device for the root + file system. + +config CMDLINE_PREPEND + string "Built-in kernel command string prepend" + depends on CMDLINE_BOOL + default "" + help + Enter arguments here that should be compiled into the kernel + image and used at boot time. If the boot loader provides a + command line at boot time, this string is prepended to it to + form the full kernel command line, when the system boots. + + However, you can use the CONFIG_CMDLINE_OVERRIDE option to + change this behavior. + + In most cases, the command line (whether built-in or provided + by the boot loader) should specify the device for the root + file system. + +config CMDLINE_OVERRIDE + bool "Built-in command line overrides boot loader arguments" + depends on CMDLINE_BOOL + help + Set this option to 'Y' to have the kernel ignore the boot loader + command line, and use ONLY the built-in command line. In this case + append and prepend strings are concatenated to form the full + command line. + + This is used to work around broken boot loaders. This should + be set to 'N' under normal conditions. +endif + endmenu # General setup source "arch/Kconfig" From patchwork Thu Mar 4 04:47:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel Walker (danielwa)" X-Patchwork-Id: 12115441 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 7AE9DC433E0 for ; Thu, 4 Mar 2021 04:59:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A2CD64EF8 for ; Thu, 4 Mar 2021 04:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233854AbhCDE6b (ORCPT ); Wed, 3 Mar 2021 23:58:31 -0500 Received: from rcdn-iport-4.cisco.com ([173.37.86.75]:49435 "EHLO rcdn-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233908AbhCDE6C (ORCPT ); Wed, 3 Mar 2021 23:58:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1665; q=dns/txt; s=iport; t=1614833882; x=1616043482; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=JPxIpWSiHwMYUhrJK0/YYj5eo6XXFdrmnrzClDHMFxg=; b=iFwTg7VLl8dV3lUL1YFrLdKVb6q+wkEhRJJ6PKGeSt2HvHp33ad5UQ6y 8TX31H+sQhrntFgv0laLfpUoip6b6qqyUYzLK2Hfe+4WU9bEve2OBAali 78jWDKICgLBVlyV2jVPPyIFJHAO4X5pA0qofkSQ9swsOJ0yezwc3CcyHz U=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CaBABRZkBg/40NJK1iHQEBAQEJARIBBQUBgg+CK4FMATkxsmkLAQEBDzQEAQGETYF8AiU4EwIDAQELAQEFAQEBAgEGBHGFboZ9AUaBPgESgnCDCK4cgiiJH4FEFIEkiFx0hBkcgUlCgRGDWIozBIJAB4EOgigSnimbe4MGgR+acg8io1aUVaJGgWsjgVczGggbFYMkUBkNnCsBXCADLzgCBgoBAQMJjBMBAQ X-IronPort-AV: E=Sophos;i="5.81,221,1610409600"; d="scan'208";a="844460945" Received: from alln-core-8.cisco.com ([173.36.13.141]) by rcdn-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 04 Mar 2021 04:48:10 +0000 Received: from zorba.cisco.com ([10.24.7.178]) by alln-core-8.cisco.com (8.15.2/8.15.2) with ESMTP id 1244m4Ww015988; Thu, 4 Mar 2021 04:48:09 GMT From: Daniel Walker To: Will Deacon , Christophe Leroy , ob Herring , Daniel Gimpelevich , Andrew Morton , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Rob Herring , Frank Rowand Cc: xe-linux-external@cisco.com, Ruslan Ruslichenko , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] CMDLINE: drivers: of: ifdef out cmdline section Date: Wed, 3 Mar 2021 20:47:59 -0800 Message-Id: <20210304044803.812204-2-danielwa@cisco.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.24.7.178, [10.24.7.178] X-Outbound-Node: alln-core-8.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org It looks like there's some seepage of cmdline stuff into the generic device tree code. This conflicts with the generic cmdline implementation so I remove it in the case when that's enabled. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Ruslichenko Signed-off-by: Daniel Walker --- drivers/of/fdt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index feb0f2d67fc5..cfe4f8d3c9f5 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 @@ -1048,8 +1049,18 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, early_init_dt_check_for_initrd(node); +#ifdef CONFIG_GENERIC_CMDLINE /* Retrieve command line */ p = of_get_flat_dt_prop(node, "bootargs", &l); + + /* + * The builtin command line will be added here, or it can override + * with the DT bootargs. + */ + cmdline_add_builtin(data, + ((p != NULL && l > 0) ? p : NULL), /* This is sanity checking */ + COMMAND_LINE_SIZE); +#else if (p != NULL && l > 0) strlcpy(data, p, min(l, COMMAND_LINE_SIZE)); @@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); #endif #endif /* CONFIG_CMDLINE */ +#endif /* CONFIG_GENERIC_CMDLINE */ pr_debug("Command line is: %s\n", (char *)data); From patchwork Thu Mar 4 04:48:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel Walker (danielwa)" X-Patchwork-Id: 12115439 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 76201C433E0 for ; Thu, 4 Mar 2021 04:58:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46DDB64EED for ; Thu, 4 Mar 2021 04:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233906AbhCDE57 (ORCPT ); Wed, 3 Mar 2021 23:57:59 -0500 Received: from rcdn-iport-7.cisco.com ([173.37.86.78]:55470 "EHLO rcdn-iport-7.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234089AbhCDE56 (ORCPT ); Wed, 3 Mar 2021 23:57:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=5087; q=dns/txt; s=iport; t=1614833878; x=1616043478; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=B7rBp+oAV8HchVJuk5DlnTjEjxhKnuSRrXyBU5WGoEc=; b=TVS+IoXa4aQQfH3H2OEzXE1hkcN6V0HB17XEqxhkPzupDOAb1c8JbARD WUGDlP6yR281/K6kh7xb9Se5XtxgIl3AwUztVwejTmCSuaP9FPh7WHArr M2qEHzpT6Ah5wknvhstV05mqfKeLzcJVXHgoQVqrdGUsMmOS/eipMd5xN 0=; X-IronPort-AV: E=Sophos;i="5.81,221,1610409600"; d="scan'208";a="855206698" Received: from alln-core-8.cisco.com ([173.36.13.141]) by rcdn-iport-7.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 04 Mar 2021 04:48:11 +0000 Received: from zorba.cisco.com ([10.24.7.178]) by alln-core-8.cisco.com (8.15.2/8.15.2) with ESMTP id 1244m4Wx015988; Thu, 4 Mar 2021 04:48:10 GMT From: Daniel Walker To: Will Deacon , Christophe Leroy , ob Herring , Daniel Gimpelevich , Andrew Morton , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Cc: xe-linux-external@cisco.com, Ruslan Ruslichenko , Ruslan Bilovol , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] CMDLINE: powerpc: convert to generic builtin command line Date: Wed, 3 Mar 2021 20:48:00 -0800 Message-Id: <20210304044803.812204-3-danielwa@cisco.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.24.7.178, [10.24.7.178] X-Outbound-Node: alln-core-8.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE option. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Ruslichenko Signed-off-by: Ruslan Bilovol Signed-off-by: Daniel Walker --- arch/powerpc/Kconfig | 37 +-------------------------------- arch/powerpc/kernel/prom.c | 1 + arch/powerpc/kernel/prom_init.c | 31 +++++++++++++++------------ 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 107bb4319e0e..276b06d5c961 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -167,6 +167,7 @@ config PPC select EDAC_SUPPORT select GENERIC_ATOMIC64 if PPC32 select GENERIC_CLOCKEVENTS_BROADCAST if SMP + select GENERIC_CMDLINE select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_VULNERABILITIES if PPC_BARRIER_NOSPEC @@ -906,42 +907,6 @@ 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" - 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_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" help diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index ae3c41730367..96d0a01be1b4 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index e9d4eb6144e1..d752be688b62 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 @@ -242,15 +243,6 @@ static int __init prom_strcmp(const char *cs, const char *ct) return 0; } -static char __init *prom_strcpy(char *dest, const char *src) -{ - char *tmp = dest; - - while ((*dest++ = *src++) != '\0') - /* nothing */; - return tmp; -} - static int __init prom_strncmp(const char *cs, const char *ct, size_t count) { unsigned char c1, c2; @@ -276,6 +268,19 @@ static size_t __init prom_strlen(const char *s) return sc - s; } +static size_t __init prom_strlcpy(char *dest, const char *src, size_t size) +{ + size_t ret = prom_strlen(src); + + if (size) { + size_t len = (ret >= size) ? size - 1 : ret; + memcpy(dest, src, len); + dest[len] = '\0'; + } + return ret; +} + + static int __init prom_memcmp(const void *cs, const void *ct, size_t count) { const unsigned char *su1, *su2; @@ -778,9 +783,9 @@ static void __init early_cmdline_parse(void) if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0) l = prom_getprop(prom.chosen, "bootargs", p, 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)); + if (l <= 0 || p[0] == '\0') /* dbl check */ + cmdline_add_builtin_custom(prom_cmd_line, NULL, sizeof(prom_cmd_line), + __prombss, &prom_strlcpy, &prom_strlcat); prom_printf("command line: %s\n", prom_cmd_line); @@ -2706,7 +2711,7 @@ static void __init flatten_device_tree(void) /* Add "phandle" in there, we'll need it */ namep = make_room(&mem_start, &mem_end, 16, 1); - prom_strcpy(namep, "phandle"); + prom_strlcpy(namep, "phandle", 8); mem_start = (unsigned long)namep + prom_strlen(namep) + 1; /* Build string array */ From patchwork Thu Mar 4 04:48:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel Walker (danielwa)" X-Patchwork-Id: 12115445 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 A89B0C43381 for ; Thu, 4 Mar 2021 04:59:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 826DC64F02 for ; Thu, 4 Mar 2021 04:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234017AbhCDE6b (ORCPT ); Wed, 3 Mar 2021 23:58:31 -0500 Received: from rcdn-iport-8.cisco.com ([173.37.86.79]:46713 "EHLO rcdn-iport-8.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233884AbhCDE6A (ORCPT ); Wed, 3 Mar 2021 23:58:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=6247; q=dns/txt; s=iport; t=1614833880; x=1616043480; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uPHyrqhndx2XuHWJn770Fcm2MeEJLaI/H/apMZaWTS4=; b=ksWo79qRGjVZtsOhsmE7heAOJ4qlebf5Gq62FM90NU15/Un+EDTGoIya 8PsyYJJF+2+nJmpM84ZgTfDzhq8cPnpK2rvsSIf0akEdfXrIvnok2XcYy SfuhpEMayh646uLrBoMD8ziBTSMUCMMP3xve8ythylSoHC1AJjv5Fl18r 0=; X-IronPort-AV: E=Sophos;i="5.81,221,1610409600"; d="scan'208";a="868193947" Received: from alln-core-8.cisco.com ([173.36.13.141]) by rcdn-iport-8.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 04 Mar 2021 04:48:13 +0000 Received: from zorba.cisco.com ([10.24.7.178]) by alln-core-8.cisco.com (8.15.2/8.15.2) with ESMTP id 1244m4X0015988; Thu, 4 Mar 2021 04:48:12 GMT From: Daniel Walker To: Will Deacon , Christophe Leroy , ob Herring , Daniel Gimpelevich , Andrew Morton , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Thomas Bogendoerfer Cc: xe-linux-external@cisco.com, Ruslan Ruslichenko , Ruslan Bilovol , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] CMDLINE: mips: convert to generic builtin command line Date: Wed, 3 Mar 2021 20:48:01 -0800 Message-Id: <20210304044803.812204-4-danielwa@cisco.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.24.7.178, [10.24.7.178] X-Outbound-Node: alln-core-8.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This updates the mips code to use the CONFIG_GENERIC_CMDLINE option. This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND and replaces the functionality with generic code. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Ruslichenko Signed-off-by: Ruslan Bilovol Signed-off-by: Daniel Walker --- arch/mips/Kconfig | 4 +--- arch/mips/Kconfig.debug | 44 ---------------------------------------- arch/mips/kernel/setup.c | 37 +++++---------------------------- 3 files changed, 6 insertions(+), 79 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 0a17bedf4f0d..7c07b3bca9fc 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -23,6 +23,7 @@ config MIPS select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1) select CPU_PM if CPU_IDLE select GENERIC_ATOMIC64 if !64BIT + select GENERIC_CMDLINE select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE select GENERIC_GETTIMEOFDAY @@ -3171,9 +3172,6 @@ choice config MIPS_CMDLINE_FROM_BOOTLOADER bool "Bootloader kernel arguments if available" - config MIPS_CMDLINE_BUILTIN_EXTEND - depends on CMDLINE_BOOL - bool "Extend builtin kernel arguments with bootloader arguments" endchoice endmenu diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug index 7a8d94cdd493..b5a099c74eb6 100644 --- a/arch/mips/Kconfig.debug +++ b/arch/mips/Kconfig.debug @@ -30,50 +30,6 @@ config EARLY_PRINTK_8250 config USE_GENERIC_EARLY_PRINTK_8250 bool -config CMDLINE_BOOL - bool "Built-in kernel command line" - help - For most systems, it is firmware or second stage bootloader that - by default specifies the kernel command line options. However, - it might be necessary or advantageous to either override the - default kernel command line or add a few extra options to it. - For such cases, this option allows you to hardcode your own - command line options directly into the kernel. For that, you - should choose 'Y' here, and fill in the extra boot arguments - in CONFIG_CMDLINE. - - The built-in options will be concatenated to the default command - line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default - command line will be ignored and replaced by the built-in string. - - Most MIPS systems will normally expect 'N' here and rely upon - the command line from the firmware or the second-stage bootloader. - -config CMDLINE - string "Default kernel command string" - depends on CMDLINE_BOOL - help - On some platforms, there is currently no way for the boot loader to - pass arguments to the kernel. For these platforms, and for the cases - when you want to add some extra options to the command line or ignore - the default command line, you can supply some command-line options at - build time by entering them here. In other cases you can specify - kernel args so that you don't have to set them up in board prom - initialization routines. - - For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE - options. - -config CMDLINE_OVERRIDE - bool "Built-in command line overrides firmware arguments" - depends on CMDLINE_BOOL - help - By setting this option to 'Y' you will have your kernel ignore - command line arguments from firmware or second stage bootloader. - Instead, the built-in command line will be used exclusively. - - Normally, you will choose 'N' here. - config SB1XXX_CORELIS bool "Corelis Debugger" depends on SIBYTE_SB1xxx_SOC diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 7e1f8e277437..b7e9c1ffffc9 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -67,12 +68,6 @@ EXPORT_SYMBOL(mips_machtype); static char __initdata command_line[COMMAND_LINE_SIZE]; char __initdata arcs_cmdline[COMMAND_LINE_SIZE]; -#ifdef CONFIG_CMDLINE_BOOL -static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE; -#else -static const char builtin_cmdline[] __initconst = ""; -#endif - /* * mips_io_port_base is the begin of the address space to which x86 style * I/O ports are mapped. @@ -546,27 +541,7 @@ static void __init bootcmdline_init(void) { bool dt_bootargs = false; - /* - * If CMDLINE_OVERRIDE is enabled then initializing the command line is - * trivial - we simply use the built-in command line unconditionally & - * unmodified. - */ - if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); - return; - } - - /* - * If the user specified a built-in command line & - * MIPS_CMDLINE_BUILTIN_EXTEND, then the built-in command line is - * prepended to arguments from the bootloader or DT so we'll copy them - * to the start of boot_command_line here. Otherwise, empty - * boot_command_line to undo anything early_init_dt_scan_chosen() did. - */ - if (IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)) - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); - else - boot_command_line[0] = 0; + boot_command_line[0] = 0; #ifdef CONFIG_OF_EARLY_FLATTREE /* @@ -589,12 +564,9 @@ static void __init bootcmdline_init(void) bootcmdline_append(arcs_cmdline, COMMAND_LINE_SIZE); /* - * If the user specified a built-in command line & we didn't already - * prepend it, we append it to boot_command_line here. + * Use the generic system for builtin prepend and append. */ - if (IS_ENABLED(CONFIG_CMDLINE_BOOL) && - !IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)) - bootcmdline_append(builtin_cmdline, COMMAND_LINE_SIZE); + cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE); } /* @@ -626,6 +598,7 @@ static void __init arch_mem_init(char **cmdline_p) memblock_set_bottom_up(true); bootcmdline_init(); + strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); *cmdline_p = command_line; From patchwork Thu Mar 4 04:48:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel Walker (danielwa)" X-Patchwork-Id: 12115443 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 66A5DC433DB for ; Thu, 4 Mar 2021 04:59:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3247664EED for ; Thu, 4 Mar 2021 04:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233873AbhCDE6b (ORCPT ); Wed, 3 Mar 2021 23:58:31 -0500 Received: from rcdn-iport-8.cisco.com ([173.37.86.79]:46722 "EHLO rcdn-iport-8.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233889AbhCDE6C (ORCPT ); Wed, 3 Mar 2021 23:58:02 -0500 X-Greylist: delayed 546 seconds by postgrey-1.27 at vger.kernel.org; Wed, 03 Mar 2021 23:58:02 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=4760; q=dns/txt; s=iport; t=1614833882; x=1616043482; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tQ2KjkNmJ1N6aeJwFCAC+GVVOXowsaBAtY9t5Zi/wUA=; b=d5Nq0Jwbi7F2K8PQ3ZgJEQkZ0MhGUpTQO3aLECCdQ1Rv+WqggXP5SWf2 SSOssgC3BsXbidVhFmCbJZIie3wHjFbgHhckayyULgrYLVEjLB0C5fZf4 xxlW5JbGZKo8D54icCp20CspBdJroplpBGMMJJHjtfqVbxtWgxMcvkKvk c=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DCAAAUZkBg/40NJK1iHAEBAQEBAQcBARIBAQQEAQGBfgQBAQsBgiqBTAE5MZYbiieSJwsBAQEPNAQBAYRNgXwCJTcGDgIDAQELAQEFAQEBAgEGBHGFboZ9ATgOgQI8ARKCcIJWAy+uHIIoiDANYoFEFIEkAYhbdIQZHIFJQoERg1iCGogZBIJGAXUZAQolAYFUgRuQHgYEgm2KLoEcmgRbgwaBH5VVhR0PIqNWlFWOP5QHgWokgVczGggbFYMkUBkNjisWjWoBXCADLzgCBgoBAQMJjBMBAQ X-IronPort-AV: E=Sophos;i="5.81,221,1610409600"; d="scan'208";a="868193958" Received: from alln-core-8.cisco.com ([173.36.13.141]) by rcdn-iport-8.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 04 Mar 2021 04:48:15 +0000 Received: from zorba.cisco.com ([10.24.7.178]) by alln-core-8.cisco.com (8.15.2/8.15.2) with ESMTP id 1244m4X1015988; Thu, 4 Mar 2021 04:48:13 GMT From: Daniel Walker To: Will Deacon , Christophe Leroy , ob Herring , Daniel Gimpelevich , Andrew Morton , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: xe-linux-external@cisco.com, Ruslan Ruslichenko , Ruslan Bilovol , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH 5/5] CMDLINE: x86: convert to generic builtin command line Date: Wed, 3 Mar 2021 20:48:02 -0800 Message-Id: <20210304044803.812204-5-danielwa@cisco.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.24.7.178, [10.24.7.178] X-Outbound-Node: alln-core-8.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This updates the x86 code to use the CONFIG_GENERIC_CMDLINE option. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Ruslichenko Signed-off-by: Ruslan Bilovol Signed-off-by: Daniel Walker --- arch/x86/Kconfig | 44 +------------------------ arch/x86/kernel/setup.c | 18 ++-------- drivers/firmware/efi/libstub/x86-stub.c | 2 +- 3 files changed, 4 insertions(+), 60 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 21f851179ff0..3950f9bf9855 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -115,6 +115,7 @@ config X86 select EDAC_SUPPORT select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC) select GENERIC_CLOCKEVENTS_MIN_ADJUST + select GENERIC_CMDLINE select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_VULNERABILITIES @@ -2368,49 +2369,6 @@ choice endchoice -config CMDLINE_BOOL - bool "Built-in kernel command line" - help - Allow for specifying boot arguments to the kernel at - build time. On some systems (e.g. embedded ones), it is - necessary or convenient to provide some or all of the - kernel boot arguments with the kernel itself (that is, - to not rely on the boot loader to provide them.) - - To compile command line arguments into the kernel, - set this option to 'Y', then fill in the - boot arguments in CONFIG_CMDLINE. - - Systems with fully functional boot loaders (i.e. non-embedded) - should leave this option set to 'N'. - -config CMDLINE - string "Built-in kernel command string" - depends on CMDLINE_BOOL - default "" - help - Enter arguments here that should be compiled into the kernel - image and used at boot time. If the boot loader provides a - command line at boot time, it is appended to this string to - form the full kernel command line, when the system boots. - - However, you can use the CONFIG_CMDLINE_OVERRIDE option to - change this behavior. - - In most cases, the command line (whether built-in or provided - by the boot loader) should specify the device for the root - file system. - -config CMDLINE_OVERRIDE - bool "Built-in command line overrides boot loader arguments" - depends on CMDLINE_BOOL && CMDLINE != "" - help - Set this option to 'Y' to have the kernel ignore the boot loader - command line, and use ONLY the built-in command line. - - This is used to work around broken boot loaders. This should - be set to 'N' under normal conditions. - config MODIFY_LDT_SYSCALL bool "Enable the LDT (local descriptor table)" if EXPERT default y diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 740f3bdb3f61..e748c3e5c1ae 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -48,6 +48,7 @@ #include #include #include +#include /* * max_low_pfn_mapped: highest directly mapped pfn < 4 GB @@ -162,9 +163,6 @@ unsigned long saved_video_mode; #define RAMDISK_LOAD_FLAG 0x4000 static char __initdata command_line[COMMAND_LINE_SIZE]; -#ifdef CONFIG_CMDLINE_BOOL -static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; -#endif #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) struct edd edd; @@ -884,19 +882,7 @@ void __init setup_arch(char **cmdline_p) bss_resource.start = __pa_symbol(__bss_start); bss_resource.end = __pa_symbol(__bss_stop)-1; -#ifdef CONFIG_CMDLINE_BOOL -#ifdef CONFIG_CMDLINE_OVERRIDE - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); -#else - if (builtin_cmdline[0]) { - /* append boot loader cmdline to builtin */ - strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); - strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); - } -#endif -#endif - + cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE); strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); *cmdline_p = command_line; diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index f14c4ff5839f..9538c9d4a0bc 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -736,7 +736,7 @@ unsigned long efi_main(efi_handle_t handle, } #ifdef CONFIG_CMDLINE_BOOL - status = efi_parse_options(CONFIG_CMDLINE); + status = efi_parse_options(CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND); if (status != EFI_SUCCESS) { efi_err("Failed to parse options\n"); goto fail;