DeviceTree validation schema and tools
Actively maintained. Last release 2 months ago, commits in 10 of the last 26 weeks. A safe choice.
pip install dtschemaDevicetree Schema Tools
The dtschema module contains tools and schema data for Devicetree schema validation using the json-schema vocabulary. The tools validate Devicetree files using DT binding schema files. The tools also validate the DT binding schema files. Schema files are written in a JSON compatible subset of YAML to be both human and machine readable.
Data Model
To understand how validation works, it is important to understand how schema data is organized and used. If you're reading this, I assume you're already familiar with Devicetree and the .dts file format.
In this repository you will find 2 kinds of data files; Schemas and Meta-Schemas.
Devicetree Schemas
Found under ./dtschema/schemas
Devicetree Schemas describe the format of devicetree data. The raw Devicetree file format is very open ended and doesn't restrict how data is encoded.Hence, it is easy to make mistakes when writing a Devicetree. Schema files impose the constraints on what data can be put into a Devicetree.
This repository contains the 'core' schemas which consists of DT properties defined within the DT Specification and common bindings such as the GPIO, clock, and PHY bindings.
This repository does not contain device specific bindings. Those are currently maintained within the Linux kernel tree alongside Devicetree files (.dts).
When validating, the tool will load all the schema files it can find and then iterate over all the nodes of the Devicetree. For each node, the tool will determine which schema(s) are applicable and make sure the node data matches the schema constraints. Nodes failing a schema test will emit an error. Nodes that don't match any schema can emit a warning.
As a developer, you would write a Devicetree schema file for each new
device binding that you create and add it to the ./schemas directory.
Schema files also have the dual purpose of documenting a binding. When you define a new binding, you only have to create one file that contains both the machine-verifiable data format and the documentation.
Devicetree Schema files are normal YAML files using the jsonschema vocabulary.
The Devicetree Schema files are simplified to make them more compact.
The default for arrays in json-schema is they are variable sized. This can be restricted by defining 'minItems', 'maxItems', and 'additionalItems'. For DeviceTree Schemas, a fixed size is desired in most cases, so these properties are added based on the size of 'items' list.
Devicetree Meta-Schemas
Found in ./dtschema/meta-schemas