mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/3] Introduce global.bootm.root_dev env var for booting via PARTUUID
@ 2020-08-05 10:10 Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 1/3] bootm: add env var root_dev Robert Karszniewicz
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Robert Karszniewicz @ 2020-08-05 10:10 UTC (permalink / raw)
  To: barebox

This patch introduces a new env var which specifies which device is the
rootfs device to be used in Linux, passed to Linux via bootargs,
identified by the rootfs partition's PARTUUID.

global.bootm.root_dev supplements global.bootm.appendroot, in that it
overrides appendroot's naïve default, which picks the partition that the
kernel resides on (global.bootm.image).

Example:
detect mmc2
global.bootm.image='/mnt/mmc2.0/zImage'
global.bootm.appendroot=1
global.bootm.root_dev=/dev/mmc2.1
boot mmc

For proper patch, I would squash all commits.

Changes from v1:
- renamed env var s/root/root_dev/
- used filesystem-agnostic approach (root_dev now takes a /dev/ instead
  of a mounted partition)

Robert Karszniewicz (3):
  bootm: add env var root_dev
  globalvar: add bootm.root_dev
  bootm: handle global.bootm.root_dev

 common/bootm.c  | 18 ++++++++++++++++--
 include/bootm.h |  2 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

-- 
2.7.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH v2 1/3] bootm: add env var root_dev
  2020-08-05 10:10 [RFC PATCH v2 0/3] Introduce global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
@ 2020-08-05 10:10 ` Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 2/3] globalvar: add bootm.root_dev Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev Robert Karszniewicz
  2 siblings, 0 replies; 6+ messages in thread
From: Robert Karszniewicz @ 2020-08-05 10:10 UTC (permalink / raw)
  To: barebox

---
 common/bootm.c  | 4 +++-
 include/bootm.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8fec1ee34dd8..311d0e058321 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -64,6 +64,7 @@ void bootm_data_init_defaults(struct bootm_data *data)
 	getenv_ul("global.bootm.image.loadaddr", &data->os_address);
 	getenv_ul("global.bootm.initrd.loadaddr", &data->initrd_address);
 	data->initrd_file = getenv_nonempty("global.bootm.initrd");
+	data->root_dev = getenv_nonempty("global.bootm.root_dev");
 	data->verify = bootm_get_verify_mode();
 	data->appendroot = bootm_appendroot;
 	data->provide_machine_id = bootm_provide_machine_id;
@@ -771,5 +772,6 @@ BAREBOX_MAGICVAR_NAMED(global_bootm_oftree, global.bootm.oftree, "bootm default
 BAREBOX_MAGICVAR_NAMED(global_bootm_tee, global.bootm.tee, "bootm default tee image");
 BAREBOX_MAGICVAR_NAMED(global_bootm_verify, global.bootm.verify, "bootm default verify level");
 BAREBOX_MAGICVAR_NAMED(global_bootm_verbose, global.bootm.verbose, "bootm default verbosity level (0=quiet)");
-BAREBOX_MAGICVAR_NAMED(global_bootm_appendroot, global.bootm.appendroot, "Add root= option to Kernel to mount rootfs from the device the Kernel comes from");
+BAREBOX_MAGICVAR_NAMED(global_bootm_appendroot, global.bootm.appendroot, "Add root= option to Kernel to mount rootfs from the device the Kernel comes from (default, device can be overridden via global.bootm.root_dev)");
+BAREBOX_MAGICVAR_NAMED(global_bootm_root_dev, global.bootm.root_dev, "bootm default root device (overrides default device in global.bootm.appendroot)");
 BAREBOX_MAGICVAR_NAMED(global_bootm_provide_machine_id, global.bootm.provide_machine_id, "If true, add systemd.machine_id= with value of global.machine_id to Kernel");
diff --git a/include/bootm.h b/include/bootm.h
index 7782de7a476d..3628a7eea5b9 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -18,6 +18,7 @@ struct bootm_data {
 	const char *initrd_file;
 	const char *oftree_file;
 	const char *tee_file;
+	const char *root_dev;
 	int verbose;
 	enum bootm_verify verify;
 	bool force;
@@ -25,6 +26,7 @@ struct bootm_data {
 	/*
 	 * appendroot - if true, try to add a suitable root= Kernel option to
 	 * mount the rootfs from the same device as the Kernel comes from.
+	 * The default rootfs device can be overridden with root_dev.
 	 */
 	bool appendroot;
 	/*
-- 
2.7.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH v2 2/3] globalvar: add bootm.root_dev
  2020-08-05 10:10 [RFC PATCH v2 0/3] Introduce global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 1/3] bootm: add env var root_dev Robert Karszniewicz
@ 2020-08-05 10:10 ` Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev Robert Karszniewicz
  2 siblings, 0 replies; 6+ messages in thread
From: Robert Karszniewicz @ 2020-08-05 10:10 UTC (permalink / raw)
  To: barebox

---
 common/bootm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/bootm.c b/common/bootm.c
index 311d0e058321..73409bf9f70c 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -743,6 +743,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("bootm.root_dev", NULL);
 	globalvar_add_simple("bootm.tee", NULL);
 	globalvar_add_simple_bool("bootm.appendroot", &bootm_appendroot);
 	globalvar_add_simple_bool("bootm.provide_machine_id", &bootm_provide_machine_id);
-- 
2.7.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev
  2020-08-05 10:10 [RFC PATCH v2 0/3] Introduce global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 1/3] bootm: add env var root_dev Robert Karszniewicz
  2020-08-05 10:10 ` [RFC PATCH v2 2/3] globalvar: add bootm.root_dev Robert Karszniewicz
@ 2020-08-05 10:10 ` Robert Karszniewicz
  2020-08-05 10:15   ` Robert Karszniewicz
  2 siblings, 1 reply; 6+ messages in thread
From: Robert Karszniewicz @ 2020-08-05 10:10 UTC (permalink / raw)
  To: barebox

---
 common/bootm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 73409bf9f70c..01b54ab93958 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -656,7 +656,18 @@ int bootm_boot(struct bootm_data *bootm_data)
 	if (bootm_data->appendroot) {
 		char *rootarg;
 
-		rootarg = path_get_linux_rootarg(data->os_file);
+		if (bootm_data->root_dev) {
+			const char *root_dev_name = devpath_to_name(bootm_data->root_dev);
+			const struct cdev *root_cdev = cdev_by_name(root_dev_name);
+
+			if (root_cdev && root_cdev->partuuid[0] != 0) {
+				rootarg = basprintf("root=PARTUUID=%s", root_cdev->partuuid);
+			} else {
+				rootarg = path_get_linux_rootarg("invalid");
+			}
+		} else {
+			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",
-- 
2.7.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev
  2020-08-05 10:10 ` [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev Robert Karszniewicz
@ 2020-08-05 10:15   ` Robert Karszniewicz
  2020-08-10  9:45     ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Karszniewicz @ 2020-08-05 10:15 UTC (permalink / raw)
  To: barebox

On 8/5/20 12:10 PM, Robert Karszniewicz wrote:
> ---
>   common/bootm.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/common/bootm.c b/common/bootm.c
> index 73409bf9f70c..01b54ab93958 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -656,7 +656,18 @@ int bootm_boot(struct bootm_data *bootm_data)
>   	if (bootm_data->appendroot) {
>   		char *rootarg;
>   
> -		rootarg = path_get_linux_rootarg(data->os_file);
> +		if (bootm_data->root_dev) {
> +			const char *root_dev_name = devpath_to_name(bootm_data->root_dev);
> +			const struct cdev *root_cdev = cdev_by_name(root_dev_name);
> +
> +			if (root_cdev && root_cdev->partuuid[0] != 0) {
> +				rootarg = basprintf("root=PARTUUID=%s", root_cdev->partuuid);
> +			} else {
> +				rootarg = path_get_linux_rootarg("invalid");

Here I wasn't sure if I should be uniform and let the function return an 
error or just straight assign ERR_PTR(-EINVAL).

> +			}
> +		} else {
> +			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",
> 


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev
  2020-08-05 10:15   ` Robert Karszniewicz
@ 2020-08-10  9:45     ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2020-08-10  9:45 UTC (permalink / raw)
  To: Robert Karszniewicz; +Cc: barebox

Hi Robert,

On Wed, Aug 05, 2020 at 12:15:50PM +0200, Robert Karszniewicz wrote:
> On 8/5/20 12:10 PM, Robert Karszniewicz wrote:
> > ---
> >   common/bootm.c | 13 ++++++++++++-
> >   1 file changed, 12 insertions(+), 1 deletion(-)
> > 
> > diff --git a/common/bootm.c b/common/bootm.c
> > index 73409bf9f70c..01b54ab93958 100644
> > --- a/common/bootm.c
> > +++ b/common/bootm.c
> > @@ -656,7 +656,18 @@ int bootm_boot(struct bootm_data *bootm_data)
> >   	if (bootm_data->appendroot) {
> >   		char *rootarg;
> > -		rootarg = path_get_linux_rootarg(data->os_file);
> > +		if (bootm_data->root_dev) {
> > +			const char *root_dev_name = devpath_to_name(bootm_data->root_dev);
> > +			const struct cdev *root_cdev = cdev_by_name(root_dev_name);
> > +
> > +			if (root_cdev && root_cdev->partuuid[0] != 0) {
> > +				rootarg = basprintf("root=PARTUUID=%s", root_cdev->partuuid);
> > +			} else {
> > +				rootarg = path_get_linux_rootarg("invalid");
> 
> Here I wasn't sure if I should be uniform and let the function return an
> error or just straight assign ERR_PTR(-EINVAL).

The latter looks better IMO.

You could be more verbose in the error case. Something like

		if (!root_cdev)
			pr_err("no cdev for %s found\n", root_dev_name);
		if (!root_cdev->partuuid[0])
			pr_err("%s doesn't have a PARTUUID, cannot set root= option\n",
				root_dev_name);

Otherwise the patch looks fine to me.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
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] 6+ messages in thread

end of thread, other threads:[~2020-08-10  9:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05 10:10 [RFC PATCH v2 0/3] Introduce global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
2020-08-05 10:10 ` [RFC PATCH v2 1/3] bootm: add env var root_dev Robert Karszniewicz
2020-08-05 10:10 ` [RFC PATCH v2 2/3] globalvar: add bootm.root_dev Robert Karszniewicz
2020-08-05 10:10 ` [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev Robert Karszniewicz
2020-08-05 10:15   ` Robert Karszniewicz
2020-08-10  9:45     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox