Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Sat, 21 Nov 2009
 13:36:17 -0700
Received: from mail1.lsil.com (mail1.lsil.com [147.145.40.21])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id nALKaE5l028712	for
 <andy.sharp@lsi.com>; Sat, 21 Nov 2009 12:36:16 -0800
Received: from psmtp.com (na3sys009amx168.postini.com [74.125.149.94])	by
 mail1.lsil.com (8.12.11/8.12.11) with SMTP id nALKaBiD029638	for
 <andy.sharp@lsi.com>; Sat, 21 Nov 2009 12:36:12 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx168.postini.com
 ([74.125.148.14]) with SMTP;	Sat, 21 Nov 2009 14:36:13 CST
Received: from localhost.localdomain ([127.0.0.1]:33653 "EHLO
	eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S1493267AbZKUUf5 (ORCPT <rfc822;andy.sharp@lsi.com>);	Sat, 21 Nov
 2009 21:35:57 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Sat, 21 Nov 2009 21:35:39
 +0100 (CET)
Received: from gw02.mail.saunalahti.fi ([195.197.172.116]:45132 "EHLO
	gw02.mail.saunalahti.fi" rhost-flags-OK-OK-OK-OK)	by ftp.linux-mips.org with
 ESMTP id S1493261AbZKUUfd (ORCPT	<rfc822;linux-mips@linux-mips.org>); Sat, 21
 Nov 2009 21:35:33 +0100
Received: from localhost.localdomain (a88-114-232-190.elisa-laajakaista.fi
 [88.114.232.190])	by gw02.mail.saunalahti.fi (Postfix) with ESMTP id
 1BC8013959C;	Sat, 21 Nov 2009 22:35:20 +0200 (EET)
From: Dmitri Vorobiev <dmitri.vorobiev@movial.com>
To: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>,
	"ralf@linux-mips.org" <ralf@linux-mips.org>
CC: Dmitri Vorobiev <dmitri.vorobiev@movial.com>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Sat, 21 Nov 2009 13:34:41 -0700
Subject: [PATCH] [MIPS] Fix and enhance built-in kernel command line
Thread-Topic: [PATCH] [MIPS] Fix and enhance built-in kernel command line
Thread-Index: Acpq6kbkCKgiKh+gRCWfJ18oCD1Hzw==
Message-ID: <1258835681-32200-1-git-send-email-dmitri.vorobiev@movial.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:94.28681/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <dmitri.vorobiev@movial.com> [22/1] 
x-pstn-neptune: 0/0/0.00/0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Currently, MIPS kernels silently overwrite kernel command-line
parameters hardcoded in CONFIG_CMDLINE by the ones received
from firmware.  Therefore, using firmware remains the only
reliable method to transfer the command-line parameters, which
is not always desirable or convenient, and the CONFIG_CMDLINE
option is thereby effectively rendered useless.

This patch fixes the problem described above and introduces
a more flexible scheme of handling the kernel command line,
in a manner identical to what is currently used for x86.
The default behavior, i.e. when CONFIG_CMDLINE_BOOL is not
defined, retains the existing semantics, and firmware
command-line arguments override the hardcoded ones.

Signed-off-by: Dmitri Vorobiev <dmitri.vorobiev@movial.com>
---
 arch/mips/Kconfig.debug  |   45 +++++++++++++++++++++++++++++++++++++++++-=
---
 arch/mips/kernel/setup.c |   24 ++++++++++++++++++++----
 2 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 364ca89..9835030 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -6,15 +6,52 @@ config TRACE_IRQFLAGS_SUPPORT
=20
 source "lib/Kconfig.debug"
=20
+config CMDLINE_BOOL
+	bool "Built-in kernel command line"
+	default n
+	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_OVERRIDE
+	bool "Built-in command line overrides firware arguments"
+	default n
+	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 CMDLINE
 	string "Default kernel command string"
+	depends on CMDLINE_BOOL
 	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
-	  other cases you can specify kernel args so that you don't have
-	  to set them up in board prom initialization routines.
+	  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.
=20
 config DEBUG_STACK_USAGE
 	bool "Enable stack utilization instrumentation"
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index bd55f71..f9513f9 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -58,8 +58,12 @@ EXPORT_SYMBOL(mips_machtype);
=20
 struct boot_mem_map boot_mem_map;
=20
-static char command_line[COMMAND_LINE_SIZE];
-       char arcs_cmdline[COMMAND_LINE_SIZE] =3D CONFIG_CMDLINE;
+static char __initdata command_line[COMMAND_LINE_SIZE];
+char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
+
+#ifdef CONFIG_CMDLINE_BOOL
+static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] =3D CONFIG_CMDLI=
NE;
+#endif
=20
 /*
  * mips_io_port_base is the begin of the address space to which x86 style
@@ -458,8 +462,20 @@ static void __init arch_mem_init(char **cmdline_p)
 	pr_info("Determined physical RAM map:\n");
 	print_memory_map();
=20
-	strlcpy(command_line, arcs_cmdline, sizeof(command_line));
-	strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_OVERRIDE
+	strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+#else
+	if (builtin_cmdline[0]) {
+		strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
+		strlcat(arcs_cmdline, builtin_cmdline, COMMAND_LINE_SIZE);
+	}
+	strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
+#endif
+#else
+	strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
+#endif
+	strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
=20
 	*cmdline_p =3D command_line;
=20
--=20
1.6.3.3


