Insmod error: insert './hello.ko': -1 Invalid module format "

I just made my first driver module, hello world module after LDD3. However, unfortunately, this error occurred:

insmod: error inserting './hello.ko': -1 Invalid module format. 

I do this on Ubuntu 11.04 and in my environment:

 $ uname -r 2.6.38-8-generic 

I get the kernel source as follows:

 sudo apt-cache search linux-source linux-source - Linux kernel source with Ubuntu patches linux-source-2.6.38 - Linux kernel source for version 2.6.38 with Ubuntu patches $sudo apt-get install linux-source-2.6.38 

my / usr / src:

 $ls /usr/src/ linux-headers-2.6.38-8 linux-source-2.6.38 vboxguest-5.0.10 linux-headers-2.6.38-8-generic linux-source-2.6.38.tar.bz2 

and then I compile the kernel

 $sudo cp /boot/config-2.6.38-8-generic ./.config $sudo make menuconfig -- load the .config file $make $make modules 

and then I compile the kernel module

 $make -C /usr/src/linux-source-2.6.38/linux-source-2.6.38 M=`pwd` modules 

with makefile:

 obj-m := hello.o 

and then finally when I insert the module:

 $sudo insmod hello_world.ko insmod: error inserting 'hello_world.ko': -1 Invalid module format 

what i found in dmesg:

 hello: disagrees about version of symbol module_layout 

So what's the problem?

I also noticed that linux-header is -2.26.38-generic and source version is -2.26.38, is this a problem? but I really did not find the linux-source-2.26.38-generic package on the Internet.

update status: I found that the file / lib / moduels / $ (name -r) / build / Makefile indicates my current kernel version:

 VERSION = 2 PATCHLEVEL = 6 SUBLEVEL = 38 EXTRAVERSION = .2 

So, I download linux-2.6.38.2 and compile, but still the same error.

I also found that there is a line in / boot / config - $ (uname -r):

 CONFIG_VERSION_SIGNATURE="Ubuntu 2.6.38-8.42-generic 2.6.38.2" 

Does anyone know what that means? I do not see it in the kernel configuration file that I create.

+5
source share
3 answers

The kernel from which you create your kernel module and to which you insert the module must be of the same version. If you do not want to take care of this, you can use the following Makefile.

 obj−m += hello−world.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 

Now you can create and try to insert a module.

I suggest you become root, if possible, before this line

$ sudo cp / boot / config-2.6.38-8-generic. /. config

 $su #cp /boot/config-2.6.38-8-generic ./.config #insmod hello_world.ko 

Alternatively, you can also use the following make file

 TARGET := hello-world WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes INCLUDE := -isystem /lib/modules/`uname -r`/build/include CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE} CC := gcc-3.0 ${TARGET}.o: ${TARGET}.c .PHONY: clean clean: rm -rf ${TARGET}.o 
+1
source

Try using cross compilation. Take a look at the code below for the make file. Remember to backtrack, otherwise you may be mistaken, for example, a missing delimiter. Stop

obj-m += hello_.o # this name should be the name of your .c file. I just use hi for example

I suggest the best approach through cross-compilation

Create a variable to store the name of the directory where the linux kernel directory is located. In my example, change the value "PATH_TO_LINUX_KERNEL_DIRECTORY" to the real path value Example ~ / linux You really need to do this so that the make file knows where to find arm-linux-gnueabi-. Without this, you are likely to run into arm-linux-gnueabi problems -

 KDIR := PATH_TO_LINUX_KERNEL_DIRECTORY all: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -C $(KDIR) M=$(shell pwd) modules clean: make -C $(KDIR) M=$(shell pwd) clean 
0
source

You did everything right, but did not boot your system with the kernel that you compiled, so the first step is to download it. If you are using Ubuntu, you can hold down the shift button at boot time and you will be presented with a list of compiled cells on your system, select linux-source-2.6.38 , and then try to create your module and install it in your own way, which you won’t find no problem. GoodLuck.

-2
source

Source: https://habr.com/ru/post/1238748/


All Articles