Quick Start
This guide walks you through creating, compiling, and running a KDAL driver from scratch.
Prerequisites
Section titled “Prerequisites”- KDAL SDK installed (Installation Guide)
kdalcandkdalityon your PATH
Your First Driver
Section titled “Your First Driver”-
Scaffold a new project:
Terminal window kdality init hello_led --class gpiocd hello_ledThis creates:
hello_led/├── hello_led.kdh # Device header├── hello_led_driver.kdc # Driver code├── Makefile # make compile, make module└── README.md # NotesThe generated files already build:
make compileworks before you change anything. -
Edit the device header (
hello_led.kdh):kdal_version: "0.1";device class HelloLed {compatible "example,hello-led";class gpio;registers {CTRL : u32 @ 0x00 rw = 0x00;STATE : u32 @ 0x04 ro;}signals {toggle : in edge(rising);}power {on : allowed;off : allowed;default : on;}} -
Implement the driver (
hello_led_driver.kdc). The header is imported under a name (LED), and every register and signal is reached through it:kdal_version: "0.1";import "hello_led.kdh" as LED;driver HelloLedDriver for LED.HelloLed {probe {write(LED.CTRL, 0x01);log("hello_led: initialized\n");}remove {write(LED.CTRL, 0x00);log("hello_led: removed\n");}on read(LED.STATE) {wait(LED.toggle, 1000);}on write(LED.CTRL, val) {write(LED.CTRL, val);}on signal(LED.toggle) {let current = read(LED.STATE);if (current == 0x01) {write(LED.CTRL, 0x00);} else {write(LED.CTRL, 0x01);}}on power(on -> off) {write(LED.CTRL, 0x00);}on power(off -> on) {write(LED.CTRL, 0x01);}} -
Lint the sources:
Terminal window kdality lint hello_led.kdhkdality lint hello_led_driver.kdc -
Compile to kernel C:
Terminal window make compile # runs: kdality compile hello_led_driver.kdc -o outputThis produces:
output/HelloLedDriver.c- the kernel module source (named after the driver)output/Makefile.kbuild- Kbuild Makefile formake modules
-
Build the kernel module:
Terminal window make module KDIR=/path/to/kernel/build -
Load it in QEMU:
Terminal window cp output/HelloLedDriver.ko /path/to/shared/# Inside the QEMU guest:insmod /mnt/modules/HelloLedDriver.ko
Simulating Without a Kernel
Section titled “Simulating Without a Kernel”You can dry-run your driver without building a kernel module:
kdality simulate hello_led_driver.kdcThis runs an interpreter that traces register reads/writes to stdout.
Generating Tests
Section titled “Generating Tests”Auto-generate KUnit test stubs from your driver:
kdality test-gen hello_led_driver.kdc -o tests/ # writes tests/test_HelloLedDriver.cGenerating Device Tree Overlays
Section titled “Generating Device Tree Overlays”If your target uses Device Tree:
kdality dt-gen hello_led.kdh -o dts/ # writes dts/HelloLed.dtsoNext Steps
Section titled “Next Steps”- Language Overview - understand
.kdhand.kdcin depth - Standard Library - pre-built device headers for UART, I2C, SPI, GPIO, GPU, NPU
- Editor Support - VS Code extension and Vim plugin