Registry / data / fdt
library0.3.3pypypi✓ verified 86d ago

The `fdt` Python library (version 0.3.3) provides utilities for parsing, manipulating, and generating Flattened Device Tree (FDT) structures. It supports both binary DTB and textual DTS formats, allowing programmatic interaction with device tree data commonly used in embedded systems. Releases are infrequent, focusing on bug fixes and minor feature enhancements.

pip install fdt
INSTALL
IMPORT
SIG · FDT
F
fdt
datapythonv0.3.3
Install
1.6s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.004s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FDT
from fdt import FDT

Demonstrates loading Flattened Device Tree data from both a binary DTB blob and a DTS string. Note the requirement for the `dtc` utility for DTS parsing.

import os from fdt import FDT # Example 1: Parsing a binary DTB blob # (Often read from a .dtb file) dtb_blob = b'\xd0\x0d\xfe\xed\x00\x00\x00\x28\x00\x00\x00\x18\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00' try: fdt_dtb = FDT(dtb_blob) print("\n--- Parsed DTB ---") print(fdt_dtb.get_dts()) # Convert to DTS string for display except Exception as e: print(f"Error parsing DTB: {e}") # Example 2: Parsing a DTS string # Requires 'dtc' (Device Tree Compiler) to be installed on the system path. # On Debian/Ubuntu: sudo apt install device-tree-compiler dts_string = """ /dts-v1/; / { compatible = "example,device"; prop1 = <0x12345678>; node1 { prop2 = "hello world"; }; }; """ try: fdt_dts = FDT.from_dts(dts_string) print("\n--- Parsed DTS ---") print(fdt_dts.get_dts()) # Display DTS string node = fdt_dts.get_node("/node1") if node: print(f"Value of prop2 in node1: {node.get_property('prop2').get_value()}") except FileNotFoundError: print("\n--- WARNING: 'dtc' not found. Cannot parse DTS string. ---") print("Please install 'dtc' (Device Tree Compiler) on your system.") except Exception as e: print(f"Error parsing DTS: {e}")
fdt --version
Debug
Known issues
gotchaParsing DTS (Device Tree Source) strings requires the `dtc` (Device Tree Compiler) utility to be installed on your system and available in the PATH. The `fdt` library executes `dtc` as a subprocess for this conversion.
fix
Install `dtc` via your system's package manager (e.g., `sudo apt install device-tree-compiler` on Debian/Ubuntu, or check your distribution's documentation).
affects: All versions
gotchaThe `FDT` constructor directly accepts binary DTB data (`bytes`), while `FDT.from_dts()` is a class method specifically for parsing DTS string data (`str`). Mixing these can lead to parsing errors.
fix
Ensure you use `FDT(binary_dtb_data)` for DTB and `FDT.from_dts(dts_string_data)` for DTS. Do not pass DTS strings directly to the `FDT` constructor.
affects: All versions
Errors
Common errors & fixes
FileNotFoundError: [Errno 2] No such file or directory: 'dtc'
You are attempting to parse a DTS string using `FDT.from_dts()`, but the `dtc` (Device Tree Compiler) utility is not installed or not found in your system's PATH.
fix
Install `dtc` on your operating system. For Debian/Ubuntu, use `sudo apt install device-tree-compiler`. For other systems, consult your distribution's package manager or the official `dtc` documentation.
fdt.FdtException: Error parsing DTB data: 'Invalid FDT magic'
The input provided to the `FDT()` constructor is not valid binary Flattened Device Tree (DTB) data. This often happens if you pass a DTS string, malformed data, or an incorrect file format.
fix
Ensure the input to `FDT()` is valid binary DTB `bytes` data. If you intend to parse a DTS string, use `FDT.from_dts(your_dts_string)` instead (and ensure `dtc` is installed).
fdt.FdtException: Error parsing DTS data: 'Command '['dtc', '-I', 'dts', '-O', 'dtb', '-o', ...
While `dtc` was found, it failed to parse the provided DTS string. This indicates a syntax error or invalid structure within your DTS input.
fix
Carefully review your DTS string for syntax errors, missing semicolons, incorrect property formats, or malformed nodes. You can try running `dtc -I dts -O dtb -o /dev/null your_file.dts` directly in your terminal to get more specific error messages from `dtc`.
Upgrade
Version history
0.3.3latest on PyPI · released Jul 8, 2022
Audit
Dependencies
dtc (Device Tree Compiler)optionalRequired system-wide for parsing DTS (Device Tree Source) files using `FDT.from_dts()`. This is typically installed via your system's package manager (e.g., `apt install device-tree-compiler` on Debian/Ubuntu).
Agent activity
10 hits · last 30 days
node
10
Resources
fdt — pip install fdt · libregistry