Skip to main content

DeviceTree validation schema and tools

Project description

Tooling for devicetree validation using YAML and jsonschema

This repository contains test code for devicetree schema validation using the json-schema vocabulary. Schema files are written in YAML (a superset of JSON), and operate on the YAML encoding of Devicetree data. Devicetree data must be transcoded from DTS to YAML before being used by this tool.

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 three kinds of files; YAML Devicetrees, Schemas and Meta-Schemas.

YAML Devicetrees

Found under ./test

YAML Devicetrees files are regular .dts files transcoded into a YAML representation. There is no special information in these files. They are used as test cases against the validation tooling.

Validation of .dtb files is now supported and preferred over YAML DT encoding.

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 constraints on what data can be put into a devicetree. As the foundation, a single core schema describes all the common property types that every devicetree node must match. e.g. In every node the 'compatible' property must be an array of strings. However, most devicetree data is heterogeneous as each device binding requires a different set of data, therefore multiple schema files are used to capture the data format of an entire devicetree.

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 will 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. Documentation generation tools are being written to extract documentation from a schema file and emit a format that can be included in the devicetree specification documents.

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.

The YAML DeviceTree format also makes all string values an array and scalar values a matrix (in order to define groupings) even when only a single value is present. Single entries in schemas are fixed up to match this encoding.

Devicetree Meta-Schemas

Found in ./dtschema/meta-schemas

Devicetree Meta-Schemas describe the data format of Devicetree Schema files. The Meta-schemas make sure all the binding schemas are in the correct format and the tool will emit an error if the format is incorrect.

As a developer you normally will not need to write metaschema files.

Devicetree Meta-Schema files are normal YAML files using the jsonschema vocabulary.

Usage

There are several tools available in the tools/ directory.

tools/dt-doc-validate This tool takes a schema file(s) or directory of schema files and validates them against the DT meta-schema.

tools/dt-mk-schema This tool takes user-provided schema file(s) plus the core schema files in this repo, removes everything not needed for validation, applies fix-ups to the schemas, and outputs a single file with the processed schema. This step is done separately to speed up subsequent validation of YAML Devicetrees.

tools/dt-validate This tool takes user-provided YAML Devicetree(s) and either a schema directory or pre-processed schema file and validates the YAML Devicetree against the schema.

Installing

The project and its dependencies can be installed with pip:

pip3 install dtschema

or directly from git:

pip3 install git+https://github.com/devicetree-org/dt-schema.git@main

All executables will be installed. Ensure ~/.local/bin is in the PATH.

For development, clone the git repository manually and run pip on local tree::

git clone https://github.com/devicetree-org/dt-schema.git
cd dt-schema
pip3 install -e .

Dependencies

Note: The above installation instructions handle all of the dependencies automatically.

This code depends on Python 3 with the pylibfdt, ruamel.yaml, rfc3987, and jsonschema libraries. Installing pylibfdt depends on the 'swig' program.

On Debian/Ubuntu, the dependencies can be installed with apt and/or pip. The rfc3987 module is not packaged, so pip must be used:

sudo apt install swig
sudo apt install python3 python3-ruamel.yaml
pip3 install rfc3987

jsonschema

This code depends on at least version 4.1.2 of the Python jsonschema library for Draft 2019-09 support.

The module can be installed directly from github with pip:

pip3 install git+https://github.com/Julian/jsonschema.git

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dtschema-2022.8.1.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dtschema-2022.8.1-py3-none-any.whl (80.8 kB view details)

Uploaded Python 3

File details

Details for the file dtschema-2022.8.1.tar.gz.

File metadata

  • Download URL: dtschema-2022.8.1.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for dtschema-2022.8.1.tar.gz
Algorithm Hash digest
SHA256 3e56a9920944223d6f93fd51ada19dd8db554ac9182ef52c1c5c9d4966ab30aa
MD5 489f4fcff1792164351aeee4ab7822d1
BLAKE2b-256 79cd0a010841e4f8f82671237b65e77ee8fd305dde81b99fcdbdba6d159577b9

See more details on using hashes here.

File details

Details for the file dtschema-2022.8.1-py3-none-any.whl.

File metadata

  • Download URL: dtschema-2022.8.1-py3-none-any.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for dtschema-2022.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 533098857601aa010b2d8e872b91ac509044c49a381a4af38d1cb6187965a42d
MD5 e38e06e1146eaa66b574ac817ff0a45c
BLAKE2b-256 1ab462f08ed6ea0fa4e6fec16dfa00ec32169fb3200629a96dd0102ced1a20cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page