From patchwork Tue Oct 6 15:59:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Walker X-Patchwork-Id: 7336751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A7B369F32B for ; Tue, 6 Oct 2015 16:06:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8FB482064D for ; Tue, 6 Oct 2015 16:06:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A5C420591 for ; Tue, 6 Oct 2015 16:06:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZjUii-0006QA-1y; Tue, 06 Oct 2015 16:04:04 +0000 Received: from ec2-54-201-57-178.us-west-2.compute.amazonaws.com ([54.201.57.178] helo=ip-172-31-12-36.us-west-2.compute.internal) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZjUie-0006Is-OF for linux-arm-kernel@lists.infradead.org; Tue, 06 Oct 2015 16:04:01 +0000 Received: by ip-172-31-12-36.us-west-2.compute.internal (Postfix, from userid 1001) id 8D9EA41069; Tue, 6 Oct 2015 15:59:44 +0000 (UTC) Date: Tue, 6 Oct 2015 08:59:44 -0700 From: dwalker@fifo99.com To: Russell King - ARM Linux Subject: [danielwa@cisco.com: [PATCH-RFC 1/7] add generic builtin command line] Message-ID: <20151006155944.GA20100@fifo99.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151006_090400_860718_5A0BE649 X-CRM114-Status: GOOD ( 25.69 ) X-Spam-Score: 1.0 (+) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ----- Forwarded message from Daniel Walker ----- Date: Tue, 6 Oct 2015 08:47:08 -0700 From: Daniel Walker To: xe-kernel@external.cisco.com, Andrew Morton Cc: Daniel Walker , linux-kernel@vger.kernel.org Subject: [PATCH-RFC 1/7] add generic builtin command line X-Mailer: git-send-email 2.1.4 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 mips and x86 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-kernel@external.cisco.com Cc: Daniel Walker Signed-off-by: Daniel Walker --- include/linux/cmdline.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ init/Kconfig | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 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 0000000..42282a1 --- /dev/null +++ b/include/linux/cmdline.h @@ -0,0 +1,69 @@ +#ifndef _LINUX_CMDLINE_H +#define _LINUX_CMDLINE_H + +/* + * + * Copyright (C) 2015. 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, char *src, char *tmp, unsigned long length) +{ + if (src != dest && src != NULL) { + strlcpy(dest, " ", length); + strlcat(dest, src, length); + } + + strlcat(dest, " ", 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, " ", length); + strlcat(tmp, dest, length); + strlcpy(dest, tmp, length); + } +} + +#define cmdline_add_builtin(dest, src, length) \ +{ \ + if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) { \ + static __initdata char cmdline_tmp_space[length]; \ + _cmdline_add_builtin(dest, src, cmdline_tmp_space, length); \ + } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { \ + _cmdline_add_builtin(dest, src, NULL, length); \ + } \ +} +#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(dest, src, length) { \ + if (src != NULL) \ + strlcpy(dest, src, length); \ +} +#endif /* CONFIG_GENERIC_CMDLINE */ + + +#endif /* _LINUX_CMDLINE_H */ diff --git a/init/Kconfig b/init/Kconfig index c24b6f7..704bed4 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1808,6 +1808,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 + source "arch/Kconfig" endmenu # General setup