Compiling the example code from O’Reilly “Linux Device Drivers” book

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/2.6.39.3/build M=$PWD
make[1]: Entering directory `/home/timm/dev/linux-2.6.39.3'
  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[2]: *** [/home/timm/dev/device_drivers/scull/scull.mod.o] Error 1
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/home/timm/dev/linux-2.6.39.3'
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.

Leave a Reply

Your email address will not be published. Required fields are marked *