All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sam Edwards <cfsworks@gmail.com>
To: Heiko Schocher <hs@denx.de>, Simon Glass <sjg@chromium.org>
Cc: Kyungmin Park <kmpark@infradead.org>,
	u-boot@lists.denx.de, Sam Edwards <CFSworks@gmail.com>
Subject: [RFC PATCH v2 4/4] HACK: enable access to `ubi 0:volname` block devices
Date: Thu,  5 Oct 2023 17:08:31 -0600	[thread overview]
Message-ID: <20231005230831.4032070-5-CFSworks@gmail.com> (raw)
In-Reply-To: <20231005230831.4032070-1-CFSworks@gmail.com>

---
 disk/part.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index a4b6d265da..7c995f583c 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -14,6 +14,9 @@
 #include <malloc.h>
 #include <part.h>
 #include <ubifs_uboot.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
 
 #undef	PART_DEBUG
 
@@ -524,6 +527,58 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 	}
 #endif
 
+#if IS_ENABLED(CONFIG_CMD_UBI) && !IS_ENABLED(CONFIG_SPL_BUILD)
+	/*
+	 * Also special-case UBI, which may use names to find the specific
+	 * volumes, so this deviates a bit from the typical devnum:partnum
+	 * syntax.
+	 */
+	if (!strcmp(ifname, "ubi")) {
+		dev = dectoul(dev_part_str, &ep);
+		if (*ep == ':') {
+			struct udevice *ubi_dev = NULL;
+			struct udevice *vol_dev = NULL;
+			part_str = &ep[1];
+
+			ret = uclass_find_device(UCLASS_UBI, dev, &ubi_dev);
+			if (!ubi_dev || ret) {
+				printf("** Cannot find UBI %x\n", dev);
+				return -EINVAL;
+			}
+
+			part = dectoul(part_str, &ep);
+			if (!*ep) {
+				struct udevice *tmp_dev;
+				device_foreach_child(tmp_dev, ubi_dev) {
+					struct blk_desc *desc = dev_get_uclass_plat(tmp_dev);
+					if (desc->devnum == part) {
+						vol_dev = tmp_dev;
+						break;
+					}
+				}
+			} else {
+				ret = device_find_child_by_name(ubi_dev, part_str, &vol_dev);
+			}
+
+			if (!vol_dev || ret) {
+				printf("** UBI volume %s not found\n", part_str);
+				return -EINVAL;
+			}
+
+			ret = device_probe(vol_dev);
+			if (ret)
+				return ret;
+
+			*desc = dev_get_uclass_plat(vol_dev);
+			part_get_info_whole_disk(*desc, info);
+			return 0;
+		}
+
+		printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+		return -EINVAL;
+	}
+#endif
+
 	/* If no dev_part_str, use bootdevice environment variable */
 	if (CONFIG_IS_ENABLED(ENV_SUPPORT)) {
 		if (!dev_part_str || !strlen(dev_part_str) ||
-- 
2.41.0


      parent reply	other threads:[~2023-10-05 23:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05 23:08 [RFC PATCH v2 0/4] mtd: ubi: Enable accessing RO filesystems in UBI vols Sam Edwards
2023-10-05 23:08 ` [RFC PATCH v2 1/4] mtd: ubi: register UBI attachments as DM devices Sam Edwards
2023-10-05 23:08 ` [RFC PATCH v2 2/4] mtd: ubi: bind block device driver for static volumes Sam Edwards
2023-10-05 23:08 ` [RFC PATCH v2 3/4] disk: part: fall-through if "ubi" requested but ubifs not mounted Sam Edwards
2023-10-05 23:08 ` Sam Edwards [this message]

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=20231005230831.4032070-5-CFSworks@gmail.com \
    --to=cfsworks@gmail.com \
    --cc=hs@denx.de \
    --cc=kmpark@infradead.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.