pydevicetree
This is a Python 3 library for parsing, querying, and modifying Devicetree Source v1 files as described in the Devicetree Specification v0.2.
Tutorial
The Devicetree
Let's say you have a file design.dts with the contents
/dts-v1/;
chosen {
stdout-path = "/soc/uart@10000000:115200";
};
/ {
#address-cells = <1>;
#size-cells = <1>;
compatible = "my,design";
cpus {
cpu@0 {
#size-cells = <0>;
compatible = "sifive,rocket0", "riscv";
device_type = "cpu";
reg = <0>;
riscv,isa = "rv32imac";
status = "okay";
timebase-frequency = <1000000>;
sifive,dtim = <&dtim>;
interrupt-controller {
#interrupt-cells = <1>;
compatible = "riscv,cpu-intc";
interrupt-controller;
};
};
};
soc {
#address-cells = <1>;
#size-cells = <1>;
compatible = "my,design-soc";
ranges;
dtim: dtim@20000000 {
compatible = "sifive,dtim0";
reg = <0x20000000 0x10000000>;
reg-names = "mem";
};
uart: uart@10000000 {
compatible = "sifive,uart0";
reg = <0x10000000 0x1000>;
reg-names = "control";
};
};
};
Parsing the Tree
Parsing the tree is as easy as 1, 2...
>>> from pydevicetree import Devicetree
>>> tree = Devicetree.parseFile("design.dts")
>>> tree
<Devicetree my,design>
Querying the Tree
By compatible string
>>> tree.match("sifive,rocket0")
[<Node cpu>]
Getting Node properties
>>> tree.match("sifive,rocket0")[0].get_field("timebase-frequency")
1000000
>>> tree.match("sifive,rocket0")[0].get_fields("compatible")
<StringList ['sifive,rocket0', 'riscv']>
Getting chosen properties
>>> tree.chosen("stdout-path")
<StringList ['/soc/uart@10000000:115200']>
Converting back to Devicetree
Any tree or subtree can be converted back to Devicetree by calling Node.to_dts() or simply
by printing it:
>>> print(tree.match("sifive,rocket0")[0])
cpu@0 {
#size-cells = <0>;
compatible = "sifive,rocket0", "riscv";
device_type = "cpu";
reg = <0x0>;
riscv,isa = "rv32imac";
status = "okay";
timebase-frequency = <1000000>;
sifive,dtim = <&dtim>;
interrupt-controller {
#interrupt-cells = <1>;
compatible = "riscv,cpu-intc";
interrupt-controller;
};
};
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydevicetree-0.0.4.tar.gz.
File metadata
- Download URL: pydevicetree-0.0.4.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27c2b1270de76b1ed569136e4b302d6d43a0a7ea3552cd3de45e24520042682f
|
|
| MD5 |
4ea2211b6f7bdeed1eb78ce1173de067
|
|
| BLAKE2b-256 |
c15ebce12ac061421b6841b2a96f0aef6a033c267e4392a6d0a673b1036d9b6e
|
File details
Details for the file pydevicetree-0.0.4-py3-none-any.whl.
File metadata
- Download URL: pydevicetree-0.0.4-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
547d7a64828aef24793d650c8a51a19ecce11348cdc44ee6a9cdfebabf07d317
|
|
| MD5 |
375c6fdce440c682e92a443d6f408a51
|
|
| BLAKE2b-256 |
e698f8dd846690f457c10d419f86a6c4b817bef12206ad490845cb2ce6bd5ae0
|