insmod 错误:插入“./hello.ko":-1 无效的模块格式" [英] insmod error: inserting './hello.ko': -1 Invalid module format"
问题描述
我刚刚制作了我的第一个驱动程序模块,即 LDD3 之后的 hello world 模块.不过很不幸遇到了这个错误:
I have just made my first driver module, the hello world module following LDD3. However unfortunately encountered this error:
insmod: error inserting './hello.ko': -1 Invalid module format.
我在 Ubuntu 11.04 和我的环境上执行此操作:
I am doing this on Ubuntu 11.04, and my environment:
$ uname -r
2.6.38-8-generic
我像这样得到内核源代码:
I get the kernel source like this:
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
我的/usr/src:
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
然后我编译内核
$sudo cp /boot/config-2.6.38-8-generic ./.config
$sudo make menuconfig -- load the .config file
$make
$make modules
然后我编译我的内核模块
and then I compile my kernel module
$make -C /usr/src/linux-source-2.6.38/linux-source-2.6.38 M=`pwd` modules
使用 Makefile:
with Makefile:
obj-m := hello.o
最后当我插入模块时:
$sudo insmod hello_world.ko
insmod: error inserting 'hello_world.ko': -1 Invalid module format
我在 dmesg 中发现的:
what I found in dmesg:
hello: disagrees about version of symbol module_layout
有什么问题吗?
我也注意到 linux-header 是 -2.26.38-generic
而源代码版本是 -2.26.38,这是问题吗?但我真的没有在网上找到 linux-source-2.26.38-generic
包.
I have also noticed that the linux-header is -2.26.38-generic
and source code version is -2.26.38, is this the problem? but I have really not found a linux-source-2.26.38-generic
package on web.
状态更新:我发现文件/lib/moduels/$(name -r)/build/Makefile 表示我正在运行的内核版本:
status update: I have found that the file /lib/moduels/$(name -r)/build/Makefile indicate my running kernel version:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 38
EXTRAVERSION = .2
于是我下载了linux-2.6.38.2并编译,还是一样的错误.
So I download the linux-2.6.38.2 and compile, but still the same error.
我还发现/boot/config-$(uname -r) 中有一行:
I have 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 any one know what is this mean? I don't see it in the config file of the kernel i am building.
推荐答案
构建内核模块的内核和插入模块的内核应该是相同的版本.如果你不想处理这个事情,你可以使用下面的 Makefile.
Kernel from which you build your kernel module and to which you are inserting module should be of same version. If you do not want to take care of this thing you can use 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 build and try to insert module.
如果可能的话,我建议你在这行之前成为root
I suggest you to become root if possible before this line
$sudo cp/boot/config-2.6.38-8-generic ./.config
$sudo cp /boot/config-2.6.38-8-generic ./.config
$su
#cp /boot/config-2.6.38-8-generic ./.config
#insmod hello_world.ko
或者,您也可以使用以下 make 文件
Alternatively you can also use 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
这篇关于insmod 错误:插入“./hello.ko":-1 无效的模块格式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!