我刚刚创建了我的第一个驱动程序模块,即LDD3之后的hello world模块。然而,不幸的是遇到了这个错误:
insmod: error inserting './hello.ko': -1 Invalid module format.我在Ubuntu 11.04上这样做,我的环境是:
$ uname -r
2.6.38-8-generic我得到的内核源代码如下:
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:
$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:
obj-m := hello.o最后,当我插入模块时:
$sudo insmod hello_world.ko
insmod: error inserting 'hello_world.ko': -1 Invalid module format我在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包。
状态更新:我发现文件/lib/moduels/$(name -r)/build/Makefile指示我正在运行的内核版本:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 38
EXTRAVERSION = .2所以我下载了linux-2.6.38.2并进行了编译,但仍然是同样的错误。
我还发现在/boot/config-$(未命名-r)中有一行:
CONFIG_VERSION_SIGNATURE="Ubuntu 2.6.38-8.42-generic 2.6.38.2"有人知道这是什么意思吗?我没有在我正在构建的内核的配置文件中看到它。
发布于 2015-12-21 11:42:25
用于构建内核模块和用于插入模块的内核应该具有相同的版本。如果你不想处理这件事,你可以使用下面的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现在您可以构建并尝试插入模块。
如果可能,我建议您在这行之前成为root
$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文件
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发布于 2017-10-23 22:11:13
尝试使用交叉编译。请看下面有关make文件的代码。注意缩进,否则可能会出现诸如 missing separator. Stop之类的错误
obj-m += hello_.o #此名称应为.c文件的名称。我只是使用hello作为例子。
我建议最好的方法是通过交叉编译。
创建一个变量来保存我的示例中linux内核目录所在的目录名,将值"PATH_TO_LINUX_KERNEL_DIRECTORY“更改为实际的路径值示例~/linux您确实需要这样做,以便make文件知道在哪里可以找到arm-linux-gnueabi-否则,您很可能会遇到问题arm-linux-gnueabi-
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发布于 2015-12-21 13:08:05
您做的一切都是正确的,但是没有用您编译的内核引导系统,所以第一步是应该用它引导。如果你使用的是Ubuntu,你可以在启动时按住shift键,然后你会看到一个编译过的内核列表,从那里选择linux-source-2.6.38,然后尝试构建你的模块并按照你的方式安装它,这样你就不会发现任何问题了。GoodLuck。
https://stackoverflow.com/questions/34379013
复制相似问题