MCPcopy Create free account
hub / github.com/coreboot/coreboot / dt_import_fragment

Function dt_import_fragment

src/commonlib/device_tree.c:2024–2067  ·  view source on GitHub ↗

* Apply an overlay /fragment@X node to a base device tree. * * @param tree Base device tree. * @param fragment /fragment@X node. * @params overlay_symbols /__symbols__ node of the overlay. * * @return 0 on success, -1 on error. */

Source from the content-addressed store, hash-verified

2022 * @return 0 on success, -1 on error.
2023 */
2024static int dt_import_fragment(struct device_tree *tree,
2025 struct device_tree_node *fragment,
2026 struct device_tree_node *overlay_symbols)
2027{
2028 /* The actual overlaid nodes/props are in an __overlay__ child node. */
2029 static const char *overlay_path[] = { "__overlay__", NULL };
2030 struct device_tree_node *overlay = dt_find_node(fragment, overlay_path,
2031 NULL, NULL, 0);
2032
2033 /* If it doesn't have an __overlay__ child, it's not a fragment. */
2034 if (!overlay)
2035 return 0;
2036
2037 /* Target node of the fragment can be given by path or by phandle. */
2038 struct device_tree_property *prop;
2039 struct device_tree_property *phandle = NULL;
2040 struct device_tree_property *path = NULL;
2041 list_for_each(prop, fragment->properties, list_node) {
2042 if (!strcmp(prop->prop.name, "target")) {
2043 phandle = prop;
2044 break; /* phandle target has priority, stop looking */
2045 }
2046 if (!strcmp(prop->prop.name, "target-path"))
2047 path = prop;
2048 }
2049
2050 struct device_tree_node *target = NULL;
2051 if (phandle) {
2052 if (phandle->prop.size != sizeof(uint32_t))
2053 return -1;
2054 target = dt_find_node_by_phandle(tree->root,
2055 be32dec(phandle->prop.data));
2056 /* Symbols already updated as part of dt_fixup_external(). */
2057 } else if (path) {
2058 target = dt_find_node_by_path(tree, path->prop.data,
2059 NULL, NULL, 0);
2060 dt_fix_symbols(overlay_symbols, fragment, path->prop.data);
2061 }
2062 if (!target)
2063 return -1;
2064
2065 dt_copy_subtree(target, overlay, 1);
2066 return 0;
2067}
2068
2069/*
2070 * Apply a device tree overlay to a base device tree. This will

Callers 1

dt_apply_overlayFunction · 0.85

Calls 6

dt_find_nodeFunction · 0.85
dt_find_node_by_phandleFunction · 0.85
dt_find_node_by_pathFunction · 0.85
dt_fix_symbolsFunction · 0.85
dt_copy_subtreeFunction · 0.85
strcmpFunction · 0.50

Tested by

no test coverage detected