Compiling kernel modules for Raspbian / Raspberry Pi

I needed to compile an out-of-tree (vendor supplied) driver for a USB device, to use it on my Raspberry Pi. Since the process was less than obvious, I’ll document it here. Maybe it will be of use to anyone else.

Normally, for compiling kernel modules, you need the kernel headers available. They have to match the version of the kernel you are targeting. In case of the Raspberry Pi running the 2012-07-15 image of Raspbian, that would be 3.1.9+. On plain Debian you would install a ‘linux-headers-x.y.z-flavour’ package, but that doesn’t seem to be available on Raspbian (at least not the right version), so we use the full kernel source from Github.

The main problem with that, is the absence of a file named Module.symvers, that contains the symbol versions of the running kernel and all of its modules. That file would normally come in the linux-headers package, that I mentioned above. To get that file, and be able to build ‘good’ modules for the kernel, you would need to build the entire kernel and all its modules yourself. At the end of the build, the file will be created. However, if you want to do that on the Pi itself, make sure you have plenty of time, because a complete kernel build will take quite a few hours.

To spare you the trouble, you can download it here: Module.symvers. Please note: this file is for the 3.1.9 kernel from Raspbian-2012-07-15, and it will not work for other kernel versions.

Assuming you have downloaded the file to your home directory, you can now download the Linux kernel source and prepare it for building out-of-tree modules like this: