insmod错误:插入"./hello.ko":-1无效的模块格式“ [英] insmod error: inserting './hello.ko': -1 Invalid module format"

查看:600
本文介绍了insmod错误:插入"./hello.ko":-1无效的模块格式“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚制作了我的第一个驱动程序模块,即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

然后我编译内核模块

$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 is -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

或者,您也可以使用以下制作文件

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆