From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/3] of: fdt: add of_unflatten_dtb_const
Date: Wed, 31 Jan 2018 12:04:38 +0100 [thread overview]
Message-ID: <20180131110438.22620-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180131110438.22620-1-s.hauer@pengutronix.de>
This adds a variant of of_unflatten_dtb() which uses the property data
directly from the input tree rather than copying it. This is mainly
useful for a single user: FIT images.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/fdt.c | 36 ++++++++++++++++++++++++++++++++++--
include/of.h | 1 +
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 614e136de6..1edb35f3d6 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -117,7 +117,7 @@ static int of_unflatten_reservemap(struct device_node *root,
* Parse a flat device tree binary blob and return a pointer to the
* unflattened tree.
*/
-struct device_node *of_unflatten_dtb(const void *infdt)
+struct device_node *__of_unflatten_dtb(const void *infdt, bool constprops)
{
const void *nodep; /* property node pointer */
uint32_t tag; /* tag */
@@ -221,7 +221,11 @@ struct device_node *of_unflatten_dtb(const void *infdt)
goto err;
}
- p = of_new_property(node, name, nodep, len);
+ if (constprops)
+ p = of_new_property_const(node, name, nodep, len);
+ else
+ p = of_new_property(node, name, nodep, len);
+
if (!strcmp(name, "phandle") && len == 4)
node->phandle = be32_to_cpup(p->value);
@@ -255,6 +259,34 @@ err:
return ERR_PTR(ret);
}
+/**
+ * of_unflatten_dtb - unflatten a dtb binary blob
+ * @infdt - the fdt blob to unflatten
+ *
+ * Parse a flat device tree binary blob and return a pointer to the unflattened
+ * tree. The tree must be freed after use with of_delete_node().
+ */
+struct device_node *of_unflatten_dtb(const void *infdt)
+{
+ return __of_unflatten_dtb(infdt, false);
+}
+
+/**
+ * of_unflatten_dtb_const - unflatten a dtb binary blob
+ * @infdt - the fdt blob to unflatten
+ *
+ * Parse a flat device tree binary blob and return a pointer to the unflattened
+ * tree. The tree must be freed after use with of_delete_node(). Unlike the
+ * above version this function uses the property data directly from the input
+ * flattened tree instead of copying the data, thus @infdt must be valid for the
+ * whole lifetime of the returned tree. This is normally not what you want, so
+ * use of_unflatten_dtb() instead.
+ */
+struct device_node *of_unflatten_dtb_const(const void *infdt)
+{
+ return __of_unflatten_dtb(infdt, true);
+}
+
struct fdt {
void *dt;
uint32_t dt_nextofs;
diff --git a/include/of.h b/include/of.h
index d3b92328a5..421e038adb 100644
--- a/include/of.h
+++ b/include/of.h
@@ -101,6 +101,7 @@ void of_print_nodes(struct device_node *node, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
struct device_node *of_unflatten_dtb(const void *fdt);
+struct device_node *of_unflatten_dtb_const(const void *infdt);
struct cdev;
--
2.15.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2018-01-31 11:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-31 11:04 [PATCH 0/3] of: Allow for const properties Sascha Hauer
2018-01-31 11:04 ` [PATCH 1/3] pinctrl: do not dereference a device tree property directly Sascha Hauer
2018-01-31 11:04 ` [PATCH 2/3] of: Allow for const properties Sascha Hauer
2018-01-31 11:04 ` 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=20180131110438.22620-4-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