mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID
@ 2020-08-10 12:20 Robert Karszniewicz
  2020-08-19 10:24 ` Robert Karszniewicz
  2020-08-20  7:05 ` Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Robert Karszniewicz @ 2020-08-10 12:20 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
---
Changes from v2:
- correct commit message line lengths

Changes from v1:
- minor commit message change

Changes from RFC v2:
- replaced path_get_linux_rootarg("invalid") by ERR_PTR(-EINVAL)
- added error messages. (I've made them mutually exclusive to prevent
  NULL-pointer dereference)

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

diff --git a/common/bootm.c b/common/bootm.c
index 8fec1ee34dd8..7f951172ccf5 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;
@@ -655,7 +656,25 @@ 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 = ERR_PTR(-EINVAL);
+
+				if (!root_cdev)
+					pr_err("no cdev found for %s, cannot set root= option\n",
+						root_dev_name);
+				else if (!root_cdev->partuuid[0])
+					pr_err("%s doesn't have a PARTUUID, cannot set root= option\n",
+						root_dev_name);
+			}
+		} 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",
@@ -742,6 +761,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);
@@ -771,5 +791,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] 4+ messages in thread

* Re: [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID
  2020-08-10 12:20 [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
@ 2020-08-19 10:24 ` Robert Karszniewicz
  2020-08-20  7:05 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Karszniewicz @ 2020-08-19 10:24 UTC (permalink / raw)
  To: barebox

What's the status on this, please?

Greetings.

On 8/10/20 2:20 PM, Robert Karszniewicz wrote:
> 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
> 
> Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
> ---
> Changes from v2:
> - correct commit message line lengths
> 
> Changes from v1:
> - minor commit message change
> 
> Changes from RFC v2:
> - replaced path_get_linux_rootarg("invalid") by ERR_PTR(-EINVAL)
> - added error messages. (I've made them mutually exclusive to prevent
>    NULL-pointer dereference)
> 
>   common/bootm.c  | 25 +++++++++++++++++++++++--
>   include/bootm.h |  2 ++
>   2 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/common/bootm.c b/common/bootm.c
> index 8fec1ee34dd8..7f951172ccf5 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;
> @@ -655,7 +656,25 @@ 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 = ERR_PTR(-EINVAL);
> +
> +				if (!root_cdev)
> +					pr_err("no cdev found for %s, cannot set root= option\n",
> +						root_dev_name);
> +				else if (!root_cdev->partuuid[0])
> +					pr_err("%s doesn't have a PARTUUID, cannot set root= option\n",
> +						root_dev_name);
> +			}
> +		} 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",
> @@ -742,6 +761,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);
> @@ -771,5 +791,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;
>   	/*
> 


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

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

* Re: [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID
  2020-08-10 12:20 [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
  2020-08-19 10:24 ` Robert Karszniewicz
@ 2020-08-20  7:05 ` Sascha Hauer
  2020-08-20 12:53   ` Robert Karszniewicz
  1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2020-08-20  7:05 UTC (permalink / raw)
  To: Robert Karszniewicz; +Cc: barebox

On Mon, Aug 10, 2020 at 02:20:08PM +0200, Robert Karszniewicz wrote:
> 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
> 
> Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
> ---

Applied, thanks

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] 4+ messages in thread

* Re: [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID
  2020-08-20  7:05 ` Sascha Hauer
@ 2020-08-20 12:53   ` Robert Karszniewicz
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Karszniewicz @ 2020-08-20 12:53 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 8/20/20 9:05 AM, Sascha Hauer wrote:
> On Mon, Aug 10, 2020 at 02:20:08PM +0200, Robert Karszniewicz wrote:
>> 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
>>
>> Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
>> ---
> 
> Applied, thanks
> 
> Sascha
> 

Thanks!

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

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

end of thread, other threads:[~2020-08-20 12:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10 12:20 [PATCH v3] bootm: add global.bootm.root_dev env var for booting via PARTUUID Robert Karszniewicz
2020-08-19 10:24 ` Robert Karszniewicz
2020-08-20  7:05 ` Sascha Hauer
2020-08-20 12:53   ` Robert Karszniewicz

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