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

info()[source]

Return object info in human readable format

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)

to_dts(tabsize: int = 4) str[source]

Store FDT Object into string format (DTS)

Parameters:

tabsize

walk(path: str = '', relative: bool = False) list[source]

Walk trough nodes and return relative/absolute path with list of sub-nodes and properties

Parameters:
  • path – The path to root node

  • relative – True for relative or False for absolute return path

class fdt.Node(name, *args)[source]

Node representation

append(item)[source]

Append node or property

Parameters:

item – The node or property object

copy()[source]

Create a copy of Node object

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

get_property(name)[source]

Get property object by its name

Parameters:

name – Property name

get_subnode(name: str)[source]

Get subnode object by name

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

to_dtb(strings: str, pos: int = 0, version: int = 17) tuple[source]

Get NODE in binary blob representation

Parameters:
  • strings

  • pos

  • version

to_dts(tabsize: int = 4, depth: int = 0) str[source]

Get string representation of NODE object

Parameters:
  • tabsize – Tabulator size in count of spaces

  • depth – Start depth for line

class fdt.PropBytes(name, *args, data=None)[source]

Property with bytes as value

copy()[source]

Create a copy of object

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)[source]

Get blob representation

Parameters:
  • strings

  • pos

  • version

to_dts(tabsize: int = 4, depth: int = 0)[source]

Get string representation

Parameters:
  • tabsize – Tabulator size in count of spaces

  • depth – Start depth for line

class fdt.PropIncBin(name, data=None, file_name=None, rpath=None)[source]

Property with bytes as value

copy()[source]

Create a copy of object

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

to_dts(tabsize: int = 4, depth: int = 0)[source]

Get string representation

Parameters:
  • tabsize – Tabulator size in count of spaces

  • depth – Start depth for line

class fdt.PropStrings(name: str, *args)[source]

Property with strings as value

copy()[source]

Get object copy

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)[source]

Get blob representation

Parameters:
  • strings

  • pos

  • version

to_dts(tabsize: int = 4, depth: int = 0)[source]

Get string representation

Parameters:
  • tabsize – Tabulator size in count of spaces

  • depth – Start depth for line

class fdt.PropWords(name, *args)[source]

Property with words as value

copy()[source]

Get object copy

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)[source]

Get blob representation

Parameters:
  • strings

  • pos

  • version

to_dts(tabsize: int = 4, depth: int = 0)[source]

Get string representation

Parameters:
  • tabsize – Tabulator size in count of spaces

  • depth – Start depth for line

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

fdt.parse_dtb(data: bytes, offset: int = 0) FDT[source]

Parse FDT Binary Blob and create FDT Object

Parameters:
  • data – FDT Binary Blob in bytes

  • offset – The offset of input data

fdt.parse_dts(text: str, root_dir: str = '') FDT[source]

Parse DTS text file and create FDT Object

Parameters:
  • text

  • root_dir