Bind a Linux platform driver
Compile code into a real kernel module and expose MMIO readings through Linux sysfs.
Jump to code and terminal ↓Move ownership into the kernel
The device tree describes the Acme register range and PLIC interrupt. The supplied platform_driver harness uses devm_ioremap_resource, request_irq, and sysfs attributes, and unwinds those resources when you remove the module. Your callbacks execute inside Linux kernel context, not a userspace process.
A small in-browser module toolchain
TinyCC compiles your callbacks against lab_driver.h. build-driver links them with the GCC-built harness and module metadata for this exact source-built kernel. The narrow callback API calls real readl/writel and DMA barriers; it avoids downloading a full GCC compiler and kernel headers. Inspect /usr/lib/lab-driver/lab_driver.h in the terminal.
Probe and read
Use api->read32(api->context, LAB_ID) to verify 0xAC1E0001. Return -19 for an absent device. Enable CONTROL bits 0 and 1, then return zero. The temperature callback reads LAB_TEMPERATURE every time sysfs is read; casting to int preserves signed temperatures.
Your goal
Implement the platform probe callback and temperature reader so Linux binds the sensor and sysfs follows hardware state.
What the tests observe
- The module links and loads inside Linux
- The platform device binds and publishes sysfs
- The reading changes when hardware is disabled and re-enabled
Need a nudge?
Hint 1
The context pointer belongs to the supplied kernel harness. Pass it unchanged to read32 and write32.
Hint 2
Return zero only after identifying and enabling the sensor. A module can load even when its device probe fails.
Hint 3
Use api->write32(api->context, LAB_CONTROL, 3), then implement the temperature callback as a current register read.
What happens inside Linux
insmod invokes Linux's module loader. The platform bus matches the device-tree compatible string, invokes probe, maps the MMIO region, and publishes sysfs attributes. Reading the attribute runs your C callback in the kernel. rmmod disables the source, removes sysfs, and releases managed resources.
Optional account sync. Exercises work without an account.