mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse
@ 2022-08-15 11:48 Ahmad Fatoum
  2022-08-15 11:48 ` [PATCH 2/2] common: bootm: reuse cdev_get_linux_rootarg() Ahmad Fatoum
  2022-08-16  8:26 ` [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-08-15 11:48 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We've the root=PARTUUID=%s generation at two places: Once to populate
fsdev->linux_rootarg and once to handle struct bootm_data::root_dev.

In preparation for dropping the duplicate out-of-sync code in the bootm
code, export the originl fs/fs.c code as cdev_get_linux_rootarg().

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c      | 50 +++++++++++++++++++++++++++++++++++---------------
 include/fs.h |  1 +
 2 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index bd6f144742ac..620cd6597a63 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2876,12 +2876,23 @@ int popd(char *oldcwd)
 	return ret;
 }
 
-static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
+static bool cdev_partname_equal(const struct cdev *a,
+				const struct cdev *b)
 {
-	struct cdev *cdevm, *cdev;
+	return a->partname && b->partname &&
+		!strcmp(a->partname, b->partname);
+}
+
+static char *get_linux_mmcblkdev(const struct cdev *root_cdev)
+{
+	struct cdev *cdevm = root_cdev->master, *cdev;
 	int id, partnum;
 
-	cdevm = fsdev->cdev->master;
+	if (!IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG))
+		return NULL;
+	if (!cdevm || !cdev_is_mci_main_part_dev(cdevm))
+		return NULL;
+
 	id = of_alias_get_id(cdevm->device_node, "mmc");
 	if (id < 0)
 		return NULL;
@@ -2894,8 +2905,7 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
 		 * in the partitions list so we need to count it instead of
 		 * skipping it.
 		 */
-		if (cdev->partname &&
-		    !strcmp(cdev->partname, fsdev->cdev->partname))
+		if (cdev_partname_equal(root_cdev, cdev))
 			return basprintf("root=/dev/mmcblk%dp%d", id, partnum);
 		partnum++;
 	}
@@ -2903,6 +2913,23 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
 	return NULL;
 }
 
+char *cdev_get_linux_rootarg(const struct cdev *cdev)
+{
+	char *str;
+
+	if (!cdev)
+		return NULL;
+
+	str = get_linux_mmcblkdev(cdev);
+	if (str)
+		return str;
+
+	if (cdev->uuid[0] != 0)
+		return basprintf("root=PARTUUID=%s", cdev->uuid);
+
+	return NULL;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -2991,17 +3018,10 @@ int mount(const char *device, const char *fsname, const char *pathname,
 
 	fsdev->vfsmount.mnt_root = fsdev->sb.s_root;
 
-	if (!fsdev->linux_rootarg && fsdev->cdev) {
-		char *str = NULL;
-
-		if (IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG) &&
-		    fsdev->cdev->master &&
-		    cdev_is_mci_main_part_dev(fsdev->cdev->master))
-			str = get_linux_mmcblkdev(fsdev);
-
-		if (!str && fsdev->cdev->uuid[0] != 0)
-			str = basprintf("root=PARTUUID=%s", fsdev->cdev->uuid);
+	if (!fsdev->linux_rootarg) {
+		char *str;
 
+		str = cdev_get_linux_rootarg(fsdev->cdev);
 		if (str)
 			fsdev_set_linux_rootarg(fsdev, str);
 	}
diff --git a/include/fs.h b/include/fs.h
index cd5eb571e08e..894cae3e4c2f 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -168,6 +168,7 @@ 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);
+char *cdev_get_linux_rootarg(const struct cdev *cdev);
 
 static inline const char *devpath_to_name(const char *devpath)
 {
-- 
2.30.2




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

end of thread, other threads:[~2022-08-16  8:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 11:48 [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Ahmad Fatoum
2022-08-15 11:48 ` [PATCH 2/2] common: bootm: reuse cdev_get_linux_rootarg() Ahmad Fatoum
2022-08-16  8:26 ` [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Sascha Hauer

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