mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/3] fs: add linux_rootarg 'root=mmcblkXpN' support
Date: Thu,  6 May 2021 13:22:19 +0200	[thread overview]
Message-ID: <20210506112219.27114-3-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20210506112219.27114-1-m.felsch@pengutronix.de>

Since commit fa2d0aa96941 ("mmc: core: Allow setting slot index via
device tree alias") the kernel supports stable mmc device names. Since
the barebox mmc device names matches the one from the kernel we can pass
the 'root=mmcblkXpN' argument on commandline to refer to the correct
boot medium.

This patch adds the support to store the above commandline as
linux_rootarg if enabled. Use the partuuid as fallback since it is not
as unique as the mmcblkXpN scheme. Add a own build option since the
system integrator needs to check if the used kernel contains the above
commit.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Hi all,

I know that:
8<-----------------
+		if (!str && fsdev->cdev->partuuid[0] != 0)
+			str = basprintf("root=PARTUUID=%s", fsdev->cdev->partuuid);
8<-----------------
is longer than 80char but for the sake of readability I kept that
oneliner. Should we update checkpatch accordingly to match the new linux
rule?

Regards,
  Marco


 common/Kconfig | 15 +++++++++++++++
 fs/fs.c        | 48 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 6b3c1701be..a09a1d9456 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -700,6 +700,21 @@ config FLEXIBLE_BOOTARGS
 	  to replace parts of the bootargs string without reconstructing it
 	  completely.
 
+config MMCBLKDEV_ROOTARG
+	bool
+	prompt "Support 'root=mmcblkXpN' cmdline appending"
+	help
+	  Enable this option to append 'root=mmcblkXpN' to the kernel cmdline
+	  instead of 'root=PARTUUID=XYZ'. Don't enale this option if your used
+	  kernel don't contain commit [1].
+
+	  The appending only happen if barebox 'linux.bootargs.bootm.appendroot'
+	  variable is set or the used blspec entry contains 'linux-appendroot'.
+
+	  [1] fa2d0aa96941 ("mmc: core: Allow setting slot index via device tree
+	      alias")
+
+
 config BAREBOX_UPDATE
 	bool "In-system barebox update infrastructure"
 
diff --git a/fs/fs.c b/fs/fs.c
index 881dc2fca0..8ee1e7febe 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2831,6 +2831,39 @@ out:
 }
 EXPORT_SYMBOL(chdir);
 
+static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
+{
+	struct cdev *cdevm, *cdev;
+	int id, partnum;
+	bool found = false;
+
+	cdevm = fsdev->cdev->master;
+	id = of_alias_get_id(cdevm->device_node, "mmc");
+	if (id < 0)
+		return NULL;
+
+	partnum = 1; /* linux partitions are 1 based */
+	list_for_each_entry(cdev, &cdevm->partitions, partition_entry) {
+
+		/*
+		 * Partname is not guaranteed but this partition cdev is listed
+		 * in the partitions list so we need to count it instead of
+		 * skipping it.
+		 */
+		if (cdev->partname &&
+		    !strcmp(cdev->partname, fsdev->cdev->partname)) {
+			found = true;
+			break;
+		}
+		partnum++;
+	}
+
+	if (!found)
+		return NULL;
+
+	return basprintf("root=/dev/mmcblk%dp%d", id, partnum);
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -2919,11 +2952,18 @@ 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 && fsdev->cdev->partuuid[0] != 0) {
-		char *str = basprintf("root=PARTUUID=%s",
-					fsdev->cdev->partuuid);
+	if (!fsdev->linux_rootarg && fsdev->cdev) {
+		char *str = NULL;
+
+		if (IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG) &&
+		    cdev_is_mci_dev(fsdev->cdev->master))
+			str = get_linux_mmcblkdev(fsdev);
+
+		if (!str && fsdev->cdev->partuuid[0] != 0)
+			str = basprintf("root=PARTUUID=%s", fsdev->cdev->partuuid);
 
-		fsdev_set_linux_rootarg(fsdev, str);
+		if (str)
+			fsdev_set_linux_rootarg(fsdev, str);
 	}
 
 	path_put(&path);
-- 
2.29.2


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


  parent reply	other threads:[~2021-05-06 11:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 11:22 [PATCH 1/3] driver: add flag to check if cdev is an mci device Marco Felsch
2021-05-06 11:22 ` [PATCH 2/3] mci: mci-core: set the DEVFS_IS_MCI_DEV flag Marco Felsch
2021-05-06 12:06   ` Ahmad Fatoum
2021-05-06 13:07     ` Marco Felsch
2021-05-06 13:10       ` Ahmad Fatoum
2021-05-06 11:22 ` Marco Felsch [this message]
2021-05-06 12:19   ` [PATCH 3/3] fs: add linux_rootarg 'root=mmcblkXpN' support Ahmad Fatoum
2021-05-06 13:30     ` Marco Felsch
2021-05-06 11:59 ` [PATCH 1/3] driver: add flag to check if cdev is an mci device Ahmad Fatoum
2021-05-06 13:08   ` Marco Felsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210506112219.27114-3-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox