mesutparis
Posts: 2
Joined: Sun Apr 24, 2016 12:39 pm

insmod: ERROR: could not insert module modul.ko: Invalid mod

Sun Apr 24, 2016 12:52 pm

hello all:
I am developping some hello world modules for my Raspberry PI 3.
i have this kernel on my Rpi : Linux raspberrypi 4.1.19+ #858 Tue Mar 15 15:52:03 GMT 2016 armv6l GNU/Linux

and i cross compile on my computer:
i use the kernel : linux-rpi-4.1.y and a hello world program:

/ -------------------------------------------------------------------------------------------- /
#include <linux/module.h> // Needed by all modules

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Salah ABBAS, 2016");
MODULE_DESCRIPTION("Demo module for cross compiling");

int init_module(void)
{
// Print a message in the kernel log
printk("Hello world\n");

// A non 0 return means init_module failed; module can't be loaded.
return 0;
}


void cleanup_module(void)
{
// Print a message in the kernel log
printk("Goodbye world\n");
}

/ -------------------------------------------------------------------------------------------- /

i use a makefile:
/ -------------------------------------------------------------------------------------------- /
# My Module Makefile
#
obj-m := test1.o
KDIR := /home/salah/Projects/Test/Kernel/linux-rpi-4.1.y/
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean

/ -------------------------------------------------------------------------------------------- /

and my cross compilation finishes well, and i get the : test1.ko file whose properties are:
//////// $ modinfo test1.ko
filename: /home/pi/test1.ko
description: Demo module for cross compiling
author: xxxx YYYYY, 2016
license: GPL
srcversion: 6EFACA1B07E7CCC55078D48
depends:
vermagic: 4.1.21 mod_unload modversions ARMv7 p2v8

/ -------------------------------------------------------------------------------------------- /
and when i run : sudo insmod test1.ko
i get the following error:

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

/ -------------------------------------------------------------------------------------------- /

do you have any idea where this is coming from ?

Thank you in advance.

Dutch_Master
Posts: 362
Joined: Sat Jul 27, 2013 11:36 am

Re: insmod: ERROR: could not insert module modul.ko: Invalid

Sun Apr 24, 2016 1:25 pm

Kernel mismatch between the RPi and your work machine? Test bulding the program on the RPi itself, this way you can deduct if the error is related to the cross-compiling. It narrows down your search by 50%! :idea:

mesutparis
Posts: 2
Joined: Sun Apr 24, 2016 12:39 pm

Re: insmod: ERROR: could not insert module modul.ko: Invalid

Tue Apr 26, 2016 7:44 pm

Hello, and thank you for tour advices.
i compiled the kernel + my module on my Raspberry, and the insmod gives the same error message !
I cross compiled, on my computer, a simple .c file just printing "hello world", and cross compilation went well, and i executed it on my Raspberry successfully !

so, my conclusion is that: my cross compilation chain works well.
There is a problem when i try to insert a compiled "module + kernel" into my Raspberry.

Do you have any ideas to try ?

Thank you so much.

Return to “Advanced users”