I am looking to create a utility that validates Embedded (PPC or ARM) Linux *.dts (device tree source) or *.dtb (binary) files against an XML configuration file from another tool. So, I need to parse the dts or dtb files. I would really like to do this with Python. Does anyone know of a Python library or tool out there that parses dts or dtb files? A Python implementation of the device tree compiler (dtc) would be perfect, but I've not seen one yet.
It seems that the Zephyr project (a RTOS making use device trees) comes with a rather generic Python module dtlib
to parse device tree source files. The module is part of the Zephyr source tree and stored in scripts/dts/dtlib.py.
Update December 2021
It seems that this got separated into its own repository available at https://github.com/zephyrproject-rtos/python-devicetree.
There is no python binding for libfdt (the device tree manipulation library shipped with dtc) yet, but it should be fairly straightforward to create one.
If you're interested in doing this, the Python docs have a bit about extending python using c modules: http://docs.python.org/release/2.6/extending/extending.html . The swig
utility can be used to automatically create the Python-to-C interface, so you just end up writing a small swig configuration file.
If you do end up doing this, send the folks at [email protected] an email - we'd be keen to hear how you go!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With