From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/2] blspec: Automatically attach UBI devices
Date: Wed, 17 Jun 2015 11:40:12 +0200 [thread overview]
Message-ID: <1434534012-30441-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1434534012-30441-1-git-send-email-s.hauer@pengutronix.de>
When blspec_scan_cdev finds an UBI device then attach it. This
allows us to boot blspec entries found on the UBIFS images inside
UBI volumes by pointing to the corresponding mtd partition.
With this we can do 'boot nand0.root' or even 'boot=nand0' on the
commandline.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index 3506388..aef246d 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -30,6 +30,7 @@
#include <of.h>
#include <linux/stat.h>
#include <linux/err.h>
+#include <mtd/ubi-user.h>
/*
* blspec_entry_var_set - set a variable to a value
@@ -436,6 +437,35 @@ err_out:
}
/*
+ * blspec_scan_ubi - scan over a cdev containing UBI volumes
+ *
+ * This function attaches a cdev as UBI devices and collects all blspec
+ * entries found in the UBI volumes
+ *
+ * returns the number of entries found or a negative error code if some unexpected
+ * error occured.
+ */
+static int blspec_scan_ubi(struct blspec *blspec, struct cdev *cdev)
+{
+ struct device_d *child;
+ int ret, found = 0;
+
+ pr_debug("%s: %s\n", __func__, cdev->name);
+
+ ret = ubi_attach_mtd_dev(cdev->mtd, UBI_DEV_NUM_AUTO, 0, 20);
+ if (ret && ret != -EEXIST)
+ return 0;
+
+ device_for_each_child(cdev->dev, child) {
+ ret = blspec_scan_device(blspec, child);
+ if (ret > 0)
+ found += ret;
+ }
+
+ return found;
+}
+
+/*
* blspec_scan_cdev - scan over a cdev
*
* Given a cdev this function mounts the filesystem and collects all blspec
@@ -446,9 +476,9 @@ err_out:
*/
static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
{
- int ret;
+ int ret, found = 0;
void *buf = xzalloc(512);
- enum filetype type;
+ enum filetype type, filetype;
const char *rootpath;
pr_debug("%s: %s\n", __func__, cdev->name);
@@ -460,16 +490,26 @@ static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
}
type = file_detect_partition_table(buf, 512);
+ filetype = file_detect_type(buf, 512);
free(buf);
if (type == filetype_mbr || type == filetype_gpt)
return -EINVAL;
+ if (filetype == filetype_ubi && IS_ENABLED(CONFIG_MTD_UBI)) {
+ ret = blspec_scan_ubi(blspec, cdev);
+ if (ret > 0)
+ found += ret;
+ }
+
rootpath = cdev_mount_default(cdev, NULL);
- if (IS_ERR(rootpath))
- return PTR_ERR(rootpath);
+ if (!IS_ERR(rootpath)) {
+ ret = blspec_scan_directory(blspec, rootpath);
+ if (ret > 0)
+ found += ret;
+ }
- return blspec_scan_directory(blspec, rootpath);
+ return found;
}
/*
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2015-06-17 9:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-17 9:40 [PATCH 1/2] blspec: Add missing prototype for blspec_scan_device Sascha Hauer
2015-06-17 9:40 ` Sascha Hauer [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=1434534012-30441-2-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