Device Tree API#
Public API#
- group Device tree
Typedefs
Functions
-
error_t dt_init(const void *fdt, fdt_t *obj)#
Read the header at fdt and set fields of obj.
Note
If an error occurs, fdt_buffer of obj is set to an invalid buffer.
- Parameters:
fdt – Pointer to the flattened device tree data.
obj – Pointer to the fdt_t structure to initialize.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid or unsupported
-
void dt_reset(fdt_t *obj)#
Reset properties of obj.
- Parameters:
obj – Pointer to the fdt_t structure to reset.
-
error_t dt_get_node_in_subtree_by_path(const fdt_t *fdt, dt_node_t node, const char *node_path, dt_node_t *nodeOUT)#
Get a node in a subtree of fdt, leave as 0 for global search.
- Parameters:
fdt – Pointer to the fdt object.
node – The node of which subtree to search, leave as 0 for global search.
node_path – Path to the node.
nodeOUT – [out] Found node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no node found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_node_by_path(const fdt_t *fdt, const char *node_path, dt_node_t *nodeOUT)#
Get a node globally in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node_path – Path to the node.
nodeOUT – [out] Found node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no node found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_node_child(const fdt_t *fdt, dt_node_t node, dt_node_t *nodeOUT)#
Get a node’s first child in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node – The parent node.
nodeOUT – [out] Child node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no node found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_node_sibling(const fdt_t *fdt, dt_node_t node, dt_node_t *nodeOUT)#
Get a node’s next sibling in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node – The node to get the sibling of.
nodeOUT – [out] Sibling node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no node found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_node_name(const fdt_t *fdt, dt_node_t node, buffer_t *bufOUT)#
Get a node’s name as a buffer in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node – The node to get the name of.
bufOUT – [out] Buffer with the name.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nodeERR_NOT_VALID – if the FDT is invalid
-
error_t dt_get_node_name_ptr(const fdt_t *fdt, dt_node_t node, const char **ptrOUT)#
Get a node’s name as a pointer in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node – The node to get the name of.
ptrOUT – [out] Pointer to the name.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nodeERR_NOT_VALID – if the FDT is invalid
-
error_t dt_get_prop_by_name(const fdt_t *fdt, dt_node_t node, const char *prop_name, dt_prop_t *propOUT)#
Get a node’s prop_name property in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node – The node to search in.
prop_name – Name of the property.
propOUT – [out] Property.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nodeERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no prop found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_first_prop(const fdt_t *fdt, dt_node_t node, dt_prop_t *propOUT)#
Get a node’s first property in fdt.
- Parameters:
fdt – Pointer to the fdt object.
node – The node to get the first property of.
propOUT – [out] First property.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nodeERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no prop found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_next_prop(const fdt_t *fdt, dt_prop_t prop, dt_prop_t *propOUT)#
Get a node’s next property after prop in fdt.
- Parameters:
fdt – Pointer to the fdt object.
prop – The current property.
propOUT – [out] Next property.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
propERR_NOT_VALID – if the FDT is invalid
ERR_NOT_FOUND – if no prop found
ERR_OUT_OF_BOUNDS – if search went out of bounds
-
error_t dt_get_prop_name(const fdt_t *fdt, dt_prop_t prop, buffer_t *bufOUT)#
Get a prop’s name as a buffer in fdt.
- Parameters:
fdt – Pointer to the fdt object.
prop – The property to get the name of.
bufOUT – [out] Buffer with the name.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
propERR_NOT_VALID – if the FDT is invalid
-
error_t dt_get_prop_name_ptr(const fdt_t *fdt, dt_prop_t prop, const char **ptrOUT)#
Get a prop’s name as a pointer in fdt.
- Parameters:
fdt – Pointer to the fdt object.
prop – The property to get the name of.
ptrOUT – [out] Pointer to the name.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
propERR_NOT_VALID – if the FDT is invalid
-
error_t dt_get_prop_buffer(const fdt_t *fdt, dt_prop_t prop, buffer_t *bufOUT)#
Get a buffer for prop’s data.
- Parameters:
fdt – Pointer to the fdt object.
prop – The property to get the data of.
bufOUT – [out] Buffer with the data.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid
-
struct fdt_t#
- #include <dt.h>
Flattened device tree structure.
-
error_t dt_init(const void *fdt, fdt_t *obj)#
Internals#
- group Dt_internal
Defines
-
FDT_MAGIC#
FDT magic number.
-
FDT_OFF_MAGIC#
Offset to magic number.
-
FDT_OFF_TOTAL_SIZE#
Offset to total size.
-
FDT_OFF_OFF_DT_STRUCT#
Offset to structure block offset.
-
FDT_OFF_OFF_DT_STRINGS#
Offset to strings block offset.
-
FDT_OFF_MEM_RSVMAP#
Offset to memory reservation map.
-
FDT_OFF_VERSION#
Offset to version.
-
FDT_OFF_LAST_COMP_VERSION#
Offset to last compatible version.
-
FDT_OFF_BOOT_CPUID_PHYS#
Offset to boot CPU physical ID.
-
FDT_OFF_SIZE_DT_STRINGS#
Offset to strings block size.
-
FDT_OFF_SIZE_DT_STRUCT#
Offset to structure block size.
-
FDT_COMPATIBLE_VERSION#
Minimum compatible FDT version.
Enums
Functions
-
error_t dt_skip_node_name(const fdt_t *fdt, dt_node_t node, u32 *offsetOUT)#
Skip node’s tag and name and output first aligned offset after them.
- Parameters:
fdt – Pointer to the flattened device tree.
node – The device tree node.
offsetOUT – [out] First aligned offset after the
node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nodeERR_NOT_VALID – if the FDT is invalid
-
error_t dt_skip_node_properties(const fdt_t *fdt, u32 offset, u32 *offsetOUT)#
Skip node’s properties starting at offset (if they exist) and output first aligned offset after them.
- Parameters:
fdt – Pointer to the flattened device tree.
offset – The offset to start skipping properties from.
offsetOUT – [out] First aligned offset after properties at
offset.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args
ERR_NOT_VALID – if the FDT is invalid
-
error_t dt_skip_node_header(const fdt_t *fdt, dt_node_t node, u32 *offsetOUT)#
Skip node’s tag, name and properties and output first aligned offset after them.
- Parameters:
fdt – Pointer to the flattened device tree.
node – The device tree node.
offsetOUT – [out] First aligned offset after the
node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nodeERR_NOT_VALID – if the FDT is invalid
-
error_t dt_skip_nested_nodes(const fdt_t *fdt, dt_node_t nested_node, dt_node_t *nodeOUT)#
Skip an overarching node’s nested nodes starting at the start of the first nested node.
- Parameters:
fdt – Pointer to the flattened device tree.
nested_node – The first nested node to start skipping from.
nodeOUT – [out] First non-nested node after the
nested_node.
- Return values:
ERR_NONE – on success
ERR_BAD_ARG – on nullptr args or misaligned
nested_nodeERR_NOT_VALID – if the FDT is invalid
-
FDT_MAGIC#