Kernel Module Build Workflow¶
This page summarizes the common out-of-tree kernel module build workflow used throughout the labs.
Build Model¶
Most labs use the standard kernel build system from outside the kernel source tree:
Minimal Makefile Pattern¶
obj-m += mydriver.o
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
Important Files¶
| File | Purpose |
|---|---|
*.ko |
Loadable kernel module |
*.mod.c |
Generated module metadata source |
Module.symvers |
Symbol version information |
modules.order |
Module build order |
Native Build on Raspberry Pi¶
Cross Build from WSL¶
Useful Inspection Commands¶
Common Pitfalls¶
KDIRpoints to the wrong kernel headersuname -ris evaluated on the host instead of the target- generated module has a different
vermagicfrom the target kernel - copied headers are incomplete
CONFIG_LOCALVERSIONor Raspberry Pi kernel suffix does not match