Skip to main content

DTS utility python package

Project description

REUSE status

PyPI - Version PyPI - License PyPI - Python Version

codecov lint unittest doc quality

dts-utils python package

dts-utils is an utility python package that aims to ease dts handling in python and source code generation based on dts files. Dts file parsing, preprocessing, validation are out of scope of this package. This package is built on top of Zephyr devicetree package.

This package was built to fit OutpostOS needs but was designed to be generic enough and code generation language agnostic. Thus, this package can be used by any project which need to use dts files and generate code source or anything else based on it.

Provided dts2src entrypoint is based on Jinja2 template processing, allowing users to fully controlled generated output by providing his/her very own templates.

Dependencies

  • Python >= 3.10
  • Jinja2 >= 3
  • devicetree >= 0.0.2
  • rich

Prerequisites

One may read, as an introduction, the following documentation:

Usage

dts_utils.Dts is the based class, it uses internally devicetree.dtlib.Dts and ease handling by extending class attributes with __getattr__. For Dts object, attributes are resolved, in order, from aliases and then in root Node. For Node, attribute are resolved from child node, label and, then, property. Property are converted according to internal dtlib value type.

Accessing a property or child node is straightforward and simply need to use the dot (.) notation. If node or property contain special characters (e.g. @, ,, #, -) in their name, one should use getattr python built-in.

import dts_utils

dts = dts_utils.Dts('/path/to/dts/file')

# get root node
root = dts.root

# get soc node
soc = dts.soc

# get usart1 device node by label
# labeled node are accessible from dts file or parent node
usart1 = dts.usart1
# OR
usart1 = soc.usart1

# get usart1 device node by name
usart1 = getattr(dts, 'usart@4xxxxxxx')

dts_dump entrypoint

Command line entrypoint that can dump in a pretty formatted form the dts file.

$ dts_dump --help
usage: dts_dump [-h] [-s] [-v] dts [node]

dump a dts in a human readable format

positional arguments:
  dts                dts file
  node               filter on node name or label

options:
  -h, --help         show this help message and exit
  -s, --status-okay  dump only status=okay nodes, except clocks
  -v, --version      show program's version number and exit

Example:

$ dts_dump /path/to/dts usart1
usart1: serial@40013800 {
        compatible = "st,stm32-usart", "st,stm32-uart";
        reg = < 0x40013800 0x400 >;
        clocks = < &rcc 0xa4 0x4000 >;
        resets = < &rctl 0xf8e >;
        interrupts = < 0x3d 0x0 >;
        status = "okay";
        pinctrl-0 = < &usart1_tx_pc1 >, < &usart1_rx_pc0 >;
        phandle = < 0x7 >;
};

dts2src entrypoint

dts2src entrypoint is a helper command line tool that process Jinja2 templates with the given dts file. To ease template writing, built-in jinja extension loopcontrol is enabled, dts object and environment variables are pass to the jinja environment along with custom jinja filters and tests

$ dts2src --help
usage: dts2src [-h] -d DTS -t TEMPLATE [-v] output

render jinja2 template using dts as data source

positional arguments:
  output                output filename

options:
  -h, --help            show this help message and exit
  -d DTS, --dts DTS     dts file to use as data source
  -t TEMPLATE, --template TEMPLATE
                        source template in jinja2 syntax
  -v, --version         show program's version number and exit

access to dts node and property

From Jinja environment, dts_utils.Dts is available as dts. Each nodes and/or properties are available using the dot (.) operator or [] operator (this is required if node or porperty name contains special characters).

e.g.

{{ dts.soc }}

or

{{ dts.usart1['pinctrl-0'] }}

access to environment variable

Environment variables are available, without external jinja extensions. Those are available as a dictionary named env.

e.g.

{{ env.USER }}

License

Copyright 2023 - 2024 Ledger SAS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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

dts_utils-0.3.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

dts_utils-0.3.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file dts_utils-0.3.0.tar.gz.

File metadata

  • Download URL: dts_utils-0.3.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.31.0 requests-toolbelt/0.10.1 urllib3/1.26.17 tqdm/4.65.0 importlib-metadata/6.0.0 keyring/24.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12

File hashes

Hashes for dts_utils-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b33c842d1bf2b9781f11f87b67e1272b1b6b68795b7925ccc6a161bdfa84fd79
MD5 d4f170e54b86b773f6fc0955dd3e3cc1
BLAKE2b-256 be4474b9397625faa64fe68b91de24888908e789ffc707aeefd7152cd4d3a32d

See more details on using hashes here.

File details

Details for the file dts_utils-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dts_utils-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.31.0 requests-toolbelt/0.10.1 urllib3/1.26.17 tqdm/4.65.0 importlib-metadata/6.0.0 keyring/24.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12

File hashes

Hashes for dts_utils-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffdad879b4a87da007d6c09bd168bbfeb65f1299c75ab854844320dc69b250f2
MD5 2d71b6d4d620bd4ad92f80d87e1ba51f
BLAKE2b-256 f5879644675a5f57905e156e9adb093d8229b1bc17c48f77215eaf1ecafb0522

See more details on using hashes here.

Supported by

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