mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 08:42:12 +02:00
core: Add functions to set properties in live-tree
Implement a set of functions to manipulate properties in a live device tree: * ofnode_write_prop() to set generic properties of a node * ofnode_write_string() to set string properties of a node * ofnode_set_enabled() to either enable or disable a node Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -791,3 +791,73 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,
|
||||
propname, propval, proplen));
|
||||
}
|
||||
}
|
||||
|
||||
int ofnode_write_prop(ofnode node, const char *propname, int len,
|
||||
const void *value)
|
||||
{
|
||||
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)
|
||||
return -ENOMEM;
|
||||
|
||||
new->value = (void *)value;
|
||||
new->length = len;
|
||||
new->next = NULL;
|
||||
|
||||
pp_last->next = new;
|
||||
|
||||
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);
|
||||
|
||||
return ofnode_write_prop(node, propname, strlen(value) + 1, value);
|
||||
}
|
||||
|
||||
int ofnode_set_enabled(ofnode node, bool value)
|
||||
{
|
||||
if (!of_live_active())
|
||||
return -ENOSYS;
|
||||
|
||||
assert(ofnode_valid(node));
|
||||
|
||||
if (value)
|
||||
return ofnode_write_string(node, "status", "okay");
|
||||
else
|
||||
return ofnode_write_string(node, "status", "disable");
|
||||
}
|
||||
|
Reference in New Issue
Block a user