/* prop_fixup contains a list of tuples of path:property_name:offset */
end = value + prop_fixup->length; for (cur = value; cur < end; cur += len + 1) {
len = strlen(cur);
node_path = cur;
s = strchr(cur, ':'); if (!s) return -EINVAL;
*s++ = '\0';
prop_name = s;
s = strchr(s, ':'); if (!s) return -EINVAL;
*s++ = '\0';
err = kstrtoint(s, 10, &offset); if (err) return err;
refnode = __of_find_node_by_full_path(of_node_get(overlay), node_path); if (!refnode) continue;
for_each_property_of_node(refnode, prop) { if (!of_prop_cmp(prop->name, prop_name)) break;
}
of_node_put(refnode);
/* compare nodes taking into account that 'name' strips out the @ part */ staticint node_name_cmp(conststruct device_node *dn1, conststruct device_node *dn2)
{ constchar *n1 = kbasename(dn1->full_name); constchar *n2 = kbasename(dn2->full_name);
return of_node_cmp(n1, n2);
}
/* * Adjust the local phandle references by the given phandle delta. * * Subtree @local_fixups, which is overlay node __local_fixups__, * mirrors the fragment node structure at the root of the overlay. * * For each property in the fragments that contains a phandle reference, * @local_fixups has a property of the same name that contains a list * of offsets of the phandle reference(s) within the respective property * value(s). The values at these offsets will be fixed up.
*/ staticint adjust_local_phandle_references(conststruct device_node *local_fixups, conststruct device_node *overlay, int phandle_delta)
{ struct device_node *overlay_child; conststruct property *prop_fix, *prop; int err, i, count; unsignedint off;
/* * These nested loops recurse down two subtrees in parallel, where the * node names in the two subtrees match. * * The roots of the subtrees are the overlay's __local_fixups__ node * and the overlay's root node.
*/
for_each_child_of_node_scoped(local_fixups, child) {
for_each_child_of_node(overlay, overlay_child) if (!node_name_cmp(child, overlay_child)) {
of_node_put(overlay_child); break;
}
if (!overlay_child) return -EINVAL;
err = adjust_local_phandle_references(child, overlay_child,
phandle_delta); if (err) return err;
}
return 0;
}
/** * of_resolve_phandles - Relocate and resolve overlay against live tree * * @overlay: Pointer to devicetree overlay to relocate and resolve * * Modify (relocate) values of local phandles in @overlay to a range that * does not conflict with the live expanded devicetree. Update references * to the local phandles in @overlay. Update (resolve) phandle references * in @overlay that refer to the live expanded devicetree. * * Phandle values in the live tree are in the range of * 1 .. live_tree_max_phandle(). The range of phandle values in the overlay * also begin with at 1. Adjust the phandle values in the overlay to begin * at live_tree_max_phandle() + 1. Update references to the phandles to * the adjusted phandle values. * * The name of each property in the "__fixups__" node in the overlay matches * the name of a symbol (a label) in the live tree. The values of each * property in the "__fixups__" node is a list of the property values in the * overlay that need to be updated to contain the phandle reference * corresponding to that symbol in the live tree. Update the references in * the overlay with the phandle values in the live tree. * * @overlay must be detached. * * Resolving and applying @overlay to the live expanded devicetree must be * protected by a mechanism to ensure that multiple overlays are processed * in a single threaded manner so that multiple overlays will not relocate * phandles to overlapping ranges. The mechanism to enforce this is not * yet implemented. * * Return: %0 on success or a negative error value on error.
*/ int of_resolve_phandles(struct device_node *overlay)
{ struct device_node *child, *refnode; struct device_node *overlay_fixups; struct device_node __free(device_node) *local_fixups = NULL; struct property *prop; constchar *refpath;
phandle phandle, phandle_delta; int err;
if (!overlay) {
pr_err("null overlay\n"); return -EINVAL;
}
if (!of_node_check_flag(overlay, OF_DETACHED)) {
pr_err("overlay not detached\n"); return -EINVAL;
}
for_each_child_of_node(overlay, local_fixups) if (of_node_name_eq(local_fixups, "__local_fixups__")) break;
err = adjust_local_phandle_references(local_fixups, overlay, phandle_delta); if (err) return err;
overlay_fixups = NULL;
for_each_child_of_node(overlay, child) { if (of_node_name_eq(child, "__fixups__"))
overlay_fixups = child;
}
if (!overlay_fixups) return 0;
struct device_node __free(device_node) *tree_symbols = of_find_node_by_path("/__symbols__"); if (!tree_symbols) {
pr_err("no symbols in root of device tree.\n"); return -EINVAL;
}
for_each_property_of_node(overlay_fixups, prop) {
/* skip properties added automatically */ if (!of_prop_cmp(prop->name, "name")) continue;
err = of_property_read_string(tree_symbols,
prop->name, &refpath); if (err) {
pr_err("node label '%s' not found in live devicetree symbols table\n",
prop->name); return err;
}
refnode = of_find_node_by_path(refpath); if (!refnode) return -ENOENT;
phandle = refnode->phandle;
of_node_put(refnode);
err = update_usages_of_a_phandle_reference(overlay, prop, phandle); if (err) break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.