本帖最后由 alex0 于 2012-08-07 15:21:24 编辑
插入模块无法成功,查了很久帖子,找不到解决方法。
insmod: error inserting './hello.ko': -1 Invalid module format
错误信息如下:
80:/w/hello # dmesg | tail
[856096.526863] hello: disagrees about version of symbol module_layout
版本:
80:/usr/src # uname -r
3.0.13-0.27-default
80:/w/hello # uname -a
Linux 80 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux
80:/w/hello # modinfo hello.ko
filename: hello.ko
license: Dual BSD/GPL
srcversion: 31FE72DA6A560C890FF9B3F
depends:
vermagic: 3.0.13-0.27-default SMP mod_unload modversions
80:/w/hello # modinfo /lib/modules/3.0.13-0.27-default/build/sound/soundcore.ko
filename: /lib/modules/3.0.13-0.27-default/build/sound/soundcore.ko
alias: char-major-14-*
license: GPL
author: Alan Cox
description: Core sound module
srcversion: 8C2CC496EFFF806BFEE1D0C
depends:
vermagic: 3.0.13-0.27-default SMP mod_unload modversions
parm: preclaim_oss:int
[/code]
1 #include<linux/init.h>
2 #include<linux/module.h>
3 MODULE_LICENSE("Dual BSD/GPL");
4 static int hello_init(void)
5 {
6 printk(KERN_ALERT "Hello, world\n");
7 return 0;
8 }
9 static void hello_exit(void)
10 {
11 printk(KERN_ALERT "Goodbye, cruel world\n");
12 }
13 module_init(hello_init);
14 module_exit(hello_exit);
Makefile文件
1 ifneq ($(KERNELRELEASE),)
2 obj-m :=hello.o
3 else
4 PWD := $(shell pwd)
5 KVER ?= $(shell uname -r)
6 KDIR := /lib/modules/$(KVER)/build
7 default:
8 $(MAKE) -C $(KDIR) M=$(PWD) modules
9 clean:
10 rm -rf .*.cmd *.mod.c *.ko .tmpversions
11 endif
------最佳解决方案--------------------
模块的版本是否和正运行的kernel的版本信息一致
------其他解决方案--------------------
貌似不是这个问题