0

Headline: I've cross-compiled a kernel module for the Raspberry Pi, but on attempting to load it, I get the following error:

insmod: ERROR: could not insert module testmod.ko: Invalid module format

Detail:

I've got the kernel source for the kernel I'm running in the following way:

$ zcat /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | grep '* firmware as of' | head -1
  * firmware as of 951799bbcd795ddf27769d14acf4813fdcbe53dc

This gives the firmware git hash. I then get the corresponding kernel hash:

$ wget https://raw.github.com/raspberrypi/firmware/951799bbcd795ddf27769d14acf4813fdcbe53dc/extra/git_hash -O - 2>/dev/null
20fe468af4bb40fec0f81753da4b20a8bfc259c9

On my Ubuntu (18.04) host, I then: $ git clone https://github.com/raspberrypi/linux $ git fetch rpi-4.1.y $ git checkout 20fe468af4bb40fec0f81753da4b20a8bfc259c9 $ scp pi@raspberrypi.lan:/proc/config.gz . $ zcat config.gz > linux/.config $ cd linux $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- oldconfig scripts/kconfig/conf --oldconfig Kconfig # # configuration written to .config #

Then in my module source dir:

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -C ../linux M=$(pwd) modules
make: Entering directory '/home/tkcook/RasPi/linux'
  CC [M]  /home/tkcook/RasPi/testmod/testmod.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/tkcook/RasPi/testmod/testmod.mod.o
  LD [M]  /home/tkcook/RasPi/testmod/testmod.ko
make: Leaving directory '/home/tkcook/RasPi/linux'

I can't see what I've done wrong here. Am I possibly using the wrong version of GCC?

  • If it is the GCC version, I'm out of luck - the raspberry pi 4.1.19 kernel was built with GCC 4.9.3 and Ubuntu only supplies the ARM cross-compiler in version 5 and up. – Tom Aug 15 '18 at 15:03
  • Any particular reason you're using that old kernel? Current RPF kernel is 4.14.x. You can find RPF toolchain at github.com/raspberrypi/tools/tree/master/arm-bcm2708. Also see raspberrypi.org/documentation/linux/kernel/building.md about cross-compiling kernel – Dirk Aug 15 '18 at 16:00
  • The work I was doing happened to be on an older embedded device that used a 4.1 kernel in a jessie distribution. There was no particular reason for that though, it was what I happened to have to hand. I've confirmed that using the GCC 4.9.3 from the RaspberryPi tools github and upgrading to stretch and 4.14 fixes this. – Tom Aug 16 '18 at 10:48

Your Answer

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

Browse other questions tagged or ask your own question.