summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-07-31 00:52:13 +0300
committerTom Rini <trini@konsulko.com>2022-08-12 15:14:24 +0300
commit39e42be12b9456e604ac3e228973b1cb1136864c (patch)
tree14b0f51e7ad986d730b39d8b0bf0440ddf1b5659 /drivers/core
parent7b1dfc9fd7e2efed345c3fe9a2412b5300ac285e (diff)
downloadu-boot-39e42be12b9456e604ac3e228973b1cb1136864c.tar.xz
dm: core: Allow writing to a flat tree with ofnode
In generally it is not permitted to implement an ofnode function only for flat tree or live tree. Both must be supported. Also the code for live tree access should be in of_access.c rather than ofnode.c which is really just for holding the API-conversion code. Update ofnode_write_prop() accordingly and fix the test so it can work with flat tree too. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/of_access.c43
-rw-r--r--drivers/core/ofnode.c51
2 files changed, 48 insertions, 46 deletions
diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c
index 0e5915a43e..a52f5a6b18 100644
--- a/drivers/core/of_access.c
+++ b/drivers/core/of_access.c
@@ -887,3 +887,46 @@ struct device_node *of_get_stdout(void)
{
return of_stdout;
}
+
+int of_write_prop(struct device_node *np, const char *propname, int len,
+ const void *value)
+{
+ struct property *pp;
+ struct property *pp_last = NULL;
+ struct property *new;
+
+ if (!np)
+ return -EINVAL;
+
+ for (pp = np->properties; pp; pp = pp->next) {
+ if (strcmp(pp->name, propname) == 0) {
+ /* Property exists -> change value */
+ pp->value = (void *)value;
+ pp->length = len;
+ return 0;
+ }
+ pp_last = pp;
+ }
+
+ if (!pp_last)
+ return -ENOENT;
+
+ /* Property does not exist -> append new property */
+ new = malloc(sizeof(struct property));
+ if (!new)
+ return -ENOMEM;
+
+ new->name = strdup(propname);
+ if (!new->name) {
+ free(new);
+ return -ENOMEM;
+ }
+
+ new->value = (void *)value;
+ new->length = len;
+ new->next = NULL;
+
+ pp_last->next = new;
+
+ return 0;
+}
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 1c9542a356..b7a55589a1 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -1108,55 +1108,17 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,
int ofnode_write_prop(ofnode node, const char *propname, const void *value,
int len)
{
- const struct device_node *np = ofnode_to_np(node);
- struct property *pp;
- struct property *pp_last = NULL;
- struct property *new;
-
- if (!of_live_active())
- return -ENOSYS;
-
- if (!np)
- return -EINVAL;
-
- for (pp = np->properties; pp; pp = pp->next) {
- if (strcmp(pp->name, propname) == 0) {
- /* Property exists -> change value */
- pp->value = (void *)value;
- pp->length = len;
- return 0;
- }
- pp_last = pp;
- }
-
- if (!pp_last)
- return -ENOENT;
-
- /* Property does not exist -> append new property */
- new = malloc(sizeof(struct property));
- if (!new)
- return -ENOMEM;
-
- new->name = strdup(propname);
- if (!new->name) {
- free(new);
- return -ENOMEM;
- }
-
- new->value = (void *)value;
- new->length = len;
- new->next = NULL;
-
- pp_last->next = new;
+ if (of_live_active())
+ return of_write_prop(ofnode_to_npw(node), propname, len, value);
+ else
+ return fdt_setprop((void *)gd->fdt_blob, ofnode_to_offset(node),
+ propname, value, len);
return 0;
}
int ofnode_write_string(ofnode node, const char *propname, const char *value)
{
- if (!of_live_active())
- return -ENOSYS;
-
assert(ofnode_valid(node));
debug("%s: %s = %s", __func__, propname, value);
@@ -1166,9 +1128,6 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value)
int ofnode_set_enabled(ofnode node, bool value)
{
- if (!of_live_active())
- return -ENOSYS;
-
assert(ofnode_valid(node));
if (value)