* [RFC] Boot command line support
@ 2011-01-26 16:43 Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 1/3] string: add skip_spaces support Jean-Christophe PLAGNIOL-VILLARD
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-26 16:43 UTC (permalink / raw)
To: barebox
HI,
as barebox is some times a second stage bootloader
it could be intresting to pass some information
I'm currently working on two support
the atags for arm and the cmdline
The cmline could be static or dynamic
so it will be easy to customise a boot sequence and etc...
this first patch will just add static cmdline
later I'll send dynamic support and arm boot ABI
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3] string: add skip_spaces support
2011-01-26 16:43 [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-01-26 16:46 ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 2/3] add command line boot support Jean-Christophe PLAGNIOL-VILLARD
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-26 16:46 UTC (permalink / raw)
To: barebox
need by parse_args for the command line parsing
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
include/linux/string.h | 1 +
lib/string.c | 14 ++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 62d743e..b4b48fb 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -59,6 +59,7 @@ extern char * _strchr(const char *,int);
#ifndef __HAVE_ARCH_STRRCHR
extern char * _strrchr(const char *,int);
#endif
+extern char * skip_spaces(const char *);
#ifndef __HAVE_ARCH_STRSTR
extern char * _strstr(const char *,const char *);
#endif
diff --git a/lib/string.c b/lib/string.c
index 77435aa..5ffb861 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -214,6 +214,20 @@ char * _strrchr(const char * s, int c)
#endif
EXPORT_SYMBOL(_strrchr);
+/**
+ * skip_spaces - Removes leading whitespace from @str.
+ * @str: The string to be stripped.
+ *
+ * Returns a pointer to the first non-whitespace character in @str.
+ */
+char *skip_spaces(const char *str)
+{
+ while (isspace(*str))
+ ++str;
+ return (char *)str;
+}
+EXPORT_SYMBOL(skip_spaces);
+
#ifndef __HAVE_ARCH_STRLEN
/**
* strlen - Find the length of a string
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] add command line boot support
2011-01-26 16:43 [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 1/3] string: add skip_spaces support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-01-26 16:46 ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-27 9:20 ` Sascha Hauer
2011-01-26 16:46 ` [PATCH 3/3] __setup test Jean-Christophe PLAGNIOL-VILLARD
2014-02-07 11:04 ` [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
3 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-26 16:46 UTC (permalink / raw)
To: barebox
for now just support static boot command support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
arch/arm/lib/barebox.lds.S | 4 +
arch/blackfin/boards/ipe337/barebox.lds.S | 4 +
arch/ppc/boards/pcm030/barebox.lds.S | 4 +
arch/sandbox/board/barebox.lds.S | 4 +
arch/sandbox/lib/barebox.lds.S | 4 +
arch/x86/lib/barebox.lds.S | 9 ++-
common/Kconfig | 11 ++
common/Makefile | 1 +
common/params.c | 158 +++++++++++++++++++++++++++++
common/startup.c | 74 +++++++++++++-
include/asm-generic/barebox.lds.h | 2 +
include/init.h | 28 +++++
12 files changed, 301 insertions(+), 2 deletions(-)
create mode 100644 common/params.c
diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
index cc74b2f..72d1306 100644
--- a/arch/arm/lib/barebox.lds.S
+++ b/arch/arm/lib/barebox.lds.S
@@ -64,6 +64,10 @@ SECTIONS
.barebox_cmd : { BAREBOX_CMDS }
__barebox_cmd_end = .;
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+
__barebox_initcalls_start = .;
.barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
diff --git a/arch/blackfin/boards/ipe337/barebox.lds.S b/arch/blackfin/boards/ipe337/barebox.lds.S
index 571eeb1..f2787e8 100644
--- a/arch/blackfin/boards/ipe337/barebox.lds.S
+++ b/arch/blackfin/boards/ipe337/barebox.lds.S
@@ -75,6 +75,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS }
___barebox_initcalls_end = .;
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+
___usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
___usymtab_end = .;
diff --git a/arch/ppc/boards/pcm030/barebox.lds.S b/arch/ppc/boards/pcm030/barebox.lds.S
index 21bf4a7..4adf9fb 100644
--- a/arch/ppc/boards/pcm030/barebox.lds.S
+++ b/arch/ppc/boards/pcm030/barebox.lds.S
@@ -107,6 +107,10 @@ SECTIONS
__barebox_initcalls_end = .;
__initcall_entries = (__barebox_initcalls_end - __barebox_initcalls_start) >> 2;
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+
__usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 53e9f60..7dae3e9 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -75,6 +75,10 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
. = ALIGN(64);
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+ . = ALIGN(64);
__barebox_cmd_start = .;
__barebox_cmd : { BAREBOX_CMDS }
__barebox_cmd_end = .;
diff --git a/arch/sandbox/lib/barebox.lds.S b/arch/sandbox/lib/barebox.lds.S
index 53e9f60..7dae3e9 100644
--- a/arch/sandbox/lib/barebox.lds.S
+++ b/arch/sandbox/lib/barebox.lds.S
@@ -75,6 +75,10 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
. = ALIGN(64);
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+ . = ALIGN(64);
__barebox_cmd_start = .;
__barebox_cmd : { BAREBOX_CMDS }
__barebox_cmd_end = .;
diff --git a/arch/x86/lib/barebox.lds.S b/arch/x86/lib/barebox.lds.S
index e0919a6..1b275ad 100644
--- a/arch/x86/lib/barebox.lds.S
+++ b/arch/x86/lib/barebox.lds.S
@@ -177,7 +177,14 @@ SECTIONS
. = ALIGN(4);
} > barebox
- .__usymtab : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
+ .initsetup : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
+ __setup_start = .;
+ INIT_SETUP
+ __setup_end = .;
+ . = ALIGN(4);
+ } > barebox
+
+ .__usymtab : AT ( LOADADDR(.initsetup) + SIZEOF (.initsetup) ) {
__usymtab_start = .;
BAREBOX_SYMS
__usymtab_end = .;
diff --git a/common/Kconfig b/common/Kconfig
index 02bc67e..53a4230 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -224,8 +224,19 @@ choice
bool "Simple parser"
help
simple shell. No if/then, no return values from commands, no loops
+
endchoice
+config BOOT_CMDLINE
+ bool "barebox boot command string"
+ help
+
+config CMDLINE
+ string "Default barebox command string"
+ depends on BOOT_CMDLINE
+ default ""
+ help
+
config GLOB
bool
prompt "hush globbing support"
diff --git a/common/Makefile b/common/Makefile
index 98c9d36..94816d5 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_DIGEST) += digest.o
obj-y += env.o
obj-$(CONFIG_CMD_BOOTM) += image.o
obj-y += startup.o
+obj-$(CONFIG_BOOT_CMDLINE) += params.o
obj-y += misc.o
obj-y += memsize.o
obj-$(CONFIG_MENU) += menu.o
diff --git a/common/params.c b/common/params.c
new file mode 100644
index 0000000..ea35401
--- /dev/null
+++ b/common/params.c
@@ -0,0 +1,158 @@
+/* Helpers for initial module or kernel cmdline parsing
+ Copyright (C) 2001 Rusty Russell.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include <malloc.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <errno.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt, a...)
+#endif
+
+/* This just allows us to keep track of which parameters are kmalloced. */
+struct kmalloced_param {
+ struct list_head list;
+ char val[];
+};
+static LIST_HEAD(kmalloced_params);
+
+static inline char dash2underscore(char c)
+{
+ if (c == '-')
+ return '_';
+ return c;
+}
+
+static inline int parameq(const char *input, const char *paramname)
+{
+ unsigned int i;
+ for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
+ if (input[i] == '\0')
+ return 1;
+ return 0;
+}
+
+static int parse_one(char *param,
+ char *val,
+ int (*handle_unknown)(char *param, char *val))
+{
+ if (handle_unknown) {
+ DEBUGP("Unknown argument: calling %p\n", handle_unknown);
+ return handle_unknown(param, val);
+ }
+
+ DEBUGP("Unknown argument `%s'\n", param);
+ return -ENOENT;
+}
+
+/* You can use " around spaces, but can't escape ". */
+/* Hyphens and underscores equivalent in parameter names. */
+static char *next_arg(char *args, char **param, char **val)
+{
+ unsigned int i, equals = 0;
+ int in_quote = 0, quoted = 0;
+ char *next;
+
+ if (*args == '"') {
+ args++;
+ in_quote = 1;
+ quoted = 1;
+ }
+
+ for (i = 0; args[i]; i++) {
+ if (isspace(args[i]) && !in_quote)
+ break;
+ if (equals == 0) {
+ if (args[i] == '=')
+ equals = i;
+ }
+ if (args[i] == '"')
+ in_quote = !in_quote;
+ }
+
+ *param = args;
+ if (!equals)
+ *val = NULL;
+ else {
+ args[equals] = '\0';
+ *val = args + equals + 1;
+
+ /* Don't include quotes in value. */
+ if (**val == '"') {
+ (*val)++;
+ if (args[i-1] == '"')
+ args[i-1] = '\0';
+ }
+ if (quoted && args[i-1] == '"')
+ args[i-1] = '\0';
+ }
+
+ if (args[i]) {
+ args[i] = '\0';
+ next = args + i + 1;
+ } else
+ next = args + i;
+
+ /* Chew up trailing spaces. */
+ return skip_spaces(next);
+}
+
+/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
+int parse_args(const char *name,
+ char *args,
+ int (*unknown)(char *param, char *val))
+{
+ char *param, *val;
+
+ DEBUGP("Parsing ARGS: %s\n", args);
+
+ /* Chew leading spaces */
+ args = skip_spaces(args);
+
+ while (*args) {
+ int ret;
+
+ args = next_arg(args, ¶m, &val);
+ ret = parse_one(param, val, unknown);
+ switch (ret) {
+ case -ENOENT:
+ printk(KERN_ERR "%s: Unknown parameter `%s'\n",
+ name, param);
+ return ret;
+ case -ENOSPC:
+ printk(KERN_ERR
+ "%s: `%s' too large for parameter `%s'\n",
+ name, val ?: "", param);
+ return ret;
+ case 0:
+ break;
+ default:
+ printk(KERN_ERR
+ "%s: `%s' invalid for parameter `%s'\n",
+ name, val ?: "", param);
+ return ret;
+ }
+ }
+
+ /* All parsed OK. */
+ return 0;
+}
diff --git a/common/startup.c b/common/startup.c
index aa76cb7..98b4aab 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -41,6 +41,7 @@
#include <reloc.h>
#include <asm-generic/memory_layout.h>
#include <asm/sections.h>
+#include <asm/setup.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
@@ -103,6 +104,15 @@ static int register_default_env(void)
device_initcall(register_default_env);
#endif
+#ifdef CONFIG_BOOT_CMDLINE
+static int __init bootmode(char *mode)
+{
+ printf("boot=%s\n", mode);
+ return 0;
+}
+__setup("boot=", bootmode);
+#endif
+
static int mount_root(void)
{
mount("none", "ramfs", "/");
@@ -112,6 +122,67 @@ static int mount_root(void)
}
fs_initcall(mount_root);
+#ifdef CONFIG_BOOT_CMDLINE
+extern const struct obs_kernel_param __setup_start[], __setup_end[];
+
+static int __init obsolete_checksetup(char *line)
+{
+ const struct obs_kernel_param *p;
+
+ p = __setup_start;
+ do {
+ int n = strlen(p->str);
+ if (!strncmp(line, p->str, n)) {
+ if (!p->setup_func) {
+ printk(KERN_WARNING "Parameter %s is obsolete,"
+ " ignored\n", p->str);
+ return 1;
+ } else if (p->setup_func(line + n))
+ return 1;
+ }
+ p++;
+ } while (p < __setup_end);
+
+ return 0;
+}
+
+/*
+ * Unknown boot options get handed to init, unless they look like
+ * unused parameters (modprobe will find them in /proc/cmdline).
+ */
+static int __init unknown_bootoption(char *param, char *val)
+{
+ /* Change NUL term back to "=", to make "param" the whole string. */
+ if (val) {
+ /* param=val or param="val"? */
+ if (val == param+strlen(param)+1)
+ val[-1] = '=';
+ else if (val == param+strlen(param)+2) {
+ val[-2] = '=';
+ memmove(val-1, val, strlen(val)+1);
+ val--;
+ } else
+ BUG();
+ }
+
+ /* Handle obsolete-style parameters */
+ obsolete_checksetup(param);
+ return 0;
+}
+
+void __init parse_param(void)
+{
+ static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
+
+ strlcpy(tmp_cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+ parse_args("Booting Barebox", tmp_cmdline, unknown_bootoption);
+}
+#else
+static void inline parse_param(void)
+{
+}
+#endif
+
void start_barebox (void)
{
initcall_t *initcall;
@@ -128,6 +199,8 @@ void start_barebox (void)
init_data_ptr = &__early_init_data_begin;
#endif /* CONFIG_HAS_EARLY_INIT */
+ parse_param();
+
for (initcall = __barebox_initcalls_start;
initcall < __barebox_initcalls_end; initcall++) {
PUTHEX_LL(*initcall);
@@ -180,4 +253,3 @@ void shutdown_barebox(void)
arch_shutdown();
#endif
}
-
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index fc141a4..18eab31 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -7,6 +7,8 @@
#define PRE_IMAGE
#endif
+#define INIT_SETUP KEEP(*(.init_setup))
+
#define INITCALLS \
KEEP(*(.initcall.0)) \
KEEP(*(.initcall.1)) \
diff --git a/include/init.h b/include/init.h
index 2f4fac1..53148fa 100644
--- a/include/init.h
+++ b/include/init.h
@@ -44,6 +44,34 @@ typedef int (*initcall_t)(void);
*/
#define __bare_init __section(.text_bare_init.text)
+#define __initconst __section(.rodata)
+
+struct obs_kernel_param {
+ const char *str;
+ int (*setup_func)(char *);
+};
+
+/*
+ * Only for really core code. See moduleparam.h for the normal way.
+ *
+ * Force the alignment so the compiler doesn't space elements of the
+ * obs_kernel_param "array" too far apart in .init.setup.
+ */
+#define __setup_param(str, unique_id, fn) \
+ static const char __setup_str_##unique_id[] __initconst \
+ __aligned(1) = str; \
+ static struct obs_kernel_param __setup_##unique_id \
+ __used __section(.init_setup) \
+ __attribute__((aligned((sizeof(long))))) \
+ = { __setup_str_##unique_id, fn}
+
+#define __setup(str, fn) \
+ __setup_param(str, fn, fn)
+
+/* Called on module insert or kernel boot */
+extern int parse_args(const char *name,
+ char *args,
+ int (*unknown)(char *param, char *val));
#endif
#endif /* _INIT_H */
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/3] __setup test
2011-01-26 16:43 [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 1/3] string: add skip_spaces support Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 2/3] add command line boot support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-01-26 16:46 ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-07 11:04 ` [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
3 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-26 16:46 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
common/startup.c | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/common/startup.c b/common/startup.c
index 98b4aab..1891cbd 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -105,12 +105,20 @@ device_initcall(register_default_env);
#endif
#ifdef CONFIG_BOOT_CMDLINE
-static int __init bootmode(char *mode)
+static __initdata char bootmode[COMMAND_LINE_SIZE];
+
+static int __init setup_bootmode(char *mode)
+{
+ strcpy(bootmode, mode);
+ return 0;
+}
+__setup("boot=", setup_bootmode);
+static int bootmode_print(void)
{
- printf("boot=%s\n", mode);
+ printf("boot=%s\n", bootmode);
return 0;
}
-__setup("boot=", bootmode);
+device_initcall(bootmode_print);
#endif
static int mount_root(void)
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] add command line boot support
2011-01-26 16:46 ` [PATCH 2/3] add command line boot support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-01-27 9:20 ` Sascha Hauer
2011-01-27 11:55 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2011-01-27 9:20 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
Hi J,
On Wed, Jan 26, 2011 at 05:46:03PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> for now just support static boot command support
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> arch/arm/lib/barebox.lds.S | 4 +
> arch/blackfin/boards/ipe337/barebox.lds.S | 4 +
> arch/ppc/boards/pcm030/barebox.lds.S | 4 +
> arch/sandbox/board/barebox.lds.S | 4 +
> arch/sandbox/lib/barebox.lds.S | 4 +
> arch/x86/lib/barebox.lds.S | 9 ++-
> common/Kconfig | 11 ++
> common/Makefile | 1 +
> common/params.c | 158 +++++++++++++++++++++++++++++
> common/startup.c | 74 +++++++++++++-
> include/asm-generic/barebox.lds.h | 2 +
> include/init.h | 28 +++++
> 12 files changed, 301 insertions(+), 2 deletions(-)
> create mode 100644 common/params.c
Except for the inlined comments I'm generally ok with this patch.
The more interesting part will be how the calling convention for
barebox as a second stage loader is and how you preserve the
registers used for commandline/atag passing during startup.
An idea which comes to my mind is that we could introduce a
CONFIG_BAREBOX_SECOND_STAGE which switches to a completely different
startup process. This startup process could then assume that
sdram is already initialized and that we do not have to call
board_init_lowlevel.
Another interesting thing is how will barebox behave if called
as a second stage loader but without valid atags?
>
>
> +config BOOT_CMDLINE
> + bool "barebox boot command string"
> + help
This is useful if you intend to use barebox as a second stage bootloader
and want to pass kernel like command line parameters to barebox. Otherwise
say no here.
> +
> +config CMDLINE
> + string "Default barebox command string"
> + depends on BOOT_CMDLINE
> + default ""
> + help
> +
> config GLOB
> bool
> prompt "hush globbing support"
> diff --git a/common/Makefile b/common/Makefile
> index 98c9d36..94816d5 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_DIGEST) += digest.o
> obj-y += env.o
> obj-$(CONFIG_CMD_BOOTM) += image.o
> obj-y += startup.o
> +obj-$(CONFIG_BOOT_CMDLINE) += params.o
> obj-y += misc.o
> obj-y += memsize.o
> obj-$(CONFIG_MENU) += menu.o
> diff --git a/common/params.c b/common/params.c
> new file mode 100644
> index 0000000..ea35401
> --- /dev/null
> +++ b/common/params.c
> @@ -0,0 +1,158 @@
> +/* Helpers for initial module or kernel cmdline parsing
> + Copyright (C) 2001 Rusty Russell.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 2 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> +*/
> +#include <malloc.h>
> +#include <linux/kernel.h>
> +#include <linux/string.h>
> +#include <errno.h>
> +#include <linux/err.h>
> +#include <linux/ctype.h>
> +
> +#if 0
> +#define DEBUGP printk
> +#else
> +#define DEBUGP(fmt, a...)
> +#endif
Please use the regular 'debug' function here.
> +
> +/* This just allows us to keep track of which parameters are kmalloced. */
> +struct kmalloced_param {
> + struct list_head list;
> + char val[];
> +};
> +static LIST_HEAD(kmalloced_params);
This seems unused.
> +
> +static inline char dash2underscore(char c)
> +{
> + if (c == '-')
> + return '_';
> + return c;
> +}
> +
> +static inline int parameq(const char *input, const char *paramname)
> +{
> + unsigned int i;
> + for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
> + if (input[i] == '\0')
> + return 1;
> + return 0;
> +}
> +
> +static int parse_one(char *param,
> + char *val,
> + int (*handle_unknown)(char *param, char *val))
> +{
> + if (handle_unknown) {
> + DEBUGP("Unknown argument: calling %p\n", handle_unknown);
> + return handle_unknown(param, val);
> + }
> +
> + DEBUGP("Unknown argument `%s'\n", param);
> + return -ENOENT;
> +}
> +
> +/* You can use " around spaces, but can't escape ". */
> +/* Hyphens and underscores equivalent in parameter names. */
> +static char *next_arg(char *args, char **param, char **val)
> +{
> + unsigned int i, equals = 0;
> + int in_quote = 0, quoted = 0;
> + char *next;
> +
> + if (*args == '"') {
> + args++;
> + in_quote = 1;
> + quoted = 1;
> + }
> +
> + for (i = 0; args[i]; i++) {
> + if (isspace(args[i]) && !in_quote)
> + break;
> + if (equals == 0) {
> + if (args[i] == '=')
> + equals = i;
> + }
> + if (args[i] == '"')
> + in_quote = !in_quote;
> + }
> +
> + *param = args;
> + if (!equals)
> + *val = NULL;
> + else {
> + args[equals] = '\0';
> + *val = args + equals + 1;
> +
> + /* Don't include quotes in value. */
> + if (**val == '"') {
> + (*val)++;
> + if (args[i-1] == '"')
> + args[i-1] = '\0';
> + }
> + if (quoted && args[i-1] == '"')
> + args[i-1] = '\0';
> + }
> +
> + if (args[i]) {
> + args[i] = '\0';
> + next = args + i + 1;
> + } else
> + next = args + i;
> +
> + /* Chew up trailing spaces. */
> + return skip_spaces(next);
> +}
> +
> +/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
> +int parse_args(const char *name,
> + char *args,
> + int (*unknown)(char *param, char *val))
> +{
> + char *param, *val;
> +
> + DEBUGP("Parsing ARGS: %s\n", args);
> +
> + /* Chew leading spaces */
> + args = skip_spaces(args);
> +
> + while (*args) {
> + int ret;
> +
> + args = next_arg(args, ¶m, &val);
> + ret = parse_one(param, val, unknown);
> + switch (ret) {
> + case -ENOENT:
> + printk(KERN_ERR "%s: Unknown parameter `%s'\n",
> + name, param);
> + return ret;
> + case -ENOSPC:
> + printk(KERN_ERR
> + "%s: `%s' too large for parameter `%s'\n",
> + name, val ?: "", param);
> + return ret;
> + case 0:
> + break;
> + default:
> + printk(KERN_ERR
> + "%s: `%s' invalid for parameter `%s'\n",
> + name, val ?: "", param);
> + return ret;
> + }
> + }
> +
> + /* All parsed OK. */
> + return 0;
> +}
> diff --git a/common/startup.c b/common/startup.c
> index aa76cb7..98b4aab 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -41,6 +41,7 @@
> #include <reloc.h>
> #include <asm-generic/memory_layout.h>
> #include <asm/sections.h>
> +#include <asm/setup.h>
>
> extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
> __barebox_initcalls_end[];
> @@ -103,6 +104,15 @@ static int register_default_env(void)
> device_initcall(register_default_env);
> #endif
>
> +#ifdef CONFIG_BOOT_CMDLINE
> +static int __init bootmode(char *mode)
> +{
> + printf("boot=%s\n", mode);
> + return 0;
> +}
> +__setup("boot=", bootmode);
> +#endif
> +
> static int mount_root(void)
> {
> mount("none", "ramfs", "/");
> @@ -112,6 +122,67 @@ static int mount_root(void)
> }
> fs_initcall(mount_root);
>
> +#ifdef CONFIG_BOOT_CMDLINE
> +extern const struct obs_kernel_param __setup_start[], __setup_end[];
> +
> +static int __init obsolete_checksetup(char *line)
> +{
> + const struct obs_kernel_param *p;
> +
> + p = __setup_start;
> + do {
> + int n = strlen(p->str);
> + if (!strncmp(line, p->str, n)) {
> + if (!p->setup_func) {
> + printk(KERN_WARNING "Parameter %s is obsolete,"
> + " ignored\n", p->str);
> + return 1;
> + } else if (p->setup_func(line + n))
> + return 1;
> + }
> + p++;
> + } while (p < __setup_end);
> +
> + return 0;
> +}
> +
> +/*
> + * Unknown boot options get handed to init, unless they look like
> + * unused parameters (modprobe will find them in /proc/cmdline).
> + */
> +static int __init unknown_bootoption(char *param, char *val)
> +{
> + /* Change NUL term back to "=", to make "param" the whole string. */
> + if (val) {
> + /* param=val or param="val"? */
> + if (val == param+strlen(param)+1)
> + val[-1] = '=';
> + else if (val == param+strlen(param)+2) {
> + val[-2] = '=';
> + memmove(val-1, val, strlen(val)+1);
> + val--;
> + } else
> + BUG();
> + }
> +
> + /* Handle obsolete-style parameters */
> + obsolete_checksetup(param);
> + return 0;
> +}
> +
> +void __init parse_param(void)
> +{
> + static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
> +
> + strlcpy(tmp_cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> + parse_args("Booting Barebox", tmp_cmdline, unknown_bootoption);
> +}
> +#else
> +static void inline parse_param(void)
> +{
> +}
> +#endif
> +
> void start_barebox (void)
> {
> initcall_t *initcall;
> @@ -128,6 +199,8 @@ void start_barebox (void)
> init_data_ptr = &__early_init_data_begin;
> #endif /* CONFIG_HAS_EARLY_INIT */
>
> + parse_param();
> +
> for (initcall = __barebox_initcalls_start;
> initcall < __barebox_initcalls_end; initcall++) {
> PUTHEX_LL(*initcall);
> @@ -180,4 +253,3 @@ void shutdown_barebox(void)
> arch_shutdown();
> #endif
> }
> -
> diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
> index fc141a4..18eab31 100644
> --- a/include/asm-generic/barebox.lds.h
> +++ b/include/asm-generic/barebox.lds.h
> @@ -7,6 +7,8 @@
> #define PRE_IMAGE
> #endif
>
> +#define INIT_SETUP KEEP(*(.init_setup))
> +
> #define INITCALLS \
> KEEP(*(.initcall.0)) \
> KEEP(*(.initcall.1)) \
> diff --git a/include/init.h b/include/init.h
> index 2f4fac1..53148fa 100644
> --- a/include/init.h
> +++ b/include/init.h
> @@ -44,6 +44,34 @@ typedef int (*initcall_t)(void);
> */
> #define __bare_init __section(.text_bare_init.text)
>
> +#define __initconst __section(.rodata)
> +
> +struct obs_kernel_param {
> + const char *str;
> + int (*setup_func)(char *);
> +};
> +
> +/*
> + * Only for really core code. See moduleparam.h for the normal way.
> + *
> + * Force the alignment so the compiler doesn't space elements of the
> + * obs_kernel_param "array" too far apart in .init.setup.
> + */
> +#define __setup_param(str, unique_id, fn) \
> + static const char __setup_str_##unique_id[] __initconst \
> + __aligned(1) = str; \
> + static struct obs_kernel_param __setup_##unique_id \
> + __used __section(.init_setup) \
> + __attribute__((aligned((sizeof(long))))) \
> + = { __setup_str_##unique_id, fn}
> +
> +#define __setup(str, fn) \
> + __setup_param(str, fn, fn)
> +
> +/* Called on module insert or kernel boot */
> +extern int parse_args(const char *name,
> + char *args,
> + int (*unknown)(char *param, char *val));
> #endif
>
> #endif /* _INIT_H */
> --
> 1.7.2.3
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] add command line boot support
2011-01-27 9:20 ` Sascha Hauer
@ 2011-01-27 11:55 ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-27 13:10 ` Sascha Hauer
0 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-27 11:55 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hi Sascha,
On 10:20 Thu 27 Jan , Sascha Hauer wrote:
> Hi J,
>
> On Wed, Jan 26, 2011 at 05:46:03PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > for now just support static boot command support
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > arch/arm/lib/barebox.lds.S | 4 +
> > arch/blackfin/boards/ipe337/barebox.lds.S | 4 +
> > arch/ppc/boards/pcm030/barebox.lds.S | 4 +
> > arch/sandbox/board/barebox.lds.S | 4 +
> > arch/sandbox/lib/barebox.lds.S | 4 +
> > arch/x86/lib/barebox.lds.S | 9 ++-
> > common/Kconfig | 11 ++
> > common/Makefile | 1 +
> > common/params.c | 158 +++++++++++++++++++++++++++++
> > common/startup.c | 74 +++++++++++++-
> > include/asm-generic/barebox.lds.h | 2 +
> > include/init.h | 28 +++++
> > 12 files changed, 301 insertions(+), 2 deletions(-)
> > create mode 100644 common/params.c
>
> Except for the inlined comments I'm generally ok with this patch.
> The more interesting part will be how the calling convention for
> barebox as a second stage loader is and how you preserve the
> registers used for commandline/atag passing during startup.
I take a look and no need to do something special we just have to put the data
in the .data section as we will supposed to be call from memmory directly
evenif we may ned to relocate our self
>
> An idea which comes to my mind is that we could introduce a
> CONFIG_BAREBOX_SECOND_STAGE which switches to a completely different
> startup process. This startup process could then assume that
> sdram is already initialized and that we do not have to call
> board_init_lowlevel.
I get in mind to keep it maybe as we can run the lowlevel init from cache as a
peekpoke table to reconfigure the board if needed
> Another interesting thing is how will barebox behave if called
> as a second stage loader but without valid atags?
I think to use in this case the default config and let the boards to get a
callback to overwrite it
I'll try to push patch soon to show the solution
I get in mind to maybe use the device tree also not sure yet
>
> >
> >
> > +config BOOT_CMDLINE
> > + bool "barebox boot command string"
> > + help
>
> This is useful if you intend to use barebox as a second stage bootloader
> and want to pass kernel like command line parameters to barebox. Otherwise
> say no here.
as you can have built_in cmdline you can use it also as a first stage
>
> > +
> > +config CMDLINE
> > + string "Default barebox command string"
> > + depends on BOOT_CMDLINE
> > + default ""
> > + help
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program; if not, write to the Free Software
> > + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> > +*/
> > +#include <malloc.h>
> > +#include <linux/kernel.h>
> > +#include <linux/string.h>
> > +#include <errno.h>
> > +#include <linux/err.h>
> > +#include <linux/ctype.h>
> > +
> > +#if 0
> > +#define DEBUGP printk
> > +#else
> > +#define DEBUGP(fmt, a...)
> > +#endif
>
> Please use the regular 'debug' function here.
ok
>
> > +
> > +/* This just allows us to keep track of which parameters are kmalloced. */
> > +struct kmalloced_param {
> > + struct list_head list;
> > + char val[];
> > +};
> > +static LIST_HEAD(kmalloced_params);
>
> This seems unused.
yeah forget to remove it
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] add command line boot support
2011-01-27 11:55 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-01-27 13:10 ` Sascha Hauer
2011-01-27 13:15 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2011-01-27 13:10 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Thu, Jan 27, 2011 at 12:55:31PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi Sascha,
>
> On 10:20 Thu 27 Jan , Sascha Hauer wrote:
> > Hi J,
> >
> > On Wed, Jan 26, 2011 at 05:46:03PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > for now just support static boot command support
> > >
> > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > > ---
> > > arch/arm/lib/barebox.lds.S | 4 +
> > > arch/blackfin/boards/ipe337/barebox.lds.S | 4 +
> > > arch/ppc/boards/pcm030/barebox.lds.S | 4 +
> > > arch/sandbox/board/barebox.lds.S | 4 +
> > > arch/sandbox/lib/barebox.lds.S | 4 +
> > > arch/x86/lib/barebox.lds.S | 9 ++-
> > > common/Kconfig | 11 ++
> > > common/Makefile | 1 +
> > > common/params.c | 158 +++++++++++++++++++++++++++++
> > > common/startup.c | 74 +++++++++++++-
> > > include/asm-generic/barebox.lds.h | 2 +
> > > include/init.h | 28 +++++
> > > 12 files changed, 301 insertions(+), 2 deletions(-)
> > > create mode 100644 common/params.c
> >
> > Except for the inlined comments I'm generally ok with this patch.
> > The more interesting part will be how the calling convention for
> > barebox as a second stage loader is and how you preserve the
> > registers used for commandline/atag passing during startup.
> I take a look and no need to do something special we just have to put the data
> in the .data section as we will supposed to be call from memmory directly
> evenif we may ned to relocate our self
Nothing special? Then how does barebox know where to find the command
line?
> >
> > An idea which comes to my mind is that we could introduce a
> > CONFIG_BAREBOX_SECOND_STAGE which switches to a completely different
> > startup process. This startup process could then assume that
> > sdram is already initialized and that we do not have to call
> > board_init_lowlevel.
> I get in mind to keep it maybe as we can run the lowlevel init from cache as a
> peekpoke table to reconfigure the board if needed
> > Another interesting thing is how will barebox behave if called
> > as a second stage loader but without valid atags?
> I think to use in this case the default config and let the boards to get a
> callback to overwrite it
> I'll try to push patch soon to show the solution
> I get in mind to maybe use the device tree also not sure yet
> >
> > >
> > >
> > > +config BOOT_CMDLINE
> > > + bool "barebox boot command string"
> > > + help
> >
> > This is useful if you intend to use barebox as a second stage bootloader
> > and want to pass kernel like command line parameters to barebox. Otherwise
> > say no here.
> as you can have built_in cmdline you can use it also as a first stage
Yes, but this really serves no purpose, does it?
> >
> > > +
> > > +config CMDLINE
> > > + string "Default barebox command string"
> > > + depends on BOOT_CMDLINE
> > > + default ""
> > > + help
> > > +
> > > + This program is distributed in the hope that it will be useful,
> > > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > > + GNU General Public License for more details.
> > > +
> > > + You should have received a copy of the GNU General Public License
> > > + along with this program; if not, write to the Free Software
> > > + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> > > +*/
> > > +#include <malloc.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/string.h>
> > > +#include <errno.h>
> > > +#include <linux/err.h>
> > > +#include <linux/ctype.h>
> > > +
> > > +#if 0
> > > +#define DEBUGP printk
> > > +#else
> > > +#define DEBUGP(fmt, a...)
> > > +#endif
> >
> > Please use the regular 'debug' function here.
> ok
> >
> > > +
> > > +/* This just allows us to keep track of which parameters are kmalloced. */
> > > +struct kmalloced_param {
> > > + struct list_head list;
> > > + char val[];
> > > +};
> > > +static LIST_HEAD(kmalloced_params);
> >
> > This seems unused.
> yeah forget to remove it
>
> Best Regards,
> J.
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] add command line boot support
2011-01-27 13:10 ` Sascha Hauer
@ 2011-01-27 13:15 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-27 13:15 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 14:10 Thu 27 Jan , Sascha Hauer wrote:
> On Thu, Jan 27, 2011 at 12:55:31PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Hi Sascha,
> >
> > On 10:20 Thu 27 Jan , Sascha Hauer wrote:
> > > Hi J,
> > >
> > > On Wed, Jan 26, 2011 at 05:46:03PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > for now just support static boot command support
> > > >
> > > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > > > ---
> > > > arch/arm/lib/barebox.lds.S | 4 +
> > > > arch/blackfin/boards/ipe337/barebox.lds.S | 4 +
> > > > arch/ppc/boards/pcm030/barebox.lds.S | 4 +
> > > > arch/sandbox/board/barebox.lds.S | 4 +
> > > > arch/sandbox/lib/barebox.lds.S | 4 +
> > > > arch/x86/lib/barebox.lds.S | 9 ++-
> > > > common/Kconfig | 11 ++
> > > > common/Makefile | 1 +
> > > > common/params.c | 158 +++++++++++++++++++++++++++++
> > > > common/startup.c | 74 +++++++++++++-
> > > > include/asm-generic/barebox.lds.h | 2 +
> > > > include/init.h | 28 +++++
> > > > 12 files changed, 301 insertions(+), 2 deletions(-)
> > > > create mode 100644 common/params.c
> > >
> > > Except for the inlined comments I'm generally ok with this patch.
> > > The more interesting part will be how the calling convention for
> > > barebox as a second stage loader is and how you preserve the
> > > registers used for commandline/atag passing during startup.
> > I take a look and no need to do something special we just have to put the data
> > in the .data section as we will supposed to be call from memmory directly
> > evenif we may ned to relocate our self
>
> Nothing special? Then how does barebox know where to find the command
> line?
yeah I agree I'll send a patch i'll be more clear
>
> > >
> > > An idea which comes to my mind is that we could introduce a
> > > CONFIG_BAREBOX_SECOND_STAGE which switches to a completely different
> > > startup process. This startup process could then assume that
> > > sdram is already initialized and that we do not have to call
> > > board_init_lowlevel.
> > I get in mind to keep it maybe as we can run the lowlevel init from cache as a
> > peekpoke table to reconfigure the board if needed
> > > Another interesting thing is how will barebox behave if called
> > > as a second stage loader but without valid atags?
> > I think to use in this case the default config and let the boards to get a
> > callback to overwrite it
> > I'll try to push patch soon to show the solution
> > I get in mind to maybe use the device tree also not sure yet
> > >
> > > >
> > > >
> > > > +config BOOT_CMDLINE
> > > > + bool "barebox boot command string"
> > > > + help
> > >
> > > This is useful if you intend to use barebox as a second stage bootloader
> > > and want to pass kernel like command line parameters to barebox. Otherwise
> > > say no here.
> > as you can have built_in cmdline you can use it also as a first stage
>
> Yes, but this really serves no purpose, does it?
yeah it's as you can dynamse the board via the static cmdline
and other part without modifying the code
and you will be able to dynamise the shell as I'm prepaaring a patch to export
them in the shell too
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] Boot command line support
2011-01-26 16:43 [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
` (2 preceding siblings ...)
2011-01-26 16:46 ` [PATCH 3/3] __setup test Jean-Christophe PLAGNIOL-VILLARD
@ 2014-02-07 11:04 ` Jean-Christophe PLAGNIOL-VILLARD
3 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2014-02-07 11:04 UTC (permalink / raw)
To: barebox; +Cc: Uwe Kleine-K??nig
Hi,
I was talking of this patch serie
Best Regards,
J.
On 17:43 Wed 26 Jan , Jean-Christophe PLAGNIOL-VILLARD wrote:
> HI,
>
> as barebox is some times a second stage bootloader
> it could be intresting to pass some information
>
> I'm currently working on two support
> the atags for arm and the cmdline
>
> The cmline could be static or dynamic
> so it will be easy to customise a boot sequence and etc...
>
> this first patch will just add static cmdline
>
> later I'll send dynamic support and arm boot ABI
>
> Best Regards,
> J.
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] add command line boot support
2011-01-27 13:02 [PATCH 1/3] string: add skip_spaces support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-01-27 13:02 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-01-27 13:02 UTC (permalink / raw)
To: barebox; +Cc: Patrice Vilchez, Nicolas Ferre
for now just support static boot command support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Patrice Vilchez <patrice.vilchez@atmel.com>
---
arch/arm/lib/barebox.lds.S | 4 +
arch/blackfin/boards/ipe337/barebox.lds.S | 4 +
arch/ppc/boards/pcm030/barebox.lds.S | 4 +
arch/sandbox/board/barebox.lds.S | 4 +
arch/sandbox/lib/barebox.lds.S | 4 +
arch/x86/lib/barebox.lds.S | 9 ++-
common/Kconfig | 11 ++
common/Makefile | 1 +
common/params.c | 145 +++++++++++++++++++++++++++++
common/startup.c | 65 +++++++++++++-
include/asm-generic/barebox.lds.h | 2 +
include/init.h | 28 ++++++
12 files changed, 279 insertions(+), 2 deletions(-)
create mode 100644 common/params.c
diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
index cc74b2f..72d1306 100644
--- a/arch/arm/lib/barebox.lds.S
+++ b/arch/arm/lib/barebox.lds.S
@@ -64,6 +64,10 @@ SECTIONS
.barebox_cmd : { BAREBOX_CMDS }
__barebox_cmd_end = .;
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+
__barebox_initcalls_start = .;
.barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
diff --git a/arch/blackfin/boards/ipe337/barebox.lds.S b/arch/blackfin/boards/ipe337/barebox.lds.S
index 571eeb1..f2787e8 100644
--- a/arch/blackfin/boards/ipe337/barebox.lds.S
+++ b/arch/blackfin/boards/ipe337/barebox.lds.S
@@ -75,6 +75,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS }
___barebox_initcalls_end = .;
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+
___usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
___usymtab_end = .;
diff --git a/arch/ppc/boards/pcm030/barebox.lds.S b/arch/ppc/boards/pcm030/barebox.lds.S
index 21bf4a7..4adf9fb 100644
--- a/arch/ppc/boards/pcm030/barebox.lds.S
+++ b/arch/ppc/boards/pcm030/barebox.lds.S
@@ -107,6 +107,10 @@ SECTIONS
__barebox_initcalls_end = .;
__initcall_entries = (__barebox_initcalls_end - __barebox_initcalls_start) >> 2;
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+
__usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 53e9f60..7dae3e9 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -75,6 +75,10 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
. = ALIGN(64);
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+ . = ALIGN(64);
__barebox_cmd_start = .;
__barebox_cmd : { BAREBOX_CMDS }
__barebox_cmd_end = .;
diff --git a/arch/sandbox/lib/barebox.lds.S b/arch/sandbox/lib/barebox.lds.S
index 53e9f60..7dae3e9 100644
--- a/arch/sandbox/lib/barebox.lds.S
+++ b/arch/sandbox/lib/barebox.lds.S
@@ -75,6 +75,10 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
. = ALIGN(64);
+ __setup_start = .;
+ .initsetup : { INIT_SETUP }
+ __setup_end = .;
+ . = ALIGN(64);
__barebox_cmd_start = .;
__barebox_cmd : { BAREBOX_CMDS }
__barebox_cmd_end = .;
diff --git a/arch/x86/lib/barebox.lds.S b/arch/x86/lib/barebox.lds.S
index e0919a6..1b275ad 100644
--- a/arch/x86/lib/barebox.lds.S
+++ b/arch/x86/lib/barebox.lds.S
@@ -177,7 +177,14 @@ SECTIONS
. = ALIGN(4);
} > barebox
- .__usymtab : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
+ .initsetup : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
+ __setup_start = .;
+ INIT_SETUP
+ __setup_end = .;
+ . = ALIGN(4);
+ } > barebox
+
+ .__usymtab : AT ( LOADADDR(.initsetup) + SIZEOF (.initsetup) ) {
__usymtab_start = .;
BAREBOX_SYMS
__usymtab_end = .;
diff --git a/common/Kconfig b/common/Kconfig
index 02bc67e..53a4230 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -224,8 +224,19 @@ choice
bool "Simple parser"
help
simple shell. No if/then, no return values from commands, no loops
+
endchoice
+config BOOT_CMDLINE
+ bool "barebox boot command string"
+ help
+
+config CMDLINE
+ string "Default barebox command string"
+ depends on BOOT_CMDLINE
+ default ""
+ help
+
config GLOB
bool
prompt "hush globbing support"
diff --git a/common/Makefile b/common/Makefile
index 98c9d36..94816d5 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_DIGEST) += digest.o
obj-y += env.o
obj-$(CONFIG_CMD_BOOTM) += image.o
obj-y += startup.o
+obj-$(CONFIG_BOOT_CMDLINE) += params.o
obj-y += misc.o
obj-y += memsize.o
obj-$(CONFIG_MENU) += menu.o
diff --git a/common/params.c b/common/params.c
new file mode 100644
index 0000000..5541470
--- /dev/null
+++ b/common/params.c
@@ -0,0 +1,145 @@
+/* Helpers for initial module or kernel cmdline parsing
+ Copyright (C) 2001 Rusty Russell.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include <malloc.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <errno.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+
+static inline char dash2underscore(char c)
+{
+ if (c == '-')
+ return '_';
+ return c;
+}
+
+static inline int parameq(const char *input, const char *paramname)
+{
+ unsigned int i;
+ for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
+ if (input[i] == '\0')
+ return 1;
+ return 0;
+}
+
+static int parse_one(char *param,
+ char *val,
+ int (*handle_unknown)(char *param, char *val))
+{
+ if (handle_unknown) {
+ debug("Unknown argument: calling %p\n", handle_unknown);
+ return handle_unknown(param, val);
+ }
+
+ debug("Unknown argument `%s'\n", param);
+ return -ENOENT;
+}
+
+/* You can use " around spaces, but can't escape ". */
+/* Hyphens and underscores equivalent in parameter names. */
+static char *next_arg(char *args, char **param, char **val)
+{
+ unsigned int i, equals = 0;
+ int in_quote = 0, quoted = 0;
+ char *next;
+
+ if (*args == '"') {
+ args++;
+ in_quote = 1;
+ quoted = 1;
+ }
+
+ for (i = 0; args[i]; i++) {
+ if (isspace(args[i]) && !in_quote)
+ break;
+ if (equals == 0) {
+ if (args[i] == '=')
+ equals = i;
+ }
+ if (args[i] == '"')
+ in_quote = !in_quote;
+ }
+
+ *param = args;
+ if (!equals)
+ *val = NULL;
+ else {
+ args[equals] = '\0';
+ *val = args + equals + 1;
+
+ /* Don't include quotes in value. */
+ if (**val == '"') {
+ (*val)++;
+ if (args[i-1] == '"')
+ args[i-1] = '\0';
+ }
+ if (quoted && args[i-1] == '"')
+ args[i-1] = '\0';
+ }
+
+ if (args[i]) {
+ args[i] = '\0';
+ next = args + i + 1;
+ } else
+ next = args + i;
+
+ /* Chew up trailing spaces. */
+ return skip_spaces(next);
+}
+
+/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
+int parse_args(const char *name,
+ char *args,
+ int (*unknown)(char *param, char *val))
+{
+ char *param, *val;
+
+ debug("Parsing ARGS: %s\n", args);
+
+ /* Chew leading spaces */
+ args = skip_spaces(args);
+
+ while (*args) {
+ int ret;
+
+ args = next_arg(args, ¶m, &val);
+ ret = parse_one(param, val, unknown);
+ switch (ret) {
+ case -ENOENT:
+ printk(KERN_ERR "%s: Unknown parameter `%s'\n",
+ name, param);
+ return ret;
+ case -ENOSPC:
+ printk(KERN_ERR
+ "%s: `%s' too large for parameter `%s'\n",
+ name, val ?: "", param);
+ return ret;
+ case 0:
+ break;
+ default:
+ printk(KERN_ERR
+ "%s: `%s' invalid for parameter `%s'\n",
+ name, val ?: "", param);
+ return ret;
+ }
+ }
+
+ /* All parsed OK. */
+ return 0;
+}
diff --git a/common/startup.c b/common/startup.c
index aa76cb7..9667b50 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -41,6 +41,7 @@
#include <reloc.h>
#include <asm-generic/memory_layout.h>
#include <asm/sections.h>
+#include <asm/setup.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
@@ -112,6 +113,67 @@ static int mount_root(void)
}
fs_initcall(mount_root);
+#ifdef CONFIG_BOOT_CMDLINE
+extern const struct obs_kernel_param __setup_start[], __setup_end[];
+
+static int __init obsolete_checksetup(char *line)
+{
+ const struct obs_kernel_param *p;
+
+ p = __setup_start;
+ do {
+ int n = strlen(p->str);
+ if (!strncmp(line, p->str, n)) {
+ if (!p->setup_func) {
+ printk(KERN_WARNING "Parameter %s is obsolete,"
+ " ignored\n", p->str);
+ return 1;
+ } else if (p->setup_func(line + n))
+ return 1;
+ }
+ p++;
+ } while (p < __setup_end);
+
+ return 0;
+}
+
+/*
+ * Unknown boot options get handed to init, unless they look like
+ * unused parameters (modprobe will find them in /proc/cmdline).
+ */
+static int __init unknown_bootoption(char *param, char *val)
+{
+ /* Change NUL term back to "=", to make "param" the whole string. */
+ if (val) {
+ /* param=val or param="val"? */
+ if (val == param+strlen(param)+1)
+ val[-1] = '=';
+ else if (val == param+strlen(param)+2) {
+ val[-2] = '=';
+ memmove(val-1, val, strlen(val)+1);
+ val--;
+ } else
+ BUG();
+ }
+
+ /* Handle obsolete-style parameters */
+ obsolete_checksetup(param);
+ return 0;
+}
+
+void __init parse_param(void)
+{
+ static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
+
+ strlcpy(tmp_cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+ parse_args("Booting Barebox", tmp_cmdline, unknown_bootoption);
+}
+#else
+static void inline parse_param(void)
+{
+}
+#endif
+
void start_barebox (void)
{
initcall_t *initcall;
@@ -128,6 +190,8 @@ void start_barebox (void)
init_data_ptr = &__early_init_data_begin;
#endif /* CONFIG_HAS_EARLY_INIT */
+ parse_param();
+
for (initcall = __barebox_initcalls_start;
initcall < __barebox_initcalls_end; initcall++) {
PUTHEX_LL(*initcall);
@@ -180,4 +244,3 @@ void shutdown_barebox(void)
arch_shutdown();
#endif
}
-
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index fc141a4..18eab31 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -7,6 +7,8 @@
#define PRE_IMAGE
#endif
+#define INIT_SETUP KEEP(*(.init_setup))
+
#define INITCALLS \
KEEP(*(.initcall.0)) \
KEEP(*(.initcall.1)) \
diff --git a/include/init.h b/include/init.h
index 2f4fac1..53148fa 100644
--- a/include/init.h
+++ b/include/init.h
@@ -44,6 +44,34 @@ typedef int (*initcall_t)(void);
*/
#define __bare_init __section(.text_bare_init.text)
+#define __initconst __section(.rodata)
+
+struct obs_kernel_param {
+ const char *str;
+ int (*setup_func)(char *);
+};
+
+/*
+ * Only for really core code. See moduleparam.h for the normal way.
+ *
+ * Force the alignment so the compiler doesn't space elements of the
+ * obs_kernel_param "array" too far apart in .init.setup.
+ */
+#define __setup_param(str, unique_id, fn) \
+ static const char __setup_str_##unique_id[] __initconst \
+ __aligned(1) = str; \
+ static struct obs_kernel_param __setup_##unique_id \
+ __used __section(.init_setup) \
+ __attribute__((aligned((sizeof(long))))) \
+ = { __setup_str_##unique_id, fn}
+
+#define __setup(str, fn) \
+ __setup_param(str, fn, fn)
+
+/* Called on module insert or kernel boot */
+extern int parse_args(const char *name,
+ char *args,
+ int (*unknown)(char *param, char *val));
#endif
#endif /* _INIT_H */
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-02-07 11:04 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-26 16:43 [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 1/3] string: add skip_spaces support Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 2/3] add command line boot support Jean-Christophe PLAGNIOL-VILLARD
2011-01-27 9:20 ` Sascha Hauer
2011-01-27 11:55 ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-27 13:10 ` Sascha Hauer
2011-01-27 13:15 ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-26 16:46 ` [PATCH 3/3] __setup test Jean-Christophe PLAGNIOL-VILLARD
2014-02-07 11:04 ` [RFC] Boot command line support Jean-Christophe PLAGNIOL-VILLARD
2011-01-27 13:02 [PATCH 1/3] string: add skip_spaces support Jean-Christophe PLAGNIOL-VILLARD
2011-01-27 13:02 ` [PATCH 2/3] add command line boot support Jean-Christophe PLAGNIOL-VILLARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox