Skip to contentSkip to conversation

Introduce global.bootm.root_dev env var for booting via PARTUUID

RFC PATCH In review Robert Karszniewicz 2 participants 6 messages Aug 5, 2020 – Aug 10, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce global.bootm.root_dev env var for booting via PARTUUID

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(-)
Signature · 7 lines
2.7.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

RFC PATCH v2 1/3 bootm: add env var root_dev

---
 common/bootm.c  | 4 +++-
 include/bootm.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
common/bootm.c +3 -1
index 8fec1ee34dd8..311d0e058321 100644
@@ -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");
include/bootm.h +2 -0
index 7782de7a476d..3628a7eea5b9 100644
@@ -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;
 	/*
Signature · 7 lines
2.7.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

RFC PATCH v2 2/3 globalvar: add bootm.root_dev

In reply to Robert Karszniewicz
---
 common/bootm.c | 1 +
 1 file changed, 1 insertion(+)
common/bootm.c +1 -0
index 311d0e058321..73409bf9f70c 100644
@@ -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);
Signature · 7 lines
2.7.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

RFC PATCH v2 3/3 bootm: handle global.bootm.root_dev

In reply to Robert Karszniewicz
---
 common/bootm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
common/bootm.c +12 -1
index 73409bf9f70c..01b54ab93958 100644
@@ -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",
Signature · 7 lines
2.7.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev

Quoted 11 lines · Robert Karszniewicz
---
  common/bootm.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
common/bootm.c +0 -0
index 73409bf9f70c..01b54ab93958 100644
@@ -656,7 +656,18 @@ int bootm_boot(struct bootm_data *bootm_data)
  	if (bootm_data->appendroot) {
  		char *rootarg;

common/bootm.c int bootm_boot(struct bootm_data *bootm_data) · line 666

Quoted 10 lines
common/bootm.c +8 -1
 
-		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).

common/bootm.c int bootm_boot(struct bootm_data *bootm_data) · line 673

Quoted 8 lines
common/bootm.c +4 -0
+			}
+		} 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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw

Re: [RFC PATCH v2 3/3] bootm: handle global.bootm.root_dev

Hi Robert,

Quoted 16 lines · Robert Karszniewicz
Quoted 15 lines · Robert Karszniewicz
---
  common/bootm.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
common/bootm.c +3 -1
index 73409bf9f70c..01b54ab93958 100644
@@ -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);
Quoted 8 lines

common/bootm.c int bootm_boot(struct bootm_data *bootm_data) · line 666

Quoted 5 lines
common/bootm.c +5 -0
+
+			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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox