fdt_path_offset(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… fdt_path_offset β€” find a tree node by its full path

okay bestie, this one is from the Kernel API Manual, section 9, and it's genuinely one of the most useful little gremlins in libfdt. It's called fdt_path_offset, and its whole entire job is: you give it a path, it gives you a node. iconic behavior, no notes. πŸŽ€


✨ SYNOPSIS ✨

int fdt_path_offset (const void *fdt , const char *path );

like, that's it. two args. in and out. slay. πŸ’…


🌸 ARGUMENTS 🌸

  • fdt β€” pointer to the device tree blob. yes, the whole blob. the big one. it's giving main character energy and it literally is the data structure everything lives in. πŸ¦‹
  • path β€” the full path of the node you're trying to locate. the address of your fave node in the tree, basically. πŸ“

🧚 DESCRIPTION 🧚

fdt_path_offset finds a node of a given path in the device tree. that's the vibe check it performs. πŸ”₯

here's the cute flexible part: each path component may omit the unit address portion. so you don't always have to type out the whole chonky name. BUT β€” and this is the dramatic part β€” the results of this are undefined if any such path component is ambiguous (that is, if there are multiple nodes at the relevant level matching the given component, differentiated only by unit address). so like, if two siblings are lowkey the same name with different unit addresses and you get sloppy? undefined behavior. we don't do that. πŸ’€

🌈 the alias situation

if the path is not absolute (i.e. does not begin with '/'), the first component is treated as an alias. 🫢

so what happens is: the property by that name is looked up in the /aliases node, and the value of that property gets used in place of that first component. it's like a nickname that expands into the full government name. iykyk.

for example, for this small fragment:

/ { aliases { i2c2 = foo; // RHS compiles to
"/soc0/i2c30a40000/eeprom52" }; soc0 { foo: i2c30a40000 { bar: eeprom52
{ }; }; }; };

these would be equivalent:

/soc0/i2c30a40000/eeprom52 i2c2/eeprom52

same node, two paths, both valid. the alias ate and left no crumbs. πŸ‘‘


⭐ RETURN ⭐

here's what you get back, and bestie, a lot of these are NOT the good ending:

  • the structure block offset of the node with the requested path, >=0 β€” on success ✨ (negative means something went sideways, keep reading)
  • -FDT_ERR_BADPATH β€” given path does not begin with '/' and the first component is not a valid alias 😭
  • -FDT_ERR_NOTFOUND β€” if the requested node does not exist. gone. not in the tree. rip. πŸ™ˆ
  • -FDT_ERR_BADMAGIC, -FDT_ERR_BADVERSION, -FDT_ERR_BADSTATE, -FDT_ERR_BADSTRUCTURE, -FDT_ERR_TRUNCATED β€” standard meanings. the classic crew. the usual suspects. πŸ’€
fr fr check your return value. a >=0 is a win, anything else is the blob telling you something is wrong with it (or with your path). don't ignore it. 🚨

πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./scripts/dtc/libfdt/libfdt.h β€” and literally the entire libfdt extended universe bestie, buckle up:

fdt_offset_ptr(9), fdt_next_tag(9), fdt_first_subnode(9), fdt_next_subnode(9), fdt_for_each_subnode(9), fdt_header_size(9), fdt_header_size_(9), fdt_check_header(9), fdt_move(9), fdt_check_full(9), fdt_get_string(9), fdt_string(9), fdt_find_max_phandle(9), fdt_get_max_phandle(9), fdt_generate_phandle(9), fdt_num_mem_rsv(9), fdt_get_mem_rsv(9), fdt_subnode_offset_namelen(9), fdt_subnode_offset(9), fdt_path_offset_namelen(9), fdt_get_name(9), fdt_first_property_offset(9), fdt_next_property_offset(9), fdt_for_each_property_offset(9), fdt_get_property_by_offset(9), fdt_get_property_namelen(9), fdt_get_property(9), fdt_getprop_by_offset(9), fdt_getprop_namelen(9), fdt_getprop(9), fdt_get_phandle(9), fdt_get_alias_namelen(9), fdt_get_alias(9), fdt_get_symbol_namelen(9), fdt_get_symbol(9), fdt_get_path(9), fdt_supernode_atdepth_offset(9), fdt_node_depth(9), fdt_parent_offset(9), fdt_node_offset_by_prop_value(9), fdt_node_offset_by_phandle(9), fdt_node_check_compatible(9), fdt_node_offset_by_compatible(9), fdt_stringlist_contains(9), fdt_stringlist_count(9), fdt_stringlist_search(9), fdt_stringlist_get(9), FDT_MAX_NCELLS(9), fdt_address_cells(9), fdt_size_cells(9), fdt_setprop_inplace_namelen_partial(9), fdt_setprop_inplace(9), fdt_setprop_inplace_u32(9), fdt_setprop_inplace_u64(9), fdt_setprop_inplace_cell(9), fdt_nop_property(9), fdt_nop_node(9), fdt_create_with_flags(9), fdt_create(9), fdt_resize(9), fdt_add_reservemap_entry(9), fdt_finish_reservemap(9), fdt_begin_node(9), fdt_property(9), fdt_property_placeholder(9), fdt_end_node(9), fdt_finish(9), fdt_create_empty_tree(9), fdt_open_into(9), fdt_pack(9), fdt_add_mem_rsv(9), fdt_del_mem_rsv(9), fdt_set_name(9), fdt_setprop_namelen(9), fdt_setprop(9), fdt_setprop_placeholder_namelen(9), fdt_setprop_placeholder(9), fdt_setprop_u32(9), fdt_setprop_u64(9), fdt_setprop_cell(9), fdt_setprop_string(9), fdt_setprop_namelen_string(9), fdt_setprop_empty(9), fdt_appendprop(9), fdt_appendprop_u32(9), fdt_appendprop_u64(9), fdt_appendprop_cell(9), fdt_appendprop_string(9), fdt_appendprop_addrrange(9), fdt_delprop(9), fdt_add_subnode_namelen(9), fdt_add_subnode(9), fdt_del_node(9), fdt_overlay_apply(9), fdt_overlay_target_offset(9), fdt_strerror(9)


anyway bestie that's the whole page πŸ’œ this beauty ships from ./scripts/dtc/libfdt, dated October 2026, and it's fdt_path_offset(9) all day. go find your nodes, queen. πŸŽ€βœ¨

πŸ“¦ where this page comes from