FDT module reference
- class fdt.FDT(header=None, entries=[])[source]
Flattened Device Tree Class
- add_item(obj, path: str = '', create: bool = True)[source]
Add sub-node or property at specified path. Raises ValueError if path doesn’t exist
- Parameters:
obj – The node or property object
path – The path to subnode
create – If True, not existing nodes will be created
- add_label(label)[source]
track labels/references to convert to phandles adds label with incrmenting handle to dictionary if not alread present returns handle for which can be used to replace the reference
- exist_node(path: str) bool [source]
Check if <path>/node exist and return True
- Parameters:
path – path/node name
:return True if <path>/node exist else False
- exist_property(name: str, path: str = '') bool [source]
Check if property exist
- Parameters:
name – Property name
path – The path
- get_node(path: str, create: bool = False) Node [source]
Get node object from specified path
- Parameters:
path – Path as string
create – If True, not existing nodes will be created
- get_property(name: str, path: str = '') Property [source]
Get property object by name from specified path
- Parameters:
name – Property name
path – Path to sub-node
- merge(fdt_obj, replace: bool = True)[source]
Merge external FDT object into this object.
- Parameters:
fdt_obj – The FDT object which will be merged into this
replace – True for replace existing items or False for keep old items
- remove_node(name: str, path: str = '')[source]
Remove node obj by path/name. Raises ValueError if path/name doesn’t exist
- Parameters:
name – Node name
path – Path to sub-node
- remove_property(name: str, path: str = '')[source]
Remove property obj by name. Raises ValueError if path/name doesn’t exist
- Parameters:
name – Property name
path – Path to subnode
- search(name: str, itype: int = 100, path: str = '', recursive: bool = True) list [source]
Search properties and/or nodes with specified name. Return list of founded items
- Parameters:
name – The Property or Node name. If empty “”, all nodes or properties will selected
itype – Item type - NODE, PROP, PROP_BASE, PROP_WORDS, PROP_BYTES, PROP_STRINGS or ALL
path – Path to root node
recursive – Search in all sub-nodes (default: True)
- set_property(name: str, value, path: str = '', create: bool = True)[source]
Set property object by name
- Parameters:
name – Property name
value – Property value
path – Path to subnode
create – If True, not existing nodes will be created
- to_dtb(version: int | None = None, last_comp_version: int | None = None, boot_cpuid_phys: int | None = None, strings: str | None = None) bytes [source]
Export FDT Object into Binary Blob format (DTB)
- Parameters:
version
last_comp_version
boot_cpuid_phys
strings
The strings param is useful (only) when manipulating a signed itb or dtb. The signature includes the strings buffer in the dtb _in order_. C executables write the strings out in a surprising order. The argument is used as an initial version of the strings buffer, so that all strings in the input file are included (and in the same order) in the output file. Usage:
# Read and parse dtb with open(input, ‘rb’) as file:
data = file.read()
dtree = fdt.parse_dtb(data)
# Read strings buffer (Assumes version >= 3) strings_start = dtree.header.off_dt_strings strings_end = strings_start + dtree.header.size_dt_strings strings = data[strings_start:strings_end].decode(“ascii”)
# Serialize dtb and write to output data = dtree.to_dtb(strings=strings) with open(output, ‘wb’) as file:
file.write(data)
- class fdt.Node(name, *args)[source]
Node representation
- exist_property(name: str) bool [source]
Check if property exist and return True if exist else False
- Parameters:
name – Property name
- exist_subnode(name: str) bool [source]
Check if subnode exist and return True if exist else False
- Parameters:
name – Subnode name
- merge(node_obj, replace: bool = True)[source]
Merge two nodes
- Parameters:
node_obj – Node object
replace – If True, replace current properties with the given properties
- remove_property(name: str)[source]
Remove property object by its name.
- Parameters:
name – Property name
- remove_subnode(name: str)[source]
Remove subnode object by its name.
- Parameters:
name – Subnode name
- set_label(value: str)
Set item label
- Parameters:
value – The label in string format
- set_name(value: str)
Set item name
- Parameters:
value – The name in string format
- set_parent(value)
Set item parent
- Parameters:
value – The parent node
- set_property(name, value)[source]
Set property
- Parameters:
name – Property name
value – Property value
- class fdt.PropBytes(name, *args, data=None)[source]
Property with bytes as value
- set_label(value: str)
Set item label
- Parameters:
value – The label in string format
- set_name(value: str)
Set item name
- Parameters:
value – The name in string format
- set_parent(value)
Set item parent
- Parameters:
value – The parent node
- class fdt.PropIncBin(name, data=None, file_name=None, rpath=None)[source]
Property with bytes as value
- set_label(value: str)
Set item label
- Parameters:
value – The label in string format
- set_name(value: str)
Set item name
- Parameters:
value – The name in string format
- set_parent(value)
Set item parent
- Parameters:
value – The parent node
- to_dtb(strings: str, pos: int = 0, version: int = 17)
Get blob representation
- Parameters:
strings
pos
version
- class fdt.PropStrings(name: str, *args)[source]
Property with strings as value
- set_label(value: str)
Set item label
- Parameters:
value – The label in string format
- set_name(value: str)
Set item name
- Parameters:
value – The name in string format
- set_parent(value)
Set item parent
- Parameters:
value – The parent node
- class fdt.PropWords(name, *args)[source]
Property with words as value
- set_label(value: str)
Set item label
- Parameters:
value – The label in string format
- set_name(value: str)
Set item name
- Parameters:
value – The name in string format
- set_parent(value)
Set item parent
- Parameters:
value – The parent node
- fdt.diff(fdt1: FDT, fdt2: FDT) tuple [source]
Compare two flattened device tree objects and return list of 3 objects (same in 1 and 2, specific for 1, specific for 2)
- Parameters:
fdt1 – The object 1 of FDT
fdt2 – The object 2 of FDT