2

I have some problems with compiling & building a simple gpio driver that I wrote( after THIS documentation). I have a Raspberry Pi Model B+ ( not sure if it's relevant to the question) with a fresh install of Raspbian and kernel 3.12.28+.

On Raspberry Pi, when I try to build the driver, I have the following error:

make[1]: *** /lib/modules/3.12.28+/build: No such file or directory.  Stop.

and the message is correct because the output of ls /lib/modules/3.12.28+ is:

kernel             modules.builtin      modules.dep.bin  modules.softdep
modules.alias      modules.builtin.bin  modules.devname  modules.symbols
modules.alias.bin  modules.dep          modules.order    modules.symbols.bin

So no build directory. I've tried some answer but none of them, after upgrading the kernel, didn't create a build directory.

Another thing that I've tried was to build the driver on my PC and after that to move it on Raspberry and install it. So I followed the documentation from Cross Compiling I built the kernel on my PC, and I changed the Makefile to execute this line:

make -C /home/arm_kernel/linux M=`pwd` modules

I executed the command make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all and the build finished successfully. But when I tried to install the driver on my Raspberry Pi after I run sudo insmod ./gpio_driver.ko I have the next error:

Error: could not insert module ./gpio_driver.ko: Invalid module format

The outup from dmesg is:

[ 1381.829484] gpio_driver: disagrees about version of symbol module_layout

What should I do to build a driver for Raspberry? I ran out of ideas...

2

no build directory

This is normally a link to the kernel source tree used to build the modules, so just ln -s /path/to/kernel/source /lib/modules/3.12.28+/build. That needs to be the actual, specific source version (3.12.28+) used in building the modules.

when I tried to install the driver on my Raspberry Pi ... I have the next error

You can't use modules from one kernel version with another. They have to match. If you actually built the kernel, then you'll need to install it, but don't bother unless you know it was configured correctly (and see also point #2 here for information about using /proc/config.gz for this).

Alternately, you could just use the same source as your current kernel (3.12.28+), which you have to get from the raspberry pi github source; unfortunately that's now at 3.12.35+, so you'd have to figure out how to roll back to there (it's not branched).

If you do install your own kernel, it goes into the first partition on the SD card (aka. the /boot directory, if the pi is running) and change the kernel= line in config.txt to point to it instead of the default kernel.img.

3

How I managed to build the driver:

  1. fresh install of Raspbian with the latest kernel, 3.12.35+
  2. I installed rpi-update and ran sudo rpi-update to get the latest firmware
  3. Installed rpi-source and run rpi-source from terminal. Instruction for rpi-update and rpi-source can be found HERE and HERE
1

Please try sudo apt-get install raspberrypi-kernel-headers

if you are working with raspbian

and check after installation if its working or not. It worked fine 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.