+
+u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)
+{
+ if (ofnode_is_np(node))
+ return of_translate_address(ofnode_to_np(node), in_addr);
+ else
+ return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
+}
+
+int ofnode_device_is_compatible(ofnode node, const char *compat)
+{
+ if (ofnode_is_np(node))
+ return of_device_is_compatible(ofnode_to_np(node), compat,
+ NULL, NULL);
+ else
+ return !fdt_node_check_compatible(gd->fdt_blob,
+ ofnode_to_offset(node),
+ compat);
+}
+
+ofnode ofnode_by_compatible(ofnode from, const char *compat)
+{
+ if (of_live_active()) {
+ return np_to_ofnode(of_find_compatible_node(
+ (struct device_node *)ofnode_to_np(from), NULL,
+ compat));
+ } else {
+ return offset_to_ofnode(fdt_node_offset_by_compatible(
+ gd->fdt_blob, ofnode_to_offset(from), compat));
+ }
+}
+
+ofnode ofnode_by_prop_value(ofnode from, const char *propname,
+ const void *propval, int proplen)
+{
+ if (of_live_active()) {
+ return np_to_ofnode(of_find_node_by_prop_value(
+ (struct device_node *)ofnode_to_np(from), propname,
+ propval, proplen));
+ } else {
+ return offset_to_ofnode(fdt_node_offset_by_prop_value(
+ gd->fdt_blob, ofnode_to_offset(from),
+ 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");
+}