4

My goal is it to cross-compile a kernel module for my raspberry pi. But I have some compatibility issues with my kernel sources on my pc and the version on my raspberry pi. My Pi uses this version:

root@Raspberry:~# uname -r
4.14.34-v7+

And if I compile the module on my host machine, I got it for this version:

name:           SimpleDriver
vermagic:       4.14.41-gadb282c SMP mod_unload ARMv7 p2v8

The problem is, that I can“t load this module, because of an invalid module format. How can I configure the kernel header on my host to match a specific version of my raspberry pi kernel?

Thanks!

Update:
I download the sources and follow your steps, but my cross-compiled module throws the error Invalid module format again. Everything seems ok if I check it with modinfo

Cross compiled:

filename:       /home/pi/Desktop/treiber/SimpleDriver.ko
description:    'Hello World' virtual device
license:        GPL
author:         Daniel Kampert
srcversion:     0CEACD8714A757B533779B7
depends:
name:           SimpleDriver
vermagic:       4.14.34-v7+ SMP mod_unload modversions ARMv7 p2v8

Makefile:

obj-m += SimpleDriver.o

# Current dir
PWD  := $(shell pwd)

# Kernel sources
KDIR := ${RASPBERRY_DIR}/Kernel/linux

all:
    make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KDIR) M=$(PWD) modules

clean:
    make -C $(KDIR) M=$(PWD) clean

root@Raspberry:/home/pi/Desktop/treiber# insmod SimpleDriver.ko
insmod: ERROR: could not insert module SimpleDriver.ko: Invalid module format

I use the arm-rpi-4.9.3-linux-gnueabihf cross compiler arm-linux-gnueabihf-gcc from https://github.com/raspberrypi/tools

Compiled on the Pi:

root@Raspberry:/home/pi/Desktop/treiber# modinfo SimpleDriver.ko
filename:       /home/pi/Desktop/treiber/SimpleDriver.ko
description:    'Hello World' virtual device
license:        GPL
author:         Daniel Kampert
srcversion:     0CEACD8714A757B533779B7
depends:
name:           SimpleDriver
vermagic:       4.14.34-v7+ SMP mod_unload modversions ARMv7 p2v8

Makefile:

obj-m+=SimpleDriver.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=${PWD} modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=${PWD} clean

What is wrong?

Thanks again!

Kampi
  • 197
  • 4
  • 11

1 Answers1

2

If you look at the Pi kernel source -- it is distinct from the mainline "vanilla" kernel -- on github, you can see by the top level Makefile the current stable is 4.14.41. The most frequent change in that Makefile is the version number, so if you look at its commit history you can find the first commit using 4.14.34. To find the latest release for that version, start with the next one (4.14.35), "Browse files", and click through "releases" at the top. The latest one will actually be for 4.14.34 (since this is the first commit for 4.14.35, which at that point has no release version -- note not all versions have releases either), and if you follow the commit index (a six digit hex value next to the .zip and .tar.gz options), you can "Browse files" again to get to the top of the tree, from April 16th, and double check the Makefile (it is 4.14.34).

https://github.com/raspberrypi/linux/tree/f70eae405b5d75f7c41ea300b9f790656f99a203

That's the source you want to use. You should then run make bcm2709_defconfig to get the v7+ configuration.

goldilocks
  • 60,325
  • 17
  • 117
  • 234