From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 15/17] mtd: fixup device tree partitions
Date: Thu, 12 Feb 2015 09:54:32 +0100 [thread overview]
Message-ID: <1423731274-9860-16-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1423731274-9860-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/core.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/mtd/mtd.h | 2 ++
2 files changed, 66 insertions(+)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index ac1001e..63b1e4a 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -482,6 +482,66 @@ static int mtd_part_compare(struct list_head *a, struct list_head *b)
return 0;
}
+static int of_mtd_fixup(struct device_node *root, void *ctx)
+{
+ struct mtd_info *mtd = ctx, *partmtd;
+ struct device_node *np, *part, *tmp;
+ int ret, i = 0;
+
+ np = of_find_node_by_path(mtd->of_path);
+ if (!np) {
+ dev_err(&mtd->class_dev, "Cannot find nodepath %s, cannot fixup\n",
+ mtd->of_path);
+ return -EINVAL;
+ }
+
+ for_each_child_of_node_safe(np, tmp, part) {
+ if (of_get_property(part, "compatible", NULL))
+ continue;
+ of_delete_node(part);
+ }
+
+ list_for_each_entry(partmtd, &mtd->partitions, partitions_entry) {
+ int na, ns, len = 0;
+ char *name = asprintf("partition@%d", i++);
+ void *p;
+ u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
+
+ if (!name)
+ return -ENOMEM;
+
+ part = of_new_node(np, name);
+ free(name);
+ if (!part)
+ return -ENOMEM;
+
+ p = of_new_property(part, "label", partmtd->cdev.partname,
+ strlen(partmtd->cdev.partname) + 1);
+ if (!p)
+ return -ENOMEM;
+
+ na = of_n_addr_cells(np);
+ ns = of_n_size_cells(np);
+
+ of_write_number(tmp + len, partmtd->master_offset, na);
+ len += na * 4;
+ of_write_number(tmp + len, partmtd->size, ns);
+ len += ns * 4;
+
+ ret = of_set_property(part, "reg", tmp, len, 1);
+ if (ret)
+ return ret;
+
+ if (partmtd->cdev.flags & DEVFS_PARTITION_READONLY) {
+ ret = of_set_property(part, "read-only", NULL, 0, 1);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
{
struct mtddev_hook *hook;
@@ -544,6 +604,10 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
if (mtd->parent && !mtd->master) {
dev_add_param(&mtd->class_dev, "partitions", mtd_partition_set, mtd_partition_get, 0);
of_parse_partitions(&mtd->cdev, mtd->parent->device_node);
+ if (IS_ENABLED(CONFIG_OFDEVICE) && mtd->parent->device_node) {
+ mtd->of_path = xstrdup(mtd->parent->device_node->full_name);
+ of_register_fixup(of_mtd_fixup, mtd);
+ }
}
list_for_each_entry(hook, &mtd_register_hooks, hook)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 72bd66b..33f1fd5 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -223,6 +223,8 @@ struct mtd_info {
struct list_head partitions;
struct list_head partitions_entry;
+
+ char *of_path;
};
int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-02-12 8:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-12 8:54 mtd partition handling updates Sascha Hauer
2015-02-12 8:54 ` [PATCH 01/17] of: Add for_each_child_of_node_safe Sascha Hauer
2015-02-12 8:54 ` [PATCH 02/17] mtd: core: add error checks Sascha Hauer
2015-02-12 8:54 ` [PATCH 03/17] mtd: partitions: Use xstrdup Sascha Hauer
2015-02-12 8:54 ` [PATCH 04/17] mtd: partitions: Add error check Sascha Hauer
2015-02-12 8:54 ` [PATCH 05/17] mtd: Add partitions to list Sascha Hauer
2015-02-12 8:54 ` [PATCH 06/17] mtd: nand: remove automatically created bb devices Sascha Hauer
2015-02-12 8:54 ` [PATCH 07/17] move cmdline partition parsing code to separate file Sascha Hauer
2015-02-12 8:54 ` [PATCH 08/17] cmdlinepart: Change SIZE_REMAINING to loff_t Sascha Hauer
2015-02-12 8:54 ` [PATCH 09/17] cmdlinepart: make argument types safer Sascha Hauer
2015-02-12 8:54 ` [PATCH 10/17] cmdlinepart: add function to parse a cmdline partition string Sascha Hauer
2015-02-12 8:54 ` [PATCH 11/17] cmndlinepart: skip devname if partstr already contains it Sascha Hauer
2015-02-12 8:54 ` [PATCH 12/17] mtd: forbid conflicting mtd partitions Sascha Hauer
2015-02-12 8:54 ` [PATCH 13/17] mtd: Use flags parameter in mtd_add_partition Sascha Hauer
2015-02-12 8:54 ` [PATCH 14/17] mtd: Add a partitions parameter to mtd devices Sascha Hauer
2015-02-12 8:54 ` Sascha Hauer [this message]
2015-02-12 8:54 ` [PATCH 16/17] defaultenv-2: mtdparts-add: remove unused variable Sascha Hauer
2015-02-12 8:54 ` [PATCH 17/17] defaultenv-2: mtdparts-add: Use new partition parameter Sascha Hauer
2015-02-13 5:54 ` mtd partition handling updates Bo Shen
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=1423731274-9860-16-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