🚧 NOTE:
dt-tools
is very experimental!
dt-tools
helps you to write, debug and read Devicetree files more efficiently with advanced tooling!
- IDE integration
- Linting
- Devicetree binding validation
- NOTE: only some basic preprocessor features are supported:
-
#define
s can't take parameters and their expansion can only go in place of names, numbers, strings and cellsTODO: add parametric macros
e.g.
// not allowed: #define MY_MACRO(a) a + 42 #define SPECIAL_SYNTAX ) + ( / { prop = (1 SPECIAL_SYNTAX 2); }; // allowed: #define MAGIC_NUMBER 42 #define MY_NODE_NAME foo #define MY_PROP_NAME bar #define MY_STRING "baz" #define MY_CELL <123 MAGIC_NUMBER> / { MY_NODE_NAME { MY_PROP_NAME = MY_CELL, MY_STRING; }; };
-
#include
can only be used outside of nodes So you can't do this:/ { # include "my-file.dtsi" };
-
#ifdef
,#ifndef
,#if
,#else
and#elif
- Can only be wrap nodes, properties and other preprocessor directives
- They can't be used on property values and
#if
,#else
and#elif
can only check for equality or ordering
-
- Possibly in the future:
- Comparing DTS or DTB files
- Comparing Android
dt
anddtbo
partitions with/sys/firmware/fdt
crates/dt-parser
implements an error-resistant parser inspired by rust-analyzercrates/dt-analyzer
is a source file analyzercrates/dt-lsp
is a language server for devicetreecrates/dt-lint
is a linter - currently only exposed to the LSPcrates/dt-binding-matcher
is a crate supposed to validate and match devicetree binding YAMLs
crates/dt-binding-matcher
could use a little help from the contributors of dt-schema- DTS generator
- Highlight address and size portions of
reg
property - Code to gobble up directories of devicetree bindings. Currently hardcoded to search from
/home/axel/dev/mainlining/linux/Documentation/devicetree/bindings
andcrates/dt-binding-matcher/dt-schema/dtschema
- Currently the schemas aren't stored in the binary and are looked up at runtime
- Add a small cache with a list of matching
compatible
items for simple definitions or wholeselect
JSON schemas along with the root binding documentation
- Take care of code containing
TODO
,FIXME
,todo!
,unimplemented!
or similar - Use arena for allocating the tree(?)
- https://www.cs.cornell.edu/~asampson/blog/flattening.html
- https://github.com/saschagrunert/indextree
- I'll need a mutable normally allocated tree as well
- Use SmallVec for GreenNode's children
- A good and correct way to to get YAML file offsets from JSON Schema
- The easiest way would be with just the schema path, but I think it could lead to incorrect positions
- I'll need a YAML parser in Rust that can reverse paths to file offsets to make LSP integration work
- Fork json-schema-rs or contribute upstream to add a way to
- Add meta-schemas more efficiently than calling
.insert
a bunch of times - Add spans to error reporting?
- Maybe roll out a custom solution so we don't have to fixup everywhere and to support
phandle: true
? - Make its error reporting at least output file information (
$id
and$ref
)
- Add meta-schemas more efficiently than calling
dt-tools
has extensive unit and integration tests, written in Rust. Here's how you can run them!
- Install Rust
- Clone this repo:
git clone --recurse-submodules https://git.axka.fi/dt-tools.git dt-tools cd dt-tools
- Run some commands:
cargo test # Run unit and integration tests # Showcase parser output cargo run --example test_parser ./crates/dt-parser/a.dts cargo run --example test_parser ./syntax_error_showcase.dts # Showcase analyzer output cargo run --example test_analyzer ./syntax_error_showcase.dts
The language server is currently only packaged for Neovim with the ./crates/dt-lsp/lsp.lua
script.
cd ./crates/dt-lsp
nvim -S lsp.lua ../../lint_showcase.dts
Features:
- Fast and safe parser and linter
- (TODO) View binding documentation straight from DTS!
- (TODO) Binding errors integrated into linter
Please first make sure that you have not introduced any regressions and format the code by running the following commands at the repository root.
cargo fmt
cargo clippy
cargo test
You can either make a GitHub pull request or email me directly:
-
Setup
git send-email
: -
Commit your changes, this will open up a text editor
git commit
-
Send your patches to me. The command sends the last commit
git send-email --to="[email protected]" HEAD^
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.