mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Bootspec: Allow to automatically append root= option
@ 2015-06-18  7:43 Sascha Hauer
  2015-06-18  7:43 ` [PATCH 1/6] Add globalvar_add_simple_string function Sascha Hauer
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

In bootspec entries we have to add a root= to specify the kernel where
it can find its root filesystem. This series allows to automatically
append this option based on the filesystem where the entry is found on.
With this we can make the root filesystem images independent of the
device they are installed on.

Sascha

----------------------------------------------------------------
Sascha Hauer (6):
      Add globalvar_add_simple_string function
      cdev: Add partuuid string to struct cdev
      fs: Add device parameter for Linux root= option
      fs: ubifs: Implement Linux rootarg
      fs: nfs: Implement Linux rootarg
      blspec: Automatically append rootarg

 Documentation/filesystems/nfs.rst    | 13 +++++++++++++
 Documentation/user/booting-linux.rst |  7 +++++++
 common/blspec.c                      | 29 +++++++++++++++++++++++++++-
 common/partitions.c                  |  1 +
 common/partitions/dos.c              |  4 ++++
 common/partitions/parser.h           |  1 +
 drivers/mtd/ubi/kapi.c               |  1 +
 fs/fs.c                              | 37 ++++++++++++++++++++++++++++++++++++
 fs/nfs.c                             | 24 +++++++++++++++++++++++
 fs/ubifs/ubifs.c                     | 23 ++++++++++++++++++++++
 include/driver.h                     |  3 +++
 include/fs.h                         |  4 ++++
 include/globalvar.h                  | 19 ++++++++++++++++++
 include/linux/mtd/ubi.h              |  1 +
 14 files changed, 166 insertions(+), 1 deletion(-)

_______________________________________________
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/6] Add globalvar_add_simple_string function
  2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
@ 2015-06-18  7:43 ` Sascha Hauer
  2015-06-18  7:43 ` [PATCH 2/6] cdev: Add partuuid string to struct cdev Sascha Hauer
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

This adds a globalvar string function to pass a pointer to a string.
With this we can directly access the string to get the variable and
don't have to getenv() the string first.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/globalvar.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/globalvar.h b/include/globalvar.h
index 8b2caf1..6e10956 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -17,6 +17,20 @@ int globalvar_add(const char *name,
 char *globalvar_get_match(const char *match, const char *separator);
 void globalvar_set_match(const char *match, const char *val);
 
+static inline int globalvar_add_simple_string(const char *name,
+		char **value)
+{
+	struct param_d *p;
+
+	p = dev_add_param_string(&global_device, name, NULL, NULL,
+		value, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
 static inline int globalvar_add_simple_int(const char *name,
 		int *value, const char *format)
 {
@@ -85,6 +99,11 @@ static inline int globalvar_add_simple(const char *name, const char *value)
 	return 0;
 }
 
+static inline int globalvar_add_simple_string(const char *name, char **value)
+{
+	return 0;
+}
+
 static inline int globalvar_add_simple_int(const char *name,
 		int *value, const char *format)
 {
-- 
2.1.4


_______________________________________________
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/6] cdev: Add partuuid string to struct cdev
  2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
  2015-06-18  7:43 ` [PATCH 1/6] Add globalvar_add_simple_string function Sascha Hauer
@ 2015-06-18  7:43 ` Sascha Hauer
  2015-06-18  7:43 ` [PATCH 3/6] fs: Add device parameter for Linux root= option Sascha Hauer
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

This adds the partuuid string to struct cdev in order to have this
available for constructing a suitable Linux root=PARTUUID= option
for booting Linux.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/partitions.c        | 1 +
 common/partitions/dos.c    | 4 ++++
 common/partitions/parser.h | 1 +
 include/driver.h           | 3 +++
 4 files changed, 9 insertions(+)

diff --git a/common/partitions.c b/common/partitions.c
index 37d9cb7..4f50bfe 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -64,6 +64,7 @@ static int register_one_partition(struct block_device *blk,
 	}
 
 	cdev->dos_partition_type = part->dos_partition_type;
+	strcpy(cdev->partuuid, part->partuuid);
 
 	free(partition_name);
 
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 37addfd..e0cb356 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -185,6 +185,7 @@ static void dos_partition(void *buf, struct block_device *blk,
 	uint8_t *buffer = buf;
 	int i;
 	struct disk_signature_priv *dsp;
+	uint32_t signature = get_unaligned_le32(buf + 0x1b8);
 
 	table = (struct partition_entry *)&buffer[446];
 
@@ -202,6 +203,9 @@ static void dos_partition(void *buf, struct block_device *blk,
 			pd->parts[n].first_sec = pentry.first_sec;
 			pd->parts[n].size = pentry.size;
 			pd->parts[n].dos_partition_type = pentry.dos_partition_type;
+			if (signature)
+				sprintf(pd->parts[n].partuuid, "%08x-%02d",
+						signature, i + 1);
 			pd->used_entries++;
 			/*
 			 * Partitions of type 0x05 and 0x0f (and some more)
diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index 8d39452..8ad134a 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -17,6 +17,7 @@
 struct partition {
 	char name[MAX_PARTITION_NAME];
 	u8 dos_partition_type;
+	char partuuid[MAX_PARTUUID_STR];
 	uint64_t first_sec;
 	uint64_t size;
 };
diff --git a/include/driver.h b/include/driver.h
index d0cdcc9..9c60054 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -435,6 +435,8 @@ struct file_operations {
 	int (*memmap)(struct cdev*, void **map, int flags);
 };
 
+#define MAX_PARTUUID_STR	sizeof("00112233-4455-6677-8899-AABBCCDDEEFF")
+
 struct cdev {
 	struct file_operations *ops;
 	void *priv;
@@ -445,6 +447,7 @@ struct cdev {
 	char *partname; /* the partition name, usually the above without the
 			 * device part, i.e. name = "nand0.barebox" -> partname = "barebox"
 			 */
+	char partuuid[MAX_PARTUUID_STR];
 	loff_t offset;
 	loff_t size;
 	unsigned int flags;
-- 
2.1.4


_______________________________________________
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/6] fs: Add device parameter for Linux root= option
  2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
  2015-06-18  7:43 ` [PATCH 1/6] Add globalvar_add_simple_string function Sascha Hauer
  2015-06-18  7:43 ` [PATCH 2/6] cdev: Add partuuid string to struct cdev Sascha Hauer
@ 2015-06-18  7:43 ` Sascha Hauer
  2015-06-18  7:43 ` [PATCH 4/6] fs: ubifs: Implement Linux rootarg Sascha Hauer
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

When registering a filesystem device add a device parameter suitable
for the Linux root= option to boot from exactly this filesystem. Currently
the fs layer sets this parameter to the root=PARTUUID= mechanism if a
partuuid is available. Other filesystems like NFS and UBIFS which do
not have a PARTUUID can overwrite this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c      | 37 +++++++++++++++++++++++++++++++++++++
 include/fs.h |  4 ++++
 2 files changed, 41 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index c249f84..67c78cd 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1298,6 +1298,12 @@ int mount(const char *device, const char *fsname, const char *_path,
 		goto err_no_driver;
 	}
 
+	if (!fsdev->linux_rootarg && fsdev->cdev && fsdev->cdev->partuuid[0] != 0) {
+		char *str = asprintf("root=PARTUUID=%s", fsdev->cdev->partuuid);
+
+		fsdev_set_linux_rootarg(fsdev, str);
+	}
+
 	return 0;
 
 err_no_driver:
@@ -1708,3 +1714,34 @@ void mount_all(void)
 			cdev_mount_default(cdev, NULL);
 	}
 }
+
+void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str)
+{
+	fsdev->linux_rootarg = xstrdup(str);
+
+	dev_add_param_fixed(&fsdev->dev, "linux.bootargs", fsdev->linux_rootarg);
+}
+
+/**
+ * path_get_linux_rootarg() - Given a path return a suitable root= option for
+ *                            Linux
+ * @path: The path
+ *
+ * Return: A string containing the root= option or an ERR_PTR. the returned
+ *         string must be freed by the caller.
+ */
+char *path_get_linux_rootarg(const char *path)
+{
+	struct fs_device_d *fsdev;
+	const char *str;
+
+	fsdev = get_fsdevice_by_path(path);
+	if (!fsdev)
+		return ERR_PTR(-EINVAL);
+
+	str = dev_get_param(&fsdev->dev, "linux.bootargs");
+	if (!str)
+		return ERR_PTR(-ENOSYS);
+
+	return xstrdup(str);
+}
diff --git a/include/fs.h b/include/fs.h
index f95464d..ee7e48b 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -100,6 +100,7 @@ struct fs_device_d {
 	struct device_d *parent_device;
 	struct list_head list;
 	char *options;
+	char *linux_rootarg;
 };
 
 #define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
@@ -189,4 +190,7 @@ const char *cdev_get_mount_path(struct cdev *cdev);
 const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions);
 void mount_all(void);
 
+void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str);
+char *path_get_linux_rootarg(const char *path);
+
 #endif /* __FS_H */
-- 
2.1.4


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

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

* [PATCH 4/6] fs: ubifs: Implement Linux rootarg
  2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
                   ` (2 preceding siblings ...)
  2015-06-18  7:43 ` [PATCH 3/6] fs: Add device parameter for Linux root= option Sascha Hauer
@ 2015-06-18  7:43 ` Sascha Hauer
  2015-06-18  7:43 ` [PATCH 5/6] fs: nfs: " Sascha Hauer
  2015-06-18  7:43 ` [PATCH 6/6] blspec: Automatically append rootarg Sascha Hauer
  5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

Add the parameter to boot from ubifs fileystems. This assumes that
there will be only one UBI device registered in the kernel, otherwise
there is no way to predict the ubi number.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/ubi/kapi.c  |  1 +
 fs/ubifs/ubifs.c        | 23 +++++++++++++++++++++++
 include/linux/mtd/ubi.h |  1 +
 3 files changed, 25 insertions(+)

diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 08cb8dd..7fc1aa8 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -36,6 +36,7 @@ void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di)
 	di->min_io_size = ubi->min_io_size;
 	di->max_write_size = ubi->max_write_size;
 	di->ro_mode = ubi->ro_mode;
+	di->mtd = ubi->mtd;
 }
 EXPORT_SYMBOL_GPL(ubi_do_get_device_info);
 
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 68d90b3..a9189f7 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -36,6 +36,7 @@
 #include <linux/zlib.h>
 #include <xfuncs.h>
 #include <fcntl.h>
+#include <linux/mtd/mtd.h>
 
 #include "ubifs.h"
 
@@ -584,6 +585,26 @@ static int ubifs_readlink(struct device_d *dev, const char *pathname, char *buf,
 	return 0;
 }
 
+static void ubifs_set_rootarg(struct ubifs_priv *priv, struct fs_device_d *fsdev)
+{
+	struct ubi_volume_info vi = {};
+	struct ubi_device_info di = {};
+	struct mtd_info *mtd;
+	char *str;
+
+	ubi_get_volume_info(priv->ubi, &vi);
+	ubi_get_device_info(vi.ubi_num, &di);
+
+	mtd = di.mtd;
+
+	str = asprintf("root=ubi0:%s ubi.mtd=%s rootfstype=ubifs",
+			vi.name, mtd->cdev.partname);
+
+	fsdev_set_linux_rootarg(fsdev, str);
+
+	free(str);
+}
+
 static int ubifs_probe(struct device_d *dev)
 {
 	struct fs_device_d *fsdev = dev_to_fs_device(dev);
@@ -612,6 +633,8 @@ static int ubifs_probe(struct device_d *dev)
 		goto err;
 	}
 
+	ubifs_set_rootarg(priv, fsdev);
+
 	return 0;
 err:
 	ubi_close_volume(priv->ubi);
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index 274ec4e..0614681 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -154,6 +154,7 @@ struct ubi_device_info {
 	int max_write_size;
 	int ro_mode;
 	dev_t cdev;
+	struct mtd_info *mtd;
 };
 
 /*
-- 
2.1.4


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

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

* [PATCH 5/6] fs: nfs: Implement Linux rootarg
  2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
                   ` (3 preceding siblings ...)
  2015-06-18  7:43 ` [PATCH 4/6] fs: ubifs: Implement Linux rootarg Sascha Hauer
@ 2015-06-18  7:43 ` Sascha Hauer
  2015-06-18  7:43 ` [PATCH 6/6] blspec: Automatically append rootarg Sascha Hauer
  5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

Add the root= parameter for NFS filesystems. We currently hardcode
v3 and tcp which probably needs to become configurable at some point.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/filesystems/nfs.rst | 13 +++++++++++++
 fs/nfs.c                          | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/Documentation/filesystems/nfs.rst b/Documentation/filesystems/nfs.rst
index f4eda5d..4469ac1 100644
--- a/Documentation/filesystems/nfs.rst
+++ b/Documentation/filesystems/nfs.rst
@@ -10,3 +10,16 @@ barebox has readonly support for NFSv3 in UDP mode.
 Example::
 
    mount -t nfs 192.168.23.4:/home/user/nfsroot /mnt/nfs
+
+The barebox NFS driver adds a ``linux.bootargs`` device parameter to the NFS device.
+This parameter holds a Linux kernel commandline snippet containing a suitable root=
+option for booting from exactly that NFS share.
+
+Example::
+
+  devinfo nfs0
+  ...
+  linux.bootargs: root=/dev/nfs nfsroot=192.168.23.4:/home/sha/nfsroot/generic-v7,v3,tcp
+
+The options default to ``v3,tcp`` but can be adjusted before mounting the NFS share with
+the ``global.linux.rootnfsopts`` variable
diff --git a/fs/nfs.c b/fs/nfs.c
index 2738c78..5bff54a 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -35,6 +35,7 @@
 #include <kfifo.h>
 #include <linux/sizes.h>
 #include <byteorder.h>
+#include <globalvar.h>
 
 #include "parseopt.h"
 
@@ -1306,6 +1307,23 @@ static int nfs_stat(struct device_d *dev, const char *filename, struct stat *s)
 	}
 }
 
+static char *rootnfsopts;
+
+static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev)
+{
+	char *str;
+	const char *ip;
+
+	ip = ip_to_string(npriv->server);
+	str = asprintf("root=/dev/nfs nfsroot=%s:%s%s%s",
+			ip, npriv->path, rootnfsopts[0] ? "," : "",
+			rootnfsopts);
+
+	fsdev_set_linux_rootarg(fsdev, str);
+
+	free(str);
+}
+
 static int nfs_probe(struct device_d *dev)
 {
 	struct fs_device_d *fsdev = dev_to_fs_device(dev);
@@ -1369,6 +1387,8 @@ static int nfs_probe(struct device_d *dev)
 		goto err2;
 	}
 
+	nfs_set_rootarg(npriv, fsdev);
+
 	free(tmp);
 
 	return 0;
@@ -1421,6 +1441,10 @@ static struct fs_driver_d nfs_driver = {
 
 static int nfs_init(void)
 {
+	rootnfsopts = xstrdup("v3,tcp");
+
+	globalvar_add_simple_string("linux.rootnfsopts", &rootnfsopts);
+
 	return register_fs_driver(&nfs_driver);
 }
 coredevice_initcall(nfs_init);
-- 
2.1.4


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

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

* [PATCH 6/6] blspec: Automatically append rootarg
  2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
                   ` (4 preceding siblings ...)
  2015-06-18  7:43 ` [PATCH 5/6] fs: nfs: " Sascha Hauer
@ 2015-06-18  7:43 ` Sascha Hauer
  2015-06-30  7:26   ` Marc Kleine-Budde
  5 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2015-06-18  7:43 UTC (permalink / raw)
  To: Barebox List

This patch makes it possible to automatically add a suitable root= option
for booting Linux from the same filesystem on which the bootspec entry
has been found. This adds an additional 'linux-appendroot' option to
bootspec which if set to 'true' will cause barebox to automatically
add a root= option. This currently works for NFS, UBIFS and regular
block devices like ATA, SD/MMC using the root=PARTUUID= mechanism.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/user/booting-linux.rst |  7 +++++++
 common/blspec.c                      | 29 ++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
index 6e7d155..39084e5 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -205,6 +205,13 @@ compatible NFS URI string must be passed to the boot command:
 
   boot nfs://nfshost//path/
 
+Additionally to the options defined in the original spec barebox understands the
+``linux-appendroot`` option. This is a boolean value and if set to ``true`` barebox
+will automatically append a ``root=`` string to the Linux commandline based on the
+device where the entry is found on. This makes it possible to use the same rootfs
+image on different devices without having to specify a different root= option each
+time.
+
 Network boot
 ------------
 
diff --git a/common/blspec.c b/common/blspec.c
index 3506388..742065e 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -601,6 +601,29 @@ 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, strerror(-PTR_ERR(rootarg)));
+		return PTR_ERR(rootarg);
+	}
+
+	globalvar_add_simple("linux.bootargs.dyn.blspec.appendroot", rootarg);
+
+	free(rootarg);
+
+	return 0;
+}
+
 /*
  * blspec_boot - boot an entry
  *
@@ -650,6 +673,10 @@ 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;
+
 	pr_info("booting %s from %s\n", blspec_entry_var_get(entry, "title"),
 			entry->cdev ? dev_name(entry->cdev->dev) : "none");
 
@@ -668,7 +695,7 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
 	ret = bootm_boot(&data);
 	if (ret)
 		pr_err("Booting failed\n");
-
+err_out:
 	free((char *)data.oftree_file);
 	free((char *)data.initrd_file);
 	free((char *)data.os_file);
-- 
2.1.4


_______________________________________________
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 6/6] blspec: Automatically append rootarg
  2015-06-18  7:43 ` [PATCH 6/6] blspec: Automatically append rootarg Sascha Hauer
@ 2015-06-30  7:26   ` Marc Kleine-Budde
  2015-07-01  6:58     ` Sascha Hauer
  0 siblings, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2015-06-30  7:26 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List


[-- Attachment #1.1: Type: text/plain, Size: 3628 bytes --]

On 06/18/2015 09:43 AM, Sascha Hauer wrote:
> This patch makes it possible to automatically add a suitable root= option
> for booting Linux from the same filesystem on which the bootspec entry
> has been found. This adds an additional 'linux-appendroot' option to
> bootspec which if set to 'true' will cause barebox to automatically
> add a root= option. This currently works for NFS, UBIFS and regular
> block devices like ATA, SD/MMC using the root=PARTUUID= mechanism.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  Documentation/user/booting-linux.rst |  7 +++++++
>  common/blspec.c                      | 29 ++++++++++++++++++++++++++++-
>  2 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
> index 6e7d155..39084e5 100644
> --- a/Documentation/user/booting-linux.rst
> +++ b/Documentation/user/booting-linux.rst
> @@ -205,6 +205,13 @@ compatible NFS URI string must be passed to the boot command:
>  
>    boot nfs://nfshost//path/
>  
> +Additionally to the options defined in the original spec barebox understands the
> +``linux-appendroot`` option. This is a boolean value and if set to ``true`` barebox
> +will automatically append a ``root=`` string to the Linux commandline based on the
> +device where the entry is found on. This makes it possible to use the same rootfs
> +image on different devices without having to specify a different root= option each
> +time.
> +
>  Network boot
>  ------------
>  
> diff --git a/common/blspec.c b/common/blspec.c
> index 3506388..742065e 100644
> --- a/common/blspec.c
> +++ b/common/blspec.c
> @@ -601,6 +601,29 @@ 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;
> +

Can you move the following into a separate function outside of blspec.c
so that it can be used somewhere else, too?

> +	rootarg = path_get_linux_rootarg(entry->rootpath);
> +	if (IS_ERR(rootarg)) {
> +		pr_err("Getting root argument for %s failed with: %s\n",
> +				entry->rootpath, strerror(-PTR_ERR(rootarg)));
> +		return PTR_ERR(rootarg);
> +	}
> +
> +	globalvar_add_simple("linux.bootargs.dyn.blspec.appendroot", rootarg);
> +
> +	free(rootarg);
> +
> +	return 0;
> +}
> +
>  /*
>   * blspec_boot - boot an entry
>   *
> @@ -650,6 +673,10 @@ 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;
> +
>  	pr_info("booting %s from %s\n", blspec_entry_var_get(entry, "title"),
>  			entry->cdev ? dev_name(entry->cdev->dev) : "none");
>  
> @@ -668,7 +695,7 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
>  	ret = bootm_boot(&data);
>  	if (ret)
>  		pr_err("Booting failed\n");
> -
> +err_out:
>  	free((char *)data.oftree_file);
>  	free((char *)data.initrd_file);
>  	free((char *)data.os_file);
> 

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
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 6/6] blspec: Automatically append rootarg
  2015-06-30  7:26   ` Marc Kleine-Budde
@ 2015-07-01  6:58     ` Sascha Hauer
  2015-07-01  7:22       ` Marc Kleine-Budde
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2015-07-01  6:58 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: Barebox List

On Tue, Jun 30, 2015 at 09:26:58AM +0200, Marc Kleine-Budde wrote:
> On 06/18/2015 09:43 AM, Sascha Hauer wrote:
> > This patch makes it possible to automatically add a suitable root= option
> > for booting Linux from the same filesystem on which the bootspec entry
> > has been found. This adds an additional 'linux-appendroot' option to
> > bootspec which if set to 'true' will cause barebox to automatically
> > add a root= option. This currently works for NFS, UBIFS and regular
> > block devices like ATA, SD/MMC using the root=PARTUUID= mechanism.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  Documentation/user/booting-linux.rst |  7 +++++++
> >  common/blspec.c                      | 29 ++++++++++++++++++++++++++++-
> >  2 files changed, 35 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
> > index 6e7d155..39084e5 100644
> > --- a/Documentation/user/booting-linux.rst
> > +++ b/Documentation/user/booting-linux.rst
> > @@ -205,6 +205,13 @@ compatible NFS URI string must be passed to the boot command:
> >  
> >    boot nfs://nfshost//path/
> >  
> > +Additionally to the options defined in the original spec barebox understands the
> > +``linux-appendroot`` option. This is a boolean value and if set to ``true`` barebox
> > +will automatically append a ``root=`` string to the Linux commandline based on the
> > +device where the entry is found on. This makes it possible to use the same rootfs
> > +image on different devices without having to specify a different root= option each
> > +time.
> > +
> >  Network boot
> >  ------------
> >  
> > diff --git a/common/blspec.c b/common/blspec.c
> > index 3506388..742065e 100644
> > --- a/common/blspec.c
> > +++ b/common/blspec.c
> > @@ -601,6 +601,29 @@ 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;
> > +
> 
> Can you move the following into a separate function outside of blspec.c
> so that it can be used somewhere else, too?
> 
> > +	rootarg = path_get_linux_rootarg(entry->rootpath);
> > +	if (IS_ERR(rootarg)) {
> > +		pr_err("Getting root argument for %s failed with: %s\n",
> > +				entry->rootpath, strerror(-PTR_ERR(rootarg)));
> > +		return PTR_ERR(rootarg);
> > +	}
> > +
> > +	globalvar_add_simple("linux.bootargs.dyn.blspec.appendroot", rootarg);
> > +
> > +	free(rootarg);
> > +
> > +	return 0;
> > +}

You mean the combination of path_get_linux_rootarg() and globalvar_add_simple()
should be a separate function? I'm not sure. Once we see a usecase for
this we can do this.

Hm, just thinking. We could create a barebox command which takes a
barebox device as argument and sets a linux.bootargs.* variable to the
corresponding root= snippet. This might be useful.

Sascha

-- 
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 6/6] blspec: Automatically append rootarg
  2015-07-01  6:58     ` Sascha Hauer
@ 2015-07-01  7:22       ` Marc Kleine-Budde
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2015-07-01  7:22 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List


[-- Attachment #1.1: Type: text/plain, Size: 1381 bytes --]

On 07/01/2015 08:58 AM, Sascha Hauer wrote:
>> Can you move the following into a separate function outside of blspec.c
>> so that it can be used somewhere else, too?
>>
>>> +	rootarg = path_get_linux_rootarg(entry->rootpath);
>>> +	if (IS_ERR(rootarg)) {
>>> +		pr_err("Getting root argument for %s failed with: %s\n",
>>> +				entry->rootpath, strerror(-PTR_ERR(rootarg)));
>>> +		return PTR_ERR(rootarg);
>>> +	}
>>> +
>>> +	globalvar_add_simple("linux.bootargs.dyn.blspec.appendroot", rootarg);
>>> +
>>> +	free(rootarg);
>>> +
>>> +	return 0;
>>> +}
> 
> You mean the combination of path_get_linux_rootarg() and globalvar_add_simple()
> should be a separate function? I'm not sure. Once we see a usecase for
> this we can do this.

I've the fit image support pachtes here. They use this functionality.

> Hm, just thinking. We could create a barebox command which takes a
> barebox device as argument and sets a linux.bootargs.* variable to the
> corresponding root= snippet. This might be useful.

Sounds nice - however I don't use the shell in that procject :D

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
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:[~2015-07-01  7:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18  7:43 Bootspec: Allow to automatically append root= option Sascha Hauer
2015-06-18  7:43 ` [PATCH 1/6] Add globalvar_add_simple_string function Sascha Hauer
2015-06-18  7:43 ` [PATCH 2/6] cdev: Add partuuid string to struct cdev Sascha Hauer
2015-06-18  7:43 ` [PATCH 3/6] fs: Add device parameter for Linux root= option Sascha Hauer
2015-06-18  7:43 ` [PATCH 4/6] fs: ubifs: Implement Linux rootarg Sascha Hauer
2015-06-18  7:43 ` [PATCH 5/6] fs: nfs: " Sascha Hauer
2015-06-18  7:43 ` [PATCH 6/6] blspec: Automatically append rootarg Sascha Hauer
2015-06-30  7:26   ` Marc Kleine-Budde
2015-07-01  6:58     ` Sascha Hauer
2015-07-01  7:22       ` Marc Kleine-Budde

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