Power & Source of Big Ideas

Invalid module format

Moderators: chensy, FATechsupport

insmod test.c

insmod: ERROR: could not insert module test.c: Invalid module format


uname -a
-----------------------------------
Linux NanoPi-M4 4.4.179 #1 SMP Tue Dec 17 18:03:10 CST 2019 aarch64 aarch64 aarch64 GNU/Linux

modinfo test.ko
------------------------------------
filename: /opt/demo/test.ko
license: GPL
depends:
vermagic: 4.4.179 SMP preempt mod_unload modversions aarch64
I got the exact same errors when I tried to compile v4l2loopback kernel module for 4.4.179
modprobe: ERROR: could not insert module test.c: Invalid module format
uname -r reported: 4.4.179
modinfo 4.4.179

It took me two days to get it fixed:

As I understand it you will need not only the matching kernel header files. You need a complete kernel source tree with
a bunch of files that are created on compiling the kernel. So what I did is the following:

Setup Development Environment:
In order to compile an Linux kernel I suggest you do it on a 64 bit Ubuntu 16.04 system (VirtualBox) and install the following packages:
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
sudo apt-get install flex curl libncurses5-dev libssl-dev gawk minicom
sudo apt-get install openjdk-8-jdk
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool

Install Cross Compiler:
git clone https://github.com/friendlyarm/prebuilts.git -b master --depth 1
cd prebuilts/gcc-x64
cat toolchain-6.4-aarch64.tar.gz* | sudo tar xz -C /

export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
export GCC_COLORS=auto

Compile FriendlyCore/FriendlyDesktop/Lubuntu/EFlasher Kernel Source Code:
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip
cd kernel-rockchip
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
make ARCH=arm64 nanopi4_linux_defconfig
make ARCH=arm64 nanopi4-images

Because my Ubuntu 16.04 system runs kernel 4.15.0-88-generic I then edited the makefile of v4l2loopback so it uses the kernel source tree that I worked on. I got a working v4l2loopback.ko that I could successfully load on the 4.4.179 kernel that comes with the FriendlyDesktop bistro from Friendlyarm for NanoPi M4V2

Who is online

In total there are 37 users online :: 0 registered, 0 hidden and 37 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 37 guests