Skip to content

nakane1chome/development-utils

Repository files navigation

development-utils

Code generation tools for embedded development that use flexible user defined templates to generate from device and interface definition formats or reverse compiling formats.

Supported Input Formats

Installation

From source

git clone https://github.com/nakane1chome/development-utils.git
cd development-utils
pip install -e .

Install dependencies only

pip install -r requirements.txt

Tools

This package provides command-line tools for generating code from various embedded development formats:

SVD (CMSIS System View Description)

svd-jinja device.svd --templates templates/ --device device_template.html --out-path output/

RDL (SystemRDL Register Description)

rdl-jinja design.rdl --templates templates/ --component component_template.html --out-path output/

IDL (Interface Definition Language)

idl-jinja interface.idl --template template.j2 --out output.txt --templates templates/
idl-jinja-bridle interface.idl --template template.j2 --out output.txt --templates templates/

DBML (Database Markup Language)

dbml-jinja schema.dbml templates/ output/

Device Tree (DTS)

dts2yaml device.dts -o device.yaml  # Convert DTS to YAML
yaml-jinja device.yaml --template template.j2 --out output.txt --templates templates/

Objdump Disassembly

objdump-jinja disassembly.txt --template template.j2 --out output.html --templates templates/

Features

  • SVD Templates: Generate code/documentation from CMSIS-SVD files
  • RDL Templates: Generate HTML maps and documentation from SystemRDL files
  • IDL Processing: Parse and generate code from Interface Definition Language files
  • DBML Templates: Generate SQLAlchemy models, Pydantic schemas, and documentation from database schemas
  • YAML Processing: Process device tree and configuration YAML files
  • Objdump Parsing: Generate documentation from disassembly listings

Template Files

Template files use the Jinja2 templating engine and should have the .jinja2 extension to clearly identify them as templates. For example:

  • device_template.html.jinja2 - Template that generates HTML output
  • peripheral_mmio_regs.hpp.jinja2 - Template that generates C++ header files
  • component_map.html.jinja2 - Template for RDL component maps

When generating output files, the .jinja2 extension is automatically stripped from the filename. The output filename is derived from the template filename by:

  1. Replacing placeholder text (e.g., device, peripheral, component) with actual names
  2. Removing the .jinja2 suffix

Example: Template peripheral_mmio_regs.hpp.jinja2 generates TIMER0_mmio_regs.hpp, UART0_mmio_regs.hpp, etc.

This convention makes it easy to identify template files while ensuring generated files have the correct extensions for their content type.

Examples

Database Schema Code Generation (DBML)

Generate SQLAlchemy models, Pydantic schemas, and documentation from DBML schemas:

# Generate SQLAlchemy models
dbml-jinja schema.dbml templates/dbml_jinja/sqlalchemy output/models/

# Generate documentation
dbml-jinja schema.dbml templates/dbml_jinja/docs output/docs/

Example DBML schema:

Table users {
  id varchar [pk]
  username varchar [not null]
  email varchar [unique, not null]
  created_at datetime [not null]
}

Table posts {
  id varchar [pk]
  title varchar [not null]
  user_id varchar [ref: > users.id]
}

See examples/dbml_jinja.sh and templates/dbml_jinja/ for complete examples.

C++ MMIO Register Access Classes

Install g++-arm-linux-gnueabi to compile the generated examples and create dissasembly.

sudo apt-get install `g++-arm-linux-gnueabi`

The project also includes C++ templates for generating MMIO register access classes:

  • C++17 MMIO interface in cxx17_mmio_interface/
  • C++20 MMIO interface in cxx20_mmio_interface/
  • C QEMU device stubs in c_qemu_svd_stubs/

See:

RISC-V CSR Register Access Classes

Based on this tooling, generation of C, C++ and Rust register access code:

C QEMU Device Model Stubs

Generate plain C code for QEMU device model implementations from SVD files:

svd-jinja device.svd \
    --templates c_qemu_svd_stubs/template/ \
    --device device.h.jinja2 \
    --peripheral peripheral_regs.h.jinja2 \
    --peripheral peripheral_qemu_stub.c.jinja2 \
    --peripheral peripheral_qemu_stub.h.jinja2 \
    --out-path output/

Generated files include:

  • <device>.h - Device base addresses and IRQ numbers
  • <peripheral>_regs.h - Register offsets, field masks, and accessor macros
  • <peripheral>_qemu_stub.c - QEMU device model with read/write handlers
  • <peripheral>_qemu_stub.h - QEMU device header

The templates use C preprocessor macros instead of C++ constexpr/templates, making them suitable for QEMU's C codebase. See examples/svd_c_qemu_stubs.sh for a complete example.

Development

Install development dependencies:

pip install -e ".[dev]"

Run tests:

pytest

About

Scripts and templates for assisting development. Code generators, MMIO Register interfaces.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors