Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Linux device tree parser in python? [closed]

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.

like image 633
jbrogdon Avatar asked Jul 04 '10 20:07

jbrogdon


2 Answers

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.

like image 52
falstaff Avatar answered Nov 13 '22 23:11

falstaff


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!

like image 42
Jeremy Kerr Avatar answered Nov 13 '22 23:11

Jeremy Kerr