From: mick@ics.forth.gr (Nick Kossifidis)
To: linux-riscv@lists.infradead.org
Subject: [PATCH] RISC-V: Implement built-in command line feature
Date: Tue, 2 Oct 2018 17:04:49 +0300 [thread overview]
Message-ID: <20181002140449.24147-1-mick@ics.forth.gr> (raw)
This patch enables the use of a built-in kernel command line, which can
optionaly also override the command line provided by the boot loader.
Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
---
arch/riscv/kernel/setup.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index aee603123..fd171ca7f 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -30,6 +30,7 @@
#include <linux/of_platform.h>
#include <linux/sched/task.h>
#include <linux/swiotlb.h>
+#include <linux/string.h>
#include <asm/setup.h>
#include <asm/sections.h>
@@ -39,6 +40,14 @@
#include <asm/tlbflush.h>
#include <asm/thread_info.h>
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_FORCE
+ static const char fixed_cmdline[] __initconst = CONFIG_CMDLINE;
+#else
+ static char builtin_cmdline[] __initdata = CONFIG_CMDLINE;
+#endif
+#endif
+
#ifdef CONFIG_EARLY_PRINTK
static void sbi_console_write(struct console *co, const char *buf,
unsigned int n)
@@ -215,6 +224,46 @@ void __init setup_arch(char **cmdline_p)
register_console(early_console);
}
#endif
+
+ /* When we return, cmdline_p should point to a temporary
+ * buffer on the kernel's init section (that gets cleaned up
+ * later on) to be saved on static_command_line and parsed for
+ * parameters.
+ *
+ * That string may get tweaked during parameter parsing so we
+ * also want to keep an untouched version of the command line
+ * to display on dmesg, /proc/cmdline etc.
+ *
+ * At this point boot_command_line is a temporary buffer
+ * (also on the init section) that contains the command line
+ * string passed from the boot loader. After we return,
+ * it will be saved to saved_command_line that holds the
+ * untouched version of the command line.
+ *
+ * Since we won't be doing any parameter parsing here, we'll
+ * hold the initial/untouched command line string on
+ * boot_command_line and make cmdline_p point to it as well.
+ * This way boot_command_line will be copied to both
+ * saved_command_line and static_command_line.
+ */
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_FORCE
+ /* Built-in args override boot loader args and
+ * boot loader args are being ignored.
+ */
+ strlcpy(boot_command_line, fixed_cmdline, COMMAND_LINE_SIZE);
+#else
+ /* Boot loader args override built-in args so we
+ * need to put built-in args before boot loader args.
+ */
+ if (builtin_cmdline[0]) {
+ 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_p = boot_command_line;
parse_early_param();
--
2.16.4
WARNING: multiple messages have this Message-ID (diff)
From: Nick Kossifidis <mick@ics.forth.gr>
To: linux-riscv@lists.infradead.org
Cc: Nick Kossifidis <mick@ics.forth.gr>,
palmer@sifive.com, aou@eecs.berkeley.edu
Subject: [PATCH] RISC-V: Implement built-in command line feature
Date: Tue, 2 Oct 2018 17:04:49 +0300 [thread overview]
Message-ID: <20181002140449.24147-1-mick@ics.forth.gr> (raw)
Message-ID: <20181002140449.2Yd1Ns8hS_NRo9T78BecqikX83kXhbH9MrroMR5Mo-4@z> (raw)
This patch enables the use of a built-in kernel command line, which can
optionaly also override the command line provided by the boot loader.
Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
---
arch/riscv/kernel/setup.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index aee603123..fd171ca7f 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -30,6 +30,7 @@
#include <linux/of_platform.h>
#include <linux/sched/task.h>
#include <linux/swiotlb.h>
+#include <linux/string.h>
#include <asm/setup.h>
#include <asm/sections.h>
@@ -39,6 +40,14 @@
#include <asm/tlbflush.h>
#include <asm/thread_info.h>
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_FORCE
+ static const char fixed_cmdline[] __initconst = CONFIG_CMDLINE;
+#else
+ static char builtin_cmdline[] __initdata = CONFIG_CMDLINE;
+#endif
+#endif
+
#ifdef CONFIG_EARLY_PRINTK
static void sbi_console_write(struct console *co, const char *buf,
unsigned int n)
@@ -215,6 +224,46 @@ void __init setup_arch(char **cmdline_p)
register_console(early_console);
}
#endif
+
+ /* When we return, cmdline_p should point to a temporary
+ * buffer on the kernel's init section (that gets cleaned up
+ * later on) to be saved on static_command_line and parsed for
+ * parameters.
+ *
+ * That string may get tweaked during parameter parsing so we
+ * also want to keep an untouched version of the command line
+ * to display on dmesg, /proc/cmdline etc.
+ *
+ * At this point boot_command_line is a temporary buffer
+ * (also on the init section) that contains the command line
+ * string passed from the boot loader. After we return,
+ * it will be saved to saved_command_line that holds the
+ * untouched version of the command line.
+ *
+ * Since we won't be doing any parameter parsing here, we'll
+ * hold the initial/untouched command line string on
+ * boot_command_line and make cmdline_p point to it as well.
+ * This way boot_command_line will be copied to both
+ * saved_command_line and static_command_line.
+ */
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_FORCE
+ /* Built-in args override boot loader args and
+ * boot loader args are being ignored.
+ */
+ strlcpy(boot_command_line, fixed_cmdline, COMMAND_LINE_SIZE);
+#else
+ /* Boot loader args override built-in args so we
+ * need to put built-in args before boot loader args.
+ */
+ if (builtin_cmdline[0]) {
+ 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_p = boot_command_line;
parse_early_param();
--
2.16.4
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2018-10-02 14:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-02 14:04 Nick Kossifidis [this message]
2018-10-02 14:04 ` [PATCH] RISC-V: Implement built-in command line feature Nick Kossifidis
2018-10-02 14:34 ` Christoph Hellwig
2018-10-02 14:34 ` Christoph Hellwig
2018-10-02 15:21 ` Nick Kossifidis
2018-10-02 15:21 ` Nick Kossifidis
2018-10-02 14:56 ` Palmer Dabbelt
2018-10-02 14:56 ` Palmer Dabbelt
2018-10-02 16:43 ` Nick Kossifidis
2018-10-02 16:43 ` Nick Kossifidis
2018-10-02 16:56 ` Palmer Dabbelt
2018-10-02 16:56 ` Palmer Dabbelt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181002140449.24147-1-mick@ics.forth.gr \
--to=mick@ics.forth.gr \
--cc=linux-riscv@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox