* (no subject)
@ 2016-04-29 9:51 Sascha Hauer
2016-04-29 9:52 ` [PATCH 1/6] globalvar: Allow to remove globalvars Sascha Hauer
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:51 UTC (permalink / raw)
To: Barebox List
With this series we can let the bootm command automatically append a root=
option for the Kernel which will let the rootfs come from the same
device as the kernel comes from. The code was already there, but only
worked with bootloader spec. By moving it to bootm we can also use it
with bootm directly. As usual there a a few things to cleanup I stumbled
upon which are also part of this series.
Sascha
----------------------------------------------------------------
Sascha Hauer (6):
globalvar: Allow to remove globalvars
string: Introduce strtobool
getenv_bool: use strtobool
parameter: Use strtobool
bootm: Optionally add a root= option to Kernel command line
blspec: push appendroot handling to bootm
Documentation/user/booting-linux.rst | 14 ++++++++++++
commands/bootm.c | 1 +
common/blspec.c | 39 +++++++++++---------------------
common/bootm.c | 17 ++++++++++++++
common/env.c | 28 ++++++++++++++---------
common/globalvar.c | 10 +++++++++
include/boot.h | 5 +++++
include/globalvar.h | 1 +
include/string.h | 1 +
lib/parameter.c | 7 +++---
lib/string.c | 43 ++++++++++++++++++++++++++++++++++++
11 files changed, 126 insertions(+), 40 deletions(-)
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] globalvar: Allow to remove globalvars
2016-04-29 9:51 Sascha Hauer
@ 2016-04-29 9:52 ` Sascha Hauer
2016-04-29 9:52 ` [PATCH 2/6] string: Introduce strtobool Sascha Hauer
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:52 UTC (permalink / raw)
To: Barebox List
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/globalvar.c | 10 ++++++++++
include/globalvar.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/common/globalvar.c b/common/globalvar.c
index 9a793ac..05c3e79 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -33,6 +33,16 @@ int globalvar_add(const char *name,
return 0;
}
+void globalvar_remove(const char *name)
+{
+ struct param_d *param = get_param_by_name(&global_device, name);
+
+ if (!param)
+ return;
+
+ dev_remove_param(param);
+}
+
static int nv_save(const char *name, const char *val)
{
int fd, ret;
diff --git a/include/globalvar.h b/include/globalvar.h
index e77209b..d0c79c0 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -14,6 +14,7 @@ int globalvar_add(const char *name,
int (*set)(struct device_d *dev, struct param_d *p, const char *val),
const char *(*get)(struct device_d *, struct param_d *p),
unsigned long flags);
+void globalvar_remove(const char *name);
char *globalvar_get_match(const char *match, const char *separator);
void globalvar_set_match(const char *match, const char *val);
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/6] string: Introduce strtobool
2016-04-29 9:51 Sascha Hauer
2016-04-29 9:52 ` [PATCH 1/6] globalvar: Allow to remove globalvars Sascha Hauer
@ 2016-04-29 9:52 ` Sascha Hauer
2016-04-29 9:52 ` [PATCH 3/6] getenv_bool: use strtobool Sascha Hauer
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:52 UTC (permalink / raw)
To: Barebox List
We have at least two places which convert a string to a boolean type,
so create a common function for this. strtobool treats
- any positive (nonzero) number as true
- "0" as false
- "true" (case insensitive) as true
- "false" (case insensitive) as false
Every other value results in an error and the input *val is not
modified. The caller is expected to initialize *val with the correct
default before calling strtobool.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/string.h | 1 +
lib/string.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/string.h b/include/string.h
index a833da1..0c557d6 100644
--- a/include/string.h
+++ b/include/string.h
@@ -4,5 +4,6 @@
#include <linux/string.h>
void *memdup(const void *, size_t);
+int strtobool(const char *str, int *val);
#endif /* __STRING_H */
diff --git a/lib/string.c b/lib/string.c
index 6a39eb5..a3e9fd8 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -739,3 +739,46 @@ void *memdup(const void *orig, size_t size)
return buf;
}
EXPORT_SYMBOL(memdup);
+
+/**
+ * strtobool - convert a string to a boolean value
+ * @str - The string
+ * @val - The boolean value returned.
+ *
+ * This function treats
+ * - any positive (nonzero) number as true
+ * - "0" as false
+ * - "true" (case insensitive) as true
+ * - "false" (case insensitive) as false
+ *
+ * Every other value results in an error and the @val is not
+ * modified. The caller is expected to initialize @val with the
+ * correct default before calling strtobool.
+ *
+ * Returns 0 for success or negative error code if the variable does
+ * not exist or contains something this function does not recognize
+ * as true or false.
+ */
+int strtobool(const char *str, int *val)
+{
+ if (!str || !*str)
+ return -EINVAL;
+
+ if (simple_strtoul(str, NULL, 0) > 0) {
+ *val = true;
+ return 0;
+ }
+
+ if (!strcmp(str, "0") || !strcasecmp(str, "false")) {
+ *val = false;
+ return 0;
+ }
+
+ if (!strcasecmp(str, "true")) {
+ *val = true;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL(strtobool);
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/6] getenv_bool: use strtobool
2016-04-29 9:51 Sascha Hauer
2016-04-29 9:52 ` [PATCH 1/6] globalvar: Allow to remove globalvars Sascha Hauer
2016-04-29 9:52 ` [PATCH 2/6] string: Introduce strtobool Sascha Hauer
@ 2016-04-29 9:52 ` Sascha Hauer
2016-04-29 9:52 ` [PATCH 4/6] parameter: Use strtobool Sascha Hauer
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:52 UTC (permalink / raw)
To: Barebox List
We now have a library function to convert a string to a boolean type.
Use it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/env.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/common/env.c b/common/env.c
index c98ed73..d6cab52 100644
--- a/common/env.c
+++ b/common/env.c
@@ -28,6 +28,7 @@
#include <xfuncs.h>
#include <errno.h>
#include <init.h>
+#include <string.h>
#include <environment.h>
static struct env_context root = {
@@ -323,20 +324,25 @@ int getenv_uint(const char *var , unsigned int *val)
}
EXPORT_SYMBOL(getenv_uint);
+/**
+ * getenv_bool - get a boolean value from an environment variable
+ * @var - Variable name
+ * @val - The boolean value returned.
+ *
+ * This function treats
+ * - any positive (nonzero) number as true
+ * - "0" as false
+ * - "true" (case insensitive) as true
+ * - "false" (case insensitive) as false
+ *
+ * Returns 0 for success or negative error code if the variable does
+ * not exist or contains something this function does not recognize
+ * as true or false.
+ */
int getenv_bool(const char *var, int *val)
{
const char *valstr = getenv(var);
- if (!valstr || !*valstr)
- return -EINVAL;
-
- if (!*valstr)
- *val = false;
- else if (*valstr == '0')
- *val = false;
- else
- *val = true;
-
- return 0;
+ return strtobool(valstr, val);
}
EXPORT_SYMBOL(getenv_bool);
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/6] parameter: Use strtobool
2016-04-29 9:51 Sascha Hauer
` (2 preceding siblings ...)
2016-04-29 9:52 ` [PATCH 3/6] getenv_bool: use strtobool Sascha Hauer
@ 2016-04-29 9:52 ` Sascha Hauer
2016-04-29 9:52 ` [PATCH 5/6] bootm: Optionally add a root= option to Kernel command line Sascha Hauer
2016-04-29 9:52 ` [PATCH 6/6] blspec: push appendroot handling to bootm Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:52 UTC (permalink / raw)
To: Barebox List
Use strtobool to convert the input string to a boolean type.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
lib/parameter.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/parameter.c b/lib/parameter.c
index fd05b49..7ceec0c 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -27,6 +27,7 @@
#include <net.h>
#include <malloc.h>
#include <driver.h>
+#include <string.h>
#include <linux/err.h>
struct param_d *get_param_by_name(struct device_d *dev, const char *name)
@@ -314,10 +315,10 @@ static int param_int_set(struct device_d *dev, struct param_d *p, const char *va
if (!val)
return -EINVAL;
- *pi->value = simple_strtol(val, NULL, 0);
-
if (pi->flags & PARAM_INT_FLAG_BOOL)
- *pi->value = !!*pi->value;
+ return strtobool(val, pi->value);
+
+ *pi->value = simple_strtol(val, NULL, 0);
if (!pi->set)
return 0;
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] bootm: Optionally add a root= option to Kernel command line
2016-04-29 9:51 Sascha Hauer
` (3 preceding siblings ...)
2016-04-29 9:52 ` [PATCH 4/6] parameter: Use strtobool Sascha Hauer
@ 2016-04-29 9:52 ` Sascha Hauer
2016-04-29 9:52 ` [PATCH 6/6] blspec: push appendroot handling to bootm Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:52 UTC (permalink / raw)
To: Barebox List
It becomes a common case that the Kernel is loaded from the filesystem
which later becomes the rootfs. This adds a possibility to let bootm
automatically append the root= option to the kernel command line. This
is done when global.bootm.appendroot is true.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Documentation/user/booting-linux.rst | 14 ++++++++++++++
commands/bootm.c | 1 +
common/bootm.c | 17 +++++++++++++++++
include/boot.h | 5 +++++
4 files changed, 37 insertions(+)
diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
index 98628fa..f26299e 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -99,6 +99,20 @@ with addpart to the Kernel:
Kernel command line: mtdparts=physmap-flash.0:512k(bootloader),512k(env),4M(kernel),-(root);
mxc_nand:1M(bootloader),1M(env),4M(kernel),-(root)
+Creating root= options for the Kernel
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+It's a common case that the Linux Kernel is loaded from a filesystem
+that later becomes the root filesystem for the Kernel. For several
+filesystems barebox can automatically append a suitable root= option
+to the Kernel command line. This is done when ``global.bootm.appendroot``
+is true. How the root= option is appended depends on the device type
+and filesystem the kernel is booted from. For disk like devices (SD/MMC,
+ATA) the partition UUID will be used, the root= option will be something
+like ``root=PARTUUID=deadbeef-1``. For UBIFS fileystems it will be
+``root=ubi0:volname ubi.mtd=mtdpartname rootfstype=ubifs``. NFS
+filesystems will result in ``root=/dev/nfs nfsroot=ip:/path/to/nfsroot,v3,tcp``.
+The ``v3,tcp`` part is configurable in ``global.linux.rootnfsopts``.
The boot command
----------------
diff --git a/commands/bootm.c b/commands/bootm.c
index 7a19fa2..bfec62c 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -166,6 +166,7 @@ BAREBOX_MAGICVAR_NAMED(global_bootm_initrd, global.bootm.initrd, "bootm default
BAREBOX_MAGICVAR_NAMED(global_bootm_initrd_loadaddr, global.bootm.initrd.loadaddr, "bootm default initrd loadaddr");
BAREBOX_MAGICVAR_NAMED(global_bootm_oftree, global.bootm.oftree, "bootm default oftree");
BAREBOX_MAGICVAR_NAMED(global_bootm_verify, global.bootm.verify, "bootm default verify level");
+BAREBOX_MAGICVAR_NAMED(global_bootm_appendroot, global.bootm.appendroot, "Add root= option to Kernel to mount rootfs from the device the Kernel comes from");
static struct binfmt_hook binfmt_uimage_hook = {
.type = filetype_uimage,
diff --git a/common/bootm.c b/common/bootm.c
index 6d22aab..cad8c73 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -48,6 +48,8 @@ static struct image_handler *bootm_find_handler(enum filetype filetype,
return NULL;
}
+static int bootm_appendroot;
+
void bootm_data_init_defaults(struct bootm_data *data)
{
data->initrd_address = UIMAGE_INVALID_ADDRESS;
@@ -58,6 +60,7 @@ void bootm_data_init_defaults(struct bootm_data *data)
getenv_ul("global.bootm.initrd.loadaddr", &data->initrd_address);
data->initrd_file = getenv_nonempty("global.bootm.initrd");
data->verify = bootm_get_verify_mode();
+ data->appendroot = bootm_appendroot;
}
static enum bootm_verify bootm_verify_mode = BOOTM_VERIFY_HASH;
@@ -576,6 +579,18 @@ int bootm_boot(struct bootm_data *bootm_data)
}
}
+ if (bootm_data->appendroot) {
+ char *rootarg;
+
+ rootarg = path_get_linux_rootarg(data->os_file);
+ if (!IS_ERR(rootarg)) {
+ printf("Adding \"%s\" to Kernel commandline\n", rootarg);
+ globalvar_add_simple("linux.bootargs.bootm.appendroot",
+ rootarg);
+ free(rootarg);
+ }
+ }
+
printf("\nLoading %s '%s'", file_type_to_string(os_type),
data->os_file);
if (os_type == filetype_uimage &&
@@ -621,6 +636,7 @@ err_out:
if (data->of_root_node && data->of_root_node != of_get_root_node())
of_delete_node(data->of_root_node);
+ globalvar_remove("linux.bootargs.bootm.appendroot");
free(data->os_file);
free(data->oftree_file);
free(data->initrd_file);
@@ -634,6 +650,7 @@ static int bootm_init(void)
globalvar_add_simple("bootm.image", NULL);
globalvar_add_simple("bootm.image.loadaddr", NULL);
globalvar_add_simple("bootm.oftree", NULL);
+ globalvar_add_simple_bool("bootm.appendroot", &bootm_appendroot);
if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD)) {
globalvar_add_simple("bootm.initrd", NULL);
globalvar_add_simple("bootm.initrd.loadaddr", NULL);
diff --git a/include/boot.h b/include/boot.h
index 0198cc8..8fcbb7f 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -21,6 +21,11 @@ struct bootm_data {
enum bootm_verify verify;
bool force;
bool dryrun;
+ /*
+ * appendroot - if true, try to add a suitable root= Kernel option to
+ * mount the rootfs from the same device as the Kernel comes from.
+ */
+ bool appendroot;
unsigned long initrd_address;
unsigned long os_address;
unsigned long os_entry;
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6/6] blspec: push appendroot handling to bootm
2016-04-29 9:51 Sascha Hauer
` (4 preceding siblings ...)
2016-04-29 9:52 ` [PATCH 5/6] bootm: Optionally add a root= option to Kernel command line Sascha Hauer
@ 2016-04-29 9:52 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2016-04-29 9:52 UTC (permalink / raw)
To: Barebox List
The bootm code now can handle the adding of the root= option itself,
so drop the code and let bootm do it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 39 +++++++++++++--------------------------
1 file changed, 13 insertions(+), 26 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index 1800556..ac8f512 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -637,29 +637,6 @@ int blspec_scan_devicename(struct blspec *blspec, const char *devname)
return blspec_scan_device(blspec, dev);
}
-static int blspec_append_root(struct blspec_entry *entry)
-{
- const char *appendroot;
- char *rootarg;
-
- appendroot = blspec_entry_var_get(entry, "linux-appendroot");
- if (!appendroot || strcmp(appendroot, "true"))
- return 0;
-
- rootarg = path_get_linux_rootarg(entry->rootpath);
- if (IS_ERR(rootarg)) {
- pr_err("Getting root argument for %s failed with: %s\n",
- entry->rootpath, strerrorp(rootarg));
- return PTR_ERR(rootarg);
- }
-
- globalvar_add_simple("linux.bootargs.dyn.blspec.appendroot", rootarg);
-
- free(rootarg);
-
- return 0;
-}
-
/*
* blspec_boot - boot an entry
*
@@ -671,6 +648,7 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
{
int ret;
const char *abspath, *devicetree, *options, *initrd, *linuximage;
+ const char *appendroot;
struct bootm_data data = {
.initrd_address = UIMAGE_INVALID_ADDRESS,
.os_address = UIMAGE_SOME_ADDRESS,
@@ -709,9 +687,18 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
globalvar_add_simple("linux.bootargs.dyn.blspec", options);
- ret = blspec_append_root(entry);
- if (ret)
- goto err_out;
+ appendroot = blspec_entry_var_get(entry, "linux-appendroot");
+ if (appendroot) {
+ int val;
+
+ ret = strtobool(appendroot, &val);
+ if (ret) {
+ pr_err("Invalid value \"%s\" for appendroot option\n",
+ appendroot);
+ goto err_out;
+ }
+ data.appendroot = val;
+ }
pr_info("booting %s from %s\n", blspec_entry_var_get(entry, "title"),
entry->cdev ? dev_name(entry->cdev->dev) : "none");
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-04-29 9:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-29 9:51 Sascha Hauer
2016-04-29 9:52 ` [PATCH 1/6] globalvar: Allow to remove globalvars Sascha Hauer
2016-04-29 9:52 ` [PATCH 2/6] string: Introduce strtobool Sascha Hauer
2016-04-29 9:52 ` [PATCH 3/6] getenv_bool: use strtobool Sascha Hauer
2016-04-29 9:52 ` [PATCH 4/6] parameter: Use strtobool Sascha Hauer
2016-04-29 9:52 ` [PATCH 5/6] bootm: Optionally add a root= option to Kernel command line Sascha Hauer
2016-04-29 9:52 ` [PATCH 6/6] blspec: push appendroot handling to bootm Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox