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!
libfdt is used to parse dtb file instead of device tree file (dts/dtsi), so it might not help to read libfdt, and you can't simply use SWIG to create a python binding of existing device parser. Since dtc uses lex/yacc as the parsing tool and its syntax definition is available in kernel, I suggest you could use lex/yacc in python ([PLY]:http://www.dabeaz.com/ply/) to compose your own device tree parser.
© 2022 - 2024 — McMap. All rights reserved.