I installed Raspbian using NOOBS_lite_v1_4.zip on a new microSD. After the initial install I ran

sudo apt-get update
sudo apt-get upgrade

Running "uname -r" tells me I am running Linux version 3.18.11-v7+. I have no cross compiler and run all the development and compiling on the Pi. I want to write an installable driver and saw on various help sites that I needed at least the kernel headers and configuration to do this. Following the example of the second answer in Compile linux module on Raspbian error I did the following:

git clone https://github.com/raspberrypi/linux.git  

I then ran:

git checkout rpi-3.18.y  

to get the closest to 3.18.11. I then ran

git log Makefile  

to get the commit hashtag for 3.18.11 which is f154a14e3....
I then got that version by:

git checkout f154a14e3  

which extracted 3.18.11.

When I try to compile a test driver using this tree I get errors that the Kernel configuration is invalid and that Module.symvers is missing. How do I get the configuration and Module.symvers for my kernel?

  • Could you expand your question to make it crystal clear what you want to do? – joan Oct 2 '15 at 17:14
  • What module? What OS did you install with noobs? are you planning to compile on the Pi or another computer? What have you tried? please edit your question and add these details then either vote to reopen or notify me in a comment with an @ comment – Steve Robillard Oct 2 '15 at 23:46

This is a multi step proces:

Step 1: Get the git_hash from the firmware

First you need the commit id of the firmware (firmware-commit-id) from the raspberrypi-bootloader package:
zgrep '* firmware as of' /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | head -1

With the firmware-commit-id in mind, you go to https://github.com/raspberrypi/firmware/commits/master and look up that commit id and click on the link with the title Browse the repository at this point in the history and then you go into the extra directory. When you're there, you should see a file named git_hash. Open that file and write down the git commit id (kernel-commit-id) you see there. From that directory also download Module7.symvers file for the Pi2 (Module.symvers for the Pi1)

Step 2: Prepare the kernel for module compilation

Get the kernel sources and put them into the rpf-linux-kernel folder:
git clone https://github.com/raspberrypi/linux rpf-linux-kernel
This will download more then 1GB of data and then process it, which will take a while.

Downloading the kernel source alone is not sufficient to compile a kernel module. There are a couple of things we need to do to get the kernel source at the time of the kernel compilation and do some other preparations before we can compile a kernel module.

cd rpf-linux-kernel git checkout -b rpi-bootloader-3.18.11 <kernel-commit-id> This will change into the directory with the raspberrypi kernel code and then checkout the code at the earlier retrieved kernel-commit-id into a new branch. I always do things in a separate branch so I can mess up all I want in that branch and start over cleanly by going back and checking out in a new branch. It is not required though.

Now that we have the exact code at the right commit id, it's time to make some preparations: make mrproper make bcm2709_defconfig make modules_prepare This cleans everything up and then loads the default configuration for the Pi2. For the Pi1 you should use make bcmrpi_defconfig instead. It then makes things ready to compile kernel modules.

cp ../Module7.symvers Module.symvers
This copies the previously saved Module7.symvers into the current directory. It must be named Module.symvers when placed in the rpf-linux-kernel directory! When compiling for the Pi1, you should just copy the previously saved Module.symvers into the rpf-linux-kernel directory. I assumed here that those *.symvers files were saved in the parent directory of rpf-linux-kernel.

Step 3: Set up your system for kernel module compilation

When you're compiling a kernel module, the build system looks in the /lib/modules/<kernel-version>/build directory for the kernel headers/sources.

For the following example we assume that the user is 'pi' and that the previous git clone command was performed in it's home directory and that we want to compile a module for the current kernel.
The link we need to set up is between the kernel source and the /lib/modules/<current-kernel-version>/build directory. The <current-kernel-version> can be obtained by the uname -r command and so the command to set up the link becomes:
sudo ln -s /home/pi/rpf-linux-kernel/ /lib/modules/$(uname -r)/build

Step 4: Compile your kernel module or test driver

Now that all the preparations are done, you can compile your kernel module or test driver by cd-ing into that directory and then do make ARCH=arm or whatever is the right way to compile your module/driver.


I wanted to compile a kernel module/driver for the RPI2. I followed the instructions from this page to build the kernel and the corresponding "Module.symvers".


Finally, I used this command to make my module:

export ARCH=arm
export CROSS_COMPILE=/home/dev/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-
make KERNELDIR=/home/dev/linux

The makefile of the module was:

obj-m := xr_usb_serial_common.o

#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
KERNELDIR ?= /home/dev/linux
PWD       := $(shell pwd)


    $(MAKE) -C $(KERNELDIR) M=$(PWD)

    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions vtty

It worked for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.