scripts/dtc/libfdt/fdt_overlay.c
Source file repositories/reference/linux-study-clean/scripts/dtc/libfdt/fdt_overlay.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/dtc/libfdt/fdt_overlay.c- Extension
.c- Size
- 27480 bytes
- Lines
- 1102
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
libfdt_env.hfdt.hlibfdt.hlibfdt_internal.h
Detected Declarations
function Copyrightfunction fdt_overlay_target_offsetfunction overlay_phandle_add_offsetfunction overlay_adjust_node_phandlesfunction fdt_for_each_subnodefunction overlay_adjust_local_phandlesfunction overlay_update_local_nodes_referencesfunction fdt_for_each_property_offsetfunction fdt_for_each_subnodefunction overlay_update_local_referencesfunction overlay_fixup_one_phandlefunction overlay_fixup_phandlefunction overlay_fixup_phandlesfunction fdt_for_each_property_offsetfunction overlay_adjust_local_conflicting_phandlefunction overlay_update_node_conflicting_referencesfunction fdt_for_each_property_offsetfunction fdt_for_each_subnodefunction overlay_update_local_conflicting_referencesfunction overlay_prevent_phandle_overwrite_nodefunction fdt_for_each_subnodefunction overlay_prevent_phandle_overwritefunction fdt_for_each_subnodefunction overlay_apply_nodefunction fdt_for_each_property_offsetfunction fdt_for_each_subnodefunction overlay_mergefunction fdt_for_each_subnodefunction get_path_lenfunction overlay_symbol_updatefunction fdt_overlay_apply
Annotated Snippet
if (!tree_val) {
if (tree_len == -FDT_ERR_NOTFOUND)
return -FDT_ERR_BADOVERLAY;
return tree_len;
}
for (i = 0; i < fixup_len; i++) {
fdt32_t *refp;
refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i));
/*
* phandles to fixup can be unaligned, so use
* fdt32_{ld,st}() to read/write them.
*/
fdt32_st(refp, fdt32_ld(refp) + delta);
}
}
fdt_for_each_subnode(fixup_child, fdto, fixup_node) {
const char *fixup_child_name = fdt_get_name(fdto, fixup_child,
NULL);
int tree_child;
tree_child = fdt_subnode_offset(fdto, tree_node,
fixup_child_name);
if (tree_child == -FDT_ERR_NOTFOUND)
return -FDT_ERR_BADOVERLAY;
if (tree_child < 0)
return tree_child;
ret = overlay_update_local_node_references(fdto,
tree_child,
fixup_child,
delta);
if (ret)
return ret;
}
return 0;
}
/**
* overlay_update_local_references - Adjust the overlay references
* @fdto: Device tree overlay blob
* @delta: Offset to shift the phandles of
*
* overlay_update_local_references() update all the phandles pointing
* to a node within the device tree overlay by adding a constant
* delta to not conflict with the base overlay.
*
* This is mainly used as part of a device tree application process,
* where you want the device tree overlays phandles to not conflict
* with the ones from the base device tree before merging them.
*
* returns:
* 0 on success
* Negative error code on failure
*/
static int overlay_update_local_references(void *fdto, uint32_t delta)
{
int fixups;
fixups = fdt_path_offset(fdto, "/__local_fixups__");
if (fixups < 0) {
/* There's no local phandles to adjust, bail out */
if (fixups == -FDT_ERR_NOTFOUND)
return 0;
return fixups;
}
/*
* Update our local references from the root of the tree
*/
return overlay_update_local_node_references(fdto, 0, fixups,
delta);
}
/**
* overlay_fixup_one_phandle - Set an overlay phandle to the base one
* @fdto: Device tree overlay blob
* @symbols_off: Node offset of the symbols node in the base device tree
* @path: Path to a node holding a phandle in the overlay
* @path_len: number of path characters to consider
* @name: Name of the property holding the phandle reference in the overlay
* @name_len: number of name characters to consider
* @poffset: Offset within the overlay property where the phandle is stored
* @phandle: Phandle referencing the node
Annotation
- Immediate include surface: `libfdt_env.h`, `fdt.h`, `libfdt.h`, `libfdt_internal.h`.
- Detected declarations: `function Copyright`, `function fdt_overlay_target_offset`, `function overlay_phandle_add_offset`, `function overlay_adjust_node_phandles`, `function fdt_for_each_subnode`, `function overlay_adjust_local_phandles`, `function overlay_update_local_nodes_references`, `function fdt_for_each_property_offset`, `function fdt_for_each_subnode`, `function overlay_update_local_references`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.