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!
.config
. Usemake bcm2709_defconfig
for the multi-core models. Note if you are not using a multicore model, you can't cross-compile using a distro toolchain. They're ARMv7. The single core models are ARMv6.