kdality CLI
kdality is the all-in-one command-line tool for KDAL development.
It wraps the compiler and adds project scaffolding, simulation, linting,
test generation, device-tree generation, and runtime control.
kdality <subcommand> [options] [arguments]The six toolchain subcommands below each take -h or --help. Any other
first argument is a runtime command (version, list, info, power,
read, write; see Runtime control), which needs the
kdal module loaded.
Subcommands
Section titled “Subcommands”compile - Compile a driver
Section titled “compile - Compile a driver”Translates a .kdc file into C and a kbuild fragment (links libkdalc.a
internally). The generated module does not build yet (open finding O7 in
KDAL’s docs/open-findings-20261121.md).
kdality compile [options] <file.kdc>| Flag | Argument | Description |
|---|---|---|
-o |
<dir> |
Output directory (default: .) |
-K |
<dir> |
Kernel build directory (KDIR) |
-x |
<pfx> |
CROSS_COMPILE prefix |
-v |
- | Verbose output |
-h |
- | Show help |
Output: <driver>.c + Makefile.kbuild
init - Scaffold a new project
Section titled “init - Scaffold a new project”Creates a ready-to-build KDAL driver project directory.
kdality init <name> [--class <class>] [--vendor <vendor>]| Flag | Argument | Default | Description |
|---|---|---|---|
--class |
<class> |
gpio |
Device class: uart, i2c, spi, gpio, gpu, npu |
--vendor |
<vendor> |
example |
Device-tree compatible prefix |
-h |
- | - | Show help |
Created files:
| File | Description |
|---|---|
<name>.kdh |
Device header with registers and signals for the chosen class |
<name>_driver.kdc |
Driver skeleton with probe/remove handlers |
Makefile |
Build rules: compile (the default), module (needs KDIR), clean |
README.md |
Getting-started instructions |
The project goes in a new directory <name>/. The name must start with a
letter and contain only letters, digits and underscores.
Example:
kdality init my_sensor --class i2c --vendor acmecd my_sensor/make # kdality compile into output/kdality lint my_sensor_driver.kdc # static analysiskdality simulate my_sensor_driver.kdc # dry runsimulate - Dry-run a driver
Section titled “simulate - Dry-run a driver”Traces driver execution without a kernel, using a virtual register file.
kdality simulate <file.kdc> [--trace] [--event <name>]| Flag | Argument | Description |
|---|---|---|
--trace |
- | Print step-by-step execution trace |
--event |
<name> |
Simulate a specific event handler |
The simulator maintains up to 64 virtual registers and prints each
read/write operation, handler by handler (here the quickstart’s driver,
with --trace):
── Simulating: probe ── [0] reg_write(CTRL, 0x1) [new]
── Simulating: remove ── [0] reg_write(CTRL, 0x0) [was 0x1]This is useful for newcomers to visualise driver behaviour before compiling and loading onto real hardware.
lint - Static analysis
Section titled “lint - Static analysis”Checks .kdh and .kdc files for common mistakes.
kdality lint <file.kdc|file.kdh> [--strict]| Flag | Description |
|---|---|
--strict |
Also report W008, W009 and W010 |
Lint rules
Section titled “Lint rules”| Code | Severity | Description |
|---|---|---|
E001 |
Error | The file does not parse, or has no device (.kdh) or driver (.kdc) declaration |
E002 |
Error | An imported header is not found (next to the .kdc, or in the standard library; KDAL_STDLIB_DIR overrides) |
W001 |
Warning | Missing probe handler |
W002 |
Warning | Missing remove handler (resource leak risk) |
W003 |
Warning | Write to read-only register |
W004 |
Warning | Read from write-only register |
W005 |
Warning | Empty handler body |
W006 |
Warning | Missing use statement (no device header imported) |
W007 |
Warning | Unused register (declared but never accessed; not reported for a standard-library header) |
W008 |
Warning | No power handler (--strict only) |
W009 |
Warning | A literal above 0xFF written by reg_write (--strict only) |
W010 |
Warning | No compatible string (--strict only) |
test-gen - Generate KUnit tests
Section titled “test-gen - Generate KUnit tests”Auto-generates KUnit test stubs from a .kdc driver.
kdality test-gen <file.kdc> [-o <dir>]| Flag | Argument | Default | Description |
|---|---|---|---|
-o |
<dir> |
. |
Output directory |
-h |
- | - | Show help |
Output: test_<driver>.c containing:
- SPDX header and
#include <kunit/test.h> - a test context and its
initfixture - one
KUNIT_CASEper event handler found in the driver - suite registration and
MODULE_LICENSE
Known issue: the generated names come from the driver’s name as written, so a driver name that is not a C identifier gives a file that does not compile.
dt-gen - Generate Device Tree overlay
Section titled “dt-gen - Generate Device Tree overlay”Produces a .dtso (Device Tree Source Overlay) from a .kdh device header.
kdality dt-gen <file.kdh> [-o <dir>] [--base-addr <addr>] [--irq <num>]| Flag | Argument | Default | Description |
|---|---|---|---|
-o |
<dir> |
. |
Output directory |
--base-addr |
<addr> |
0x10000000 |
Base MMIO address (hex) |
--irq |
<num> |
none | Interrupt number (decimal); without it the overlay has no interrupts |
-h |
- | - | Show help |
The generator parses the .kdh for device name, compatible string,
and register offsets. The region size is the highest register offset plus
4, at least 0x100. A .kdh without a compatible string gets
kdal,<name>.
Runtime control
Section titled “Runtime control”The runtime commands talk to loaded KDAL drivers through /dev/kdal
ioctls (tools/kdality/kdalctl.c). There is no kdalctl subcommand: the
command is the first argument.
kdality <command> [arguments]| Command | Arguments | Description |
|---|---|---|
version |
- | Kernel module version (without the module: the tool’s) |
list |
- | List all registered KDAL devices |
info |
<name> |
Show device details (class, power state, features, caps) |
power |
<name> <state> |
Set power state: on, off, suspend |
read |
<name> <count> |
Read bytes from a device |
write |
<name> <data> |
Write a string to a device |
read and write select the device themselves (KDAL_IOCTL_SELECT_DEV).
Example (the output format of kdalctl.c; the values are illustrative):
kdality list# Registered devices (1):# my_sensor
kdality info my_sensor# Device: my_sensor# class: i2c (2)# power: on (1)# features: 0x00000003# caps: 2
kdality power my_sensor suspend# my_sensor: power → suspendSource Files
Section titled “Source Files”| File | Purpose |
|---|---|
tools/kdality/main.c |
Subcommand dispatcher |
tools/kdality/compile.c |
compile subcommand |
tools/kdality/init.c |
init - project scaffolding |
tools/kdality/simulate.c |
simulate - dry-run interpreter |
tools/kdality/lint.c |
lint - static analysis |
tools/kdality/testgen.c |
test-gen - KUnit test generator |
tools/kdality/dtgen.c |
dt-gen - Device Tree overlay generator |
tools/kdality/kdalctl.c |
Runtime commands over /dev/kdal |
tools/kdality/templates.h |
Embedded templates for init |
tools/kdality/paths.h |
Checks on the paths typed on the command line |