We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
Zephyr 项目(一个使用设备树的 RTOS)似乎附带了一个相当通用的 Python 模块 dtlib 来解析设备树源文件。该模块是 Zephyr 源代码树的一部分,存储在 脚本/dts/dtlib.py。
2021 年 12 月更新
看来这已被分离到自己的存储库中,可在 https://github.com/zephyrproject-rtos/python-devicetree。
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.
目前还没有 libfdt(dtc 附带的设备树操作库)的 Python 绑定,但创建一个应该相当简单。
如果您有兴趣这样做,Python 文档有一些关于使用 c 模块扩展 python 的内容: http://docs.python.org/release/2.6/extending/extending.html 。
swig
实用程序可用于自动创建 Python 到 C 的接口,因此您最终只需编写一个小的 swig 配置文件即可。如果您最终这样做了,请将人员发送至 [email& nbsp;受保护]一封电子邮件 - 我们很想听听您的进展!
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 用于解析 dtb 文件而不是设备树文件(dts/dtsi),因此读取 libfdt 可能没有帮助,并且您不能简单地使用 SWIG 创建现有设备解析器的 python 绑定。
由于 dtc 使用 lex/yacc 作为解析工具,并且其语法定义在内核中可用,因此我建议您可以在 python 中使用 lex/yacc ([PLY]:http://www.dabeaz.com/ply/) 来编写您自己的设备树解析器。
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.