ECE 440 · Week 4
Modern Computer: Full Stack
What a bind line looks like in the kernel log, and which job stays in userspace.
Week 4 of 10 · Solitude
ECE 440 · Week 4 · In class
What a bind line looks like in the kernel log, and which job stays in userspace.
- The first kernel driver gets both lectures.
ECE 440 · Week 4 · In class
A bind line is the kernel log line that names your module and the device it attached to.
- The job that stays in userspace is the program that opens the device node after the module has bound.
- Write both names down before you load anything.
- Those two names are the homework.
- Unload and load once more on the second pass, and keep the second bind line in your notes.
ECE 440 · Week 4 · Lecture
How a driver meets its device
- The device tree describes a node: a
compatiblestring, registers, interrupts. - A platform driver lists the
compatiblestrings it handles. - When the two strings match, the kernel calls the driver's
probe()with that device. - No match, no probe, and no error either: silence is the first thing to debug.
ECE 440 · Week 4 · Lecture
The smallest platform driver
static const struct of_device_id mydev_ids[] = {
{ .compatible = "vendor,mydev" },
{ }
};
MODULE_DEVICE_TABLE(of, mydev_ids);
static struct platform_driver mydev_driver = {
.probe = mydev_probe,
.driver = {
.name = "mydev",
.of_match_table = mydev_ids,
},
};
module_platform_driver(mydev_driver);
ECE 440 · Week 4 · Lecture
probe(): map the registers, read one
static int mydev_probe(struct platform_device *pdev)
{
void __iomem *base;
u32 val;
base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base))
return PTR_ERR(base);
val = readl(base);
dev_info(&pdev->dev, "bound, reg0=0x%08x\n", val);
return 0;
}
ECE 440 · Week 4 · Lecture
Reading the bind line
dev_info()prefixes the driver name and the device name, so the line says who bound to what.dmesgshows it afterinsmod;rmmodtheninsmodagain shows a second one./sys/bus/platform/drivers/<name>/lists the devices a driver holds.- A negative return from
probe()leaves an error in the log and no device in that directory.
ECE 440 · Week 4 · Lecture
What stays in userspace
| Kernel driver | Userspace program |
|---|---|
| Maps registers, handles interrupts | Decides what to do with the data |
| Exposes a device node or a sysfs file | Opens that node and reads or writes it |
| A bug can take the whole board down | A bug ends one process |
Put in the kernel only what needs the hardware or its timing.
ECE 440 · Week 4 · Lab
Lab
- Write and load a kernel module that binds to the week-2 node and reads one register from the device.
- Name one job that stays in userspace. Second pass: unload the module and load it once more, and keep the second bind line in your notes.
- Assemble the lab hand-in: The kernel module source, the bind line from the kernel log, and one sentence naming a job that stays in userspace.
ECE 440 · Week 4 · Lab
Hand in
The kernel module source, the bind line from the kernel log, and one sentence naming a job that stays in userspace.
ECE 440 · Week 4 · Homework
Homework
- Write the module name you will pass to the loader, and the userspace program that will open the device node.
ECE 440 · Week 4 · Homework
Turn in
Those two names.
ECE 440 · Week 4 · Read
Read
On the lab site: Module 11, Drivers. This week grades your module, the bind line, and the userspace sentence.
ECE 440 · Week 4 · Next
Week 5
Boot time and input power are a pair.