From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 5/8] mtd: detect ubi devices automatically
Date: Fri, 26 Jun 2015 09:31:04 +0200 [thread overview]
Message-ID: <1435303867-12889-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1435303867-12889-1-git-send-email-s.hauer@pengutronix.de>
Hook UBI attachment into the mtd class devices detect function. This
makes it possible to attach ubi devices with 'detect nand0.root'.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/core.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 681dc93..8a07086 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -18,7 +18,9 @@
#include <common.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/mtd.h>
+#include <mtd/ubi-user.h>
#include <cmdlinepart.h>
+#include <filetype.h>
#include <init.h>
#include <xfuncs.h>
#include <driver.h>
@@ -542,6 +544,41 @@ static int of_mtd_fixup(struct device_node *root, void *ctx)
return 0;
}
+static int mtd_detect(struct device_d *dev)
+{
+ struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+ int bufsize = 512;
+ void *buf;
+ int ret;
+ enum filetype filetype;
+ size_t retlen;
+
+ /*
+ * Do not try to attach an UBI device if this device has partitions
+ * as it's not a good idea to attach UBI on a raw device when the
+ * real UBI only spans the first partition.
+ */
+ if (!list_empty(&mtd->partitions))
+ return -EBUSY;
+
+ buf = xmalloc(bufsize);
+
+ ret = mtd_read(mtd, 0, bufsize, &retlen, buf);
+ if (ret)
+ goto out;
+
+ filetype = file_detect_type(buf, bufsize);
+ if (filetype == filetype_ubi) {
+ ret = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 20);
+ if (ret == -EEXIST)
+ ret = 0;
+ }
+out:
+ free(buf);
+
+ return ret;
+}
+
int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
{
struct mtddev_hook *hook;
@@ -554,6 +591,9 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
if (mtd->parent)
mtd->class_dev.parent = mtd->parent;
+ if (IS_ENABLED(CONFIG_MTD_UBI))
+ mtd->class_dev.detect = mtd_detect;
+
ret = register_device(&mtd->class_dev);
if (ret)
return ret;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-06-26 7:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
2015-06-26 7:31 ` [PATCH 1/8] commands: detect: use device_detect_by_name Sascha Hauer
2015-06-26 7:31 ` [PATCH 2/8] driver: detect: detect parent devices aswell Sascha Hauer
2015-06-26 7:31 ` [PATCH 3/8] blspec: Use device_detect_by_name Sascha Hauer
2015-06-26 7:31 ` [PATCH 4/8] ubi: Use preditable device names Sascha Hauer
2015-06-26 7:31 ` Sascha Hauer [this message]
2015-06-26 7:31 ` [PATCH 6/8] ubi: Lower 'already attached' message to debug level Sascha Hauer
2015-06-26 7:31 ` [PATCH 7/8] commands: mount: detect the device to be mounted Sascha Hauer
2015-06-26 7:31 ` [PATCH 8/8] ubi: Update documentation Sascha Hauer
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=1435303867-12889-6-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@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