-
Notifications
You must be signed in to change notification settings - Fork 8.1k
[RFC] tools: Integrate DTSh, a shell-like interface to Devicetree, as an optional module project (v2) #59863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7057216
to
66b9925
Compare
7f86207
to
b170331
Compare
I think VS Code extension: nRF DeviceTree is a good graphical tool. But it's not open source. Not particularly friendly to non-nRF devices |
b1c9d74
to
b5d6d2c
Compare
Thanks for this. I think it's a great idea and I especially appreciate the attention to detail you put into the RFC as well as volunteering maintenance. Consider me onboard with this idea. I'll give it some testing and review. |
Some unboxing comments:
I can't get tab completion working as I expect using the homebrew python 3.11. From the prompt:
I press TAB and expect commands to be completed. But instead I see a tab character is inserted. Is that expected? Here is my python info (using a virtual environment):
I can The command parser also doesn't seem to be stripping leading whitespace:
this isn't like what you'd expect from a shell in my opinion -- I would expect both of those to quit. |
Assuming that it is up to me to decide among acceptable approaches, I can propose:
If we agree on this base, I will prepare the corresponding new PRs. Thanks. |
So this would be solution number 1 listed in the outcome of the Architecture WG meeting on February 4th, 2025 (#59863 (comment)). I think that's a good solution. CC: @carlescufi |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Integrate DTSh, a shell-like interface to Devicetree, as an optional module project providing a new West extension: $ west build $ west dtsh dtsh (0.2.2): Shell-like interface with Devicetree How to exit: q, or quit, or exit, or press Ctrl-D / > cd &flash_controller /soc/flash-controller@4001e000 > ls -l Name Labels Binding ───────────────────────────── flash@0 flash0 soc-nv-flash Part of RFC zephyrproject-rtos#59863. Signed-off-by: Christophe Dufaza <[email protected]>
Add a brief entry to zephyr-cmds.rst to improve discoverability, especially since west --help won't show the dtsh command. Part of RFC zephyrproject-rtos#59863. Signed-off-by: Christophe Dufaza <[email protected]>
The following west manifest projects have changed revision in this Pull Request:
⛔ DNM label due to: 1 added project and 1 unreachable repo Note: This message is automatically posted and updated by the Manifest GitHub Action. |
Add a brief entry to zephyr-cmds.rst to improve discoverability, especially since west --help won't show the dtsh command. Part of RFC zephyrproject-rtos#59863. Signed-off-by: Christophe Dufaza <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please list this in https://docs.zephyrproject.org/latest/develop/manifest/index.html#external-projects-modules instead. This is inline with this RFC from @nashif: #91061
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I wasn't aware of this issue and related changes.
Can we still keep a brief entry in zephyr-cmds.rst
for better visibility of the West command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should go into the documentation for the module (i.e. https://docs.zephyrproject.org/latest/develop/manifest/external/dtsh.html).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this will be more consistent with the other external modules (AFAICT they don't add a West extension, though).
|
I have largely rewritten the RFC description to focus on this approach (an optional/external module project): this should clarify where this long and sometimes confusing conversation has taken us, what needs review, and what the remaining issues are. I also updated the PR accordingly: with this approach, changes to the With Zephyr 4.3 reaching Fearure Freeze in the next few days, I think we should try (one last time) to postpone DTSh integration (to milestone 4.4). Hope this helps. Thanks. |
If this ends up just being a documentation change, it can even go in after the feature freeze. |
Introduction
Note
This RFC initially proposed moving DTSh development to Zephyr’s devicetree tooling, sibling to the
python-devicetree
library.The conversation showed that such close integration was questionable, especially:
Acceptable approaches were eventually selected during an Architecture WG meeting on February, 2025 (minutes).
Among these, it seems there is now some consensus to integrate DTSh as an optional project (@henrikbrixandersen , @decsny): this second version of the RFC follows this design. Thanks for your feedback.
Problem description
When I was first getting to know Zephyr's use of Devicetree, I wished I had a quick and easy tool at hand to explore the DTS files generated at build time:
Others had already experienced a comparable lack, still without an obvious answer, see e.g. #29295, October 2020:
Proposed Change (Summary)
DTSh is an interactive DTS files viewer with a shell-like command line interface: the devicetree is presented as a hierarchical file system, navigated and queried with familiar commands like
cd
,ls
orfind
. Commands output redirection with e.g.>
permits to export custom reproducible views of the devicetree to text, HTML, or SVG files.The
dtsh
shell has a rich user interface (contextual auto-completion, commands history, semantic highlighting, pager integration, user profiles). It can also execute commands or scripts non-interactively.Please refer to the DTSh manual for details.
The proposed change is a new West command, provided by an optional project, that opens DTS files in
dtsh
:where:
west dtsh
: called without argument, the command will open the DTS filebuild/zephyr/zephyr.dts
, and retrieve the bindings that Zephyr used at build-time from the CMake cache filebuild/CMakeCache.txt
cd &flash_controller
changes the current working branch from the devicetree's root to the node at/soc/flash-controller@4001e000
, using its DTS labelflash_controller
find
is with no surprise a shell command that will search for devices, bindings, buses, interrupts, etc-E --also-known-as (image|storage).*
will match nodes with a label or alias starting withimage
orstorage
; predicates like--with-reg-size >4k
are also supported--format NKd
: set the node output format to the columns "nodeN
ame,", "AlsoK
nown As" (all labels and aliases), and "d
escription" (D
is the "Depends-on" column)-T
: list found nodes in tree-like format> doc/partitions.svg
to the last command line would save the partitions tree to the filedoc/partitions.svg
, in SVG formatDetailed RFC
This RFC proposes integrating DTSh as an optional module project.
Proposed Change (Detailed)
With this approach, changes to the
zephyrproject-rtos/zephyr
repository are minimal:submanifests/optional.yaml
zephyr-cmds.rst
to introduce the West commandOptional project
Add optional project
zephyrproject-rtos/dtsh
tosubmanifests/optional.yaml
:The proposed project layout is given bellow:
where:
lib/dtsh
contains DTSh implementationscripts
contains the West extension added by the projecttests
contains DTSh unit testszephyr
contains the Zephyr module definition, mainly to benefit from thewest packages
commodityDocumentation
Although the main documentation should belong to
zephyrproject-rtos/dtsh
, adding a brief entry tozephyr-cmds.rst
might improve discoverability, especially sincewest --help
won't show thedtsh
command.Dependencies
DTSh is implemented in Python, with few dependencies:
External dependencies
These are external Python libraries needed to run
west dtsh
that have not already been installed with Zephyr requirements:These dependencies will be installed as module requirements with:
Note
For auto-completion, command history and key bindings, DTSh relies on the
readline
module of the Python standard library.On POSIX-like systems, the underlying Readline library API may be implemented by the
libedit
library instead of GNU readline which DTSh expects. On macOS, wherelibedit
will likely be the default for most Python distributions, DTSh will substitute the shippedreadline
module withgnureadline
, which is statically linked to GNU Readline.On MS Windows, the
readline
module has a rather eventful history, e.g.:In a nutshell, although the situation is improving (Python 3.13 for MS Windows includes an almost complete
readline
module, and Python 3.14 should be fine), Readline support will very likely be disabled on MS Windows, resulting in a degraded user experience.This kind of small differences in the non-essential tools available across platforms is deemed acceptable.
python-devicetree
DTSh relies on Zephyr’s python-devicetree library for loading DTS and binding files into Devicetree models.
We agreed (see comment) that
west dtsh
should always import thedevicetree
package from$ZEPHYR_BASE/scripts/dts/python-devicetree/src
(in-tree): it is therefore not a requirement of the module.DTSh is however developed out-of-tree, and may be distributed and used outside of Zephyr: in these contexts, we should not depend on any
ZEPHYR_BASE
. For this, we agreed that regular updates to the python-devicetree release available on PyPI would definitely be a plus, and @mbolivar seems quite willing to take it on.Note
Although not a priority, compatibility with other users of the Devicetree specifications, such as the Linux kernel, was part of Zephyr Design goals.
DTSh shares this hope hand in hand with
edtlib
, even if not in a foreseeable future.Concerns and Unresolved Questions
Repositories and policies
The development of DTSh continues in the repository dottspina/dtsh.
Integration with Zephyr is carried out within the optional project
zephyrproject-rtos/dtsh
(to be created). Also being a module, its default branch should be namedzephyr
.It is not considered a direct downstream of
dottspina/dtsh
, and may not preserve its whole folder structure.Bellow are a some policies that I think are reasonable, and largely match the Module Repositories guidelines:
.github/workflows/
)dottspina/dtsh
(subject to exceptions)west dtsh
should first report issues to the module repository, they will be upstreamed todottspina/dtsh
if appropriatedtsh
updates, be a default assignee, CI configuration)These rules are probably not detailed enough: to be supplemented with the help of reviewers.
Note
For example, the PR fails compliance tests at:
CI shows a similar error:
Should I propose adding myself somewhere in the MAINTAINERS file, or ask for a volunteer ?
Kconfig
From Build system integration:
Although the DTSh module does not actually integrate with Zephyr build system, should we include a minimal
Kconfig
file to at least defineZEPHYR_DTSH_MODULE
?Security
The proposed change is not that hazardous:
dtsh
does not evaluate (eval()
) any part of the user inputdtsh
does not pipe any part of the user input to the system interpreter (e.g.os.system()
)dtsh
will not override user files, excepted when appending a redirected command output to an existing file$XDG_CONFIG_HOME
or%LOCALAPPDATA%
)West command completion
I didn't figure out how to integrate with West commands completion (we can't add ourselves to the
scripts/west_commands/completion/west-completion.*
files as Zephyr extensions usually do).Personal biases
Why a command line application ? Well, when you've done
west build
, you're already at the command line, and I think continuing from there withwest dtsh
, getting a different prompt but the same user interface paradigms and even key bindings (the base ones used by Zsh, GNU Bash, Emacs, GDB), is more ditrsaction-free than opening a GUI.Beyond this personal biases, things like PyGObject or Qt for Python have nonetheless been considered, but:
Alternatives Considered
There doesn't seem to be many DTS file viewers, and even fewer that support Zephyr's bindings.
Nordic Semiconductor's distributes the nRF DeviceTree extension for VS Code, which looks interesting but does not address the initial problem (as @hongshui3000 also pointed out):
Work on the more ambitious RFC - DTV (Device Tree Visualiser) appears to have stopped in 2020.