I’ve been having a go at device driver programming on linux, and the obvious place to start was the well-known O’Reilly book on the subject. Unfortunately, it appears that the example code hasn’t been updated in a long time, and is incompatible with the current kernel in a lot of ways. Most of the problems are reasonably easy to figure out, and make a good exercise for the reader (I’m maintaining a git repo here), but one of the Kbuild problems was particularly frustrating.
When you attempt to build modules using the code provided, the build fails with:
make -C /lib/modules/188.8.131.52/build M=$PWD make: Entering directory `/home/timm/dev/linux-184.108.40.206' Building modules, stage 2. MODPOST 1 modules CC /home/timm/dev/device_drivers/scull/scull.mod.o /home/timm/dev/device_drivers/scull/scull.mod.c:9:2: error: implicit declaration of function âKBUILD_STRâ /home/timm/dev/device_drivers/scull/scull.mod.c:9:10: error: âscullâ undeclared here (not in a function) make: *** [/home/timm/dev/device_drivers/scull/scull.mod.o] Error 1 make: *** [modules] Error 2 make: Leaving directory `/home/timm/dev/linux-220.127.116.11' make: *** [default] Error 2
It turns out that the problem is down to the following line in the makefile:
EXTRA_CFLAGS += -I$(LDDINC)
I’m not entirely sure what this is supposed to do, and why it causes the failure. But for me, removing this line was enough to get the build working again.