mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3 1/3] driver: add flag to check if cdev is an mci device
@ 2021-05-10 10:25 Marco Felsch
  2021-05-10 10:25 ` [PATCH v3 2/3] mci: mci-core: set the DEVFS_IS_MCI_MAIN_PART_DEV flag Marco Felsch
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marco Felsch @ 2021-05-10 10:25 UTC (permalink / raw)
  To: barebox

We need this during mount() to check if the cdev is an mmc/mci main|user
hardware partition device. Later on we add the feature to pass
"root=/dev/mmcblkXpN" as kernel command line.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
v3:
- no changes

v2:
- dropped the !!
- renamed the flag due to v1 comments
- renamed the function to

 include/driver.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/driver.h b/include/driver.h
index 0d43b36148..d84fe35d50 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -496,6 +496,7 @@ int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset);
 #define DEVFS_PARTITION_READONLY	(1U << 1)
 #define DEVFS_IS_CHARACTER_DEV		(1U << 3)
 #define DEVFS_PARTITION_FROM_TABLE	(1U << 4)
+#define DEVFS_IS_MCI_MAIN_PART_DEV	(1U << 5)
 
 struct cdev *devfs_add_partition(const char *devname, loff_t offset,
 		loff_t size, unsigned int flags, const char *name);
@@ -509,6 +510,11 @@ static inline void cdev_create_default_automount(struct cdev *cdev)
 }
 #endif
 
+static inline bool cdev_is_mci_main_part_dev(struct cdev *cdev)
+{
+	return cdev->flags & DEVFS_IS_MCI_MAIN_PART_DEV;
+}
+
 #define DEVFS_PARTITION_APPEND		0
 
 /**
-- 
2.29.2


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


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

* [PATCH v3 2/3] mci: mci-core: set the DEVFS_IS_MCI_MAIN_PART_DEV flag
  2021-05-10 10:25 [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Marco Felsch
@ 2021-05-10 10:25 ` Marco Felsch
  2021-05-10 10:25 ` [PATCH v3 3/3] fs: add linux_rootarg 'root=mmcblkXpN' support Marco Felsch
  2021-05-12  5:25 ` [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Marco Felsch @ 2021-05-10 10:25 UTC (permalink / raw)
  To: barebox

Set the new introduced flag to be able to check if the cdev is an
mmc/mci device.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
v3:
- no changes

v2:
- only set the flag for MMC_BLK_DATA_AREA_MAIN

 drivers/mci/mci-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 017f25d35f..a160b98894 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -426,8 +426,10 @@ static void mci_part_add(struct mci *mci, uint64_t size,
 	part->part_cfg = part_cfg;
 	part->idx = idx;
 
-	if (area_type == MMC_BLK_DATA_AREA_MAIN)
+	if (area_type == MMC_BLK_DATA_AREA_MAIN) {
 		part->blk.cdev.device_node = mci->host->hw_dev->device_node;
+		part->blk.cdev.flags |= DEVFS_IS_MCI_MAIN_PART_DEV;
+	}
 
 	mci->nr_parts++;
 }
-- 
2.29.2


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


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

* [PATCH v3 3/3] fs: add linux_rootarg 'root=mmcblkXpN' support
  2021-05-10 10:25 [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Marco Felsch
  2021-05-10 10:25 ` [PATCH v3 2/3] mci: mci-core: set the DEVFS_IS_MCI_MAIN_PART_DEV flag Marco Felsch
@ 2021-05-10 10:25 ` Marco Felsch
  2021-05-12  5:25 ` [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Marco Felsch @ 2021-05-10 10:25 UTC (permalink / raw)
  To: barebox

Since commit fa2d0aa96941 ("mmc: core: Allow setting slot index via
device tree alias") the linux kernel supports stable mmc device names.
Barebox has stable names since years so now we can connect both which
allows us to pass 'root=mmcblkXpN' as argument for the cmdline. Note: it
is crucial that the kernel device tree and the barebox device tree uses
the same mmc aliases.

This patch adds the support to store the above cmdline as linux_rootarg
if enabled. The partuuid is now used as fallback since it is not as
unique as the mmcblkXpN scheme. It is added as 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>
---
v3:
- fix Kconfig spelling
- check if cdev has an master (cdev->master) before accessing it.

v2:
- improved Kconfig deps
- improved Kconfig help message
- minimal get_linux_mmcblkdev() simplifications

 common/Kconfig | 21 +++++++++++++++++++++
 fs/fs.c        | 43 +++++++++++++++++++++++++++++++++++++++----
 2 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 6b3c1701be..db7cc6713a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -700,6 +700,27 @@ config FLEXIBLE_BOOTARGS
 	  to replace parts of the bootargs string without reconstructing it
 	  completely.
 
+config MMCBLKDEV_ROOTARG
+	bool
+	prompt "Support 'root=mmcblkXpN' cmdline appending"
+	depends on FLEXIBLE_BOOTARGS
+	depends on MCI
+	depends on OFTREE
+	help
+	  Enable this option to append 'root=mmcblkXpN' to the cmdline instead
+	  of 'root=PARTUUID=XYZ'. Don't enable this option if your used linux
+	  kernel doesn't contain commit [1]. The first linux kernel release
+	  containing that commit is v5.10-rc1.
+
+	  The appending only happen if barebox 'linux.bootargs.bootm.appendroot'
+	  variable is set or the used blspec entry contains 'linux-appendroot'.
+
+	  Note: It is crucial that the kernel device tree and the barebox device
+	  tree uses the same mmc aliases.
+
+	  [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..6d952a18b1 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2831,6 +2831,33 @@ out:
 }
 EXPORT_SYMBOL(chdir);
 
+static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
+{
+	struct cdev *cdevm, *cdev;
+	int id, partnum;
+
+	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))
+			return basprintf("root=/dev/mmcblk%dp%d", id, partnum);
+		partnum++;
+	}
+
+	return NULL;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -2919,11 +2946,19 @@ 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) &&
+		    fsdev->cdev->master &&
+		    cdev_is_mci_main_part_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


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

* Re: [PATCH v3 1/3] driver: add flag to check if cdev is an mci device
  2021-05-10 10:25 [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Marco Felsch
  2021-05-10 10:25 ` [PATCH v3 2/3] mci: mci-core: set the DEVFS_IS_MCI_MAIN_PART_DEV flag Marco Felsch
  2021-05-10 10:25 ` [PATCH v3 3/3] fs: add linux_rootarg 'root=mmcblkXpN' support Marco Felsch
@ 2021-05-12  5:25 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-05-12  5:25 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

On Mon, May 10, 2021 at 12:25:21PM +0200, Marco Felsch wrote:
> We need this during mount() to check if the cdev is an mmc/mci main|user
> hardware partition device. Later on we add the feature to pass
> "root=/dev/mmcblkXpN" as kernel command line.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---

Applied, thanks

Sascha

> v3:
> - no changes
> 
> v2:
> - dropped the !!
> - renamed the flag due to v1 comments
> - renamed the function to
> 
>  include/driver.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/driver.h b/include/driver.h
> index 0d43b36148..d84fe35d50 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -496,6 +496,7 @@ int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset);
>  #define DEVFS_PARTITION_READONLY	(1U << 1)
>  #define DEVFS_IS_CHARACTER_DEV		(1U << 3)
>  #define DEVFS_PARTITION_FROM_TABLE	(1U << 4)
> +#define DEVFS_IS_MCI_MAIN_PART_DEV	(1U << 5)
>  
>  struct cdev *devfs_add_partition(const char *devname, loff_t offset,
>  		loff_t size, unsigned int flags, const char *name);
> @@ -509,6 +510,11 @@ static inline void cdev_create_default_automount(struct cdev *cdev)
>  }
>  #endif
>  
> +static inline bool cdev_is_mci_main_part_dev(struct cdev *cdev)
> +{
> +	return cdev->flags & DEVFS_IS_MCI_MAIN_PART_DEV;
> +}
> +
>  #define DEVFS_PARTITION_APPEND		0
>  
>  /**
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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

end of thread, other threads:[~2021-05-12  5:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 10:25 [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Marco Felsch
2021-05-10 10:25 ` [PATCH v3 2/3] mci: mci-core: set the DEVFS_IS_MCI_MAIN_PART_DEV flag Marco Felsch
2021-05-10 10:25 ` [PATCH v3 3/3] fs: add linux_rootarg 'root=mmcblkXpN' support Marco Felsch
2021-05-12  5:25 ` [PATCH v3 1/3] driver: add flag to check if cdev is an mci device Sascha Hauer

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