模块不能插入的问题解决 disagrees about version of symbol struct_module

本篇文章主要介绍了"模块不能插入的问题解决 disagrees about version of symbol struct_module",主要涉及到模块不能插入的问题解决 disagrees about version of symbol struct_module方面的内容,对于模块不能插入的问题解决 disagrees about version of symbol struct_module感兴趣的同学可以参考一下。

最近开发产品的时候发现个问题,以前没出现过,现在记录下来,算个积累吧。

编译了一个新的模块,在进行加载的时候出现了如下问题:

/opt/autorun # insmod board_config.ko 
board_config: disagrees about version of symbol __class_create
board_config: Unknown symbol __class_create (err -22)
board_config: disagrees about version of symbol class_destroy
board_config: Unknown symbol class_destroy (err -22)
board_config: disagrees about version of symbol device_create
board_config: Unknown symbol device_create (err -22)
board_config: disagrees about version of symbol device_destroy
board_config: Unknown symbol device_destroy (err -22)
insmod: can't insert 'board_config.ko': invalid parameter

用modinfo命令查看:modinfo board_config.ko后如下所示:

filename:       board_config.ko
license:        GPL
depends:        
vermagic:       2.6.37 mod_unload modversions ARMv7 p2v8

wdove很好的解释了这个问题,在此感谢!原文http://blog.csdn.net/wdove/article/details/5329783 

下面转载其解释:

最开始下载的内核源码和机子的kernel不匹配,参照http://blog.csdn.net/hecant/archive/2007/10/31/1859606.aspx:

检查/usr/src/linux/Makefile,确保下面这些特定的版本信息同你使用的内核完全一致:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 5
EXTRAVERSION = -1.358custom
...
不必完全编译一遍内核,只得到需要的文件即可:
root@pcsenonsrv linux-2.6.x]# make
CHK     include/linux/version.h
UPD     include/linux/version.h
SYMLINK include/asm -> include/asm-i386
SPLIT   include/linux/autoconf.h -> include/config/*
HOSTCC  scrīpts/basic/fixdep
HOSTCC  scrīpts/basic/split-include
HOSTCC  scrīpts/basic/docproc
HOSTCC  scrīpts/conmakehash
HOSTCC  scrīpts/kallsyms
CC      scrīpts/empty.o
...
      
如果你不是确实想编译一个内核,你可以在SPLIT后通过按下CTRL-C中止编译过程。因为此时你需要的文件 已经就绪了。现在你可以返回你的模块目录然后编译加载它:此时模块将完全针对你的当前内核编译,加载时也不会由任何错误提示。

 

其中还提到:

我们可以借助选项--force-vermagic解决该问题,但这种方法有潜在的危险,所以在成熟的模块中也是不可接受的。

首 先,准备同你目前的内核版本完全一致的内核代码树。然后,找到你的当前内核的编译配置文件。通常它可以在路径 /boot下找到,使用像config-2.6.x的文件名。你可以直接将它拷贝到内核代码树的路径下: cp /boot/config-`uname -r` /usr/src/linux-`uname -r`/.config。


不过用过了,不起作用。

 

最后:

自编module

$ modinfo memory.ko
filename:       memory.ko
license:        Dual BSD/GPL
srcversion:     BC5712DD3ED953ACB98BF49
depends:
vermagic:       2.6.24-19-386 mod_unload modversions 486

 

内核

$ uname -a
Linux shlx12 2.6.24-19-386 #1 Wed Jun 18 14:09:56 UTC 2008 i686 GNU/Linux

 

系统module

$ modinfo /lib/modules/2.6.24-19-386/kernel/sound/soundcore.ko
filename:       /lib/modules/2.6.24-19-386/kernel/sound/soundcore.ko
alias:          char-major-14-*
license:        GPL
author:         Alan Cox
description:    Core sound module
srcversion:     548AA54AF08207316C104F8
depends:
vermagic:       2.6.24-19-386 mod_unload 486

 

因为kernel source是一个ubuntu修改版的内核,所有有 modversions的记号,不知道去哪里除掉。最后查Makefile, .config发现了

  x Symbol: MODVERSIONS [=n]                                                                   x
  x Prompt: Module versioning support                                                          x
  x   Defined at init/Kconfig:874                                                              x
  x   Depends on: MODULES                                                                      x
  x   Location:                                                                                x
  x     -> Enable loadable module support (MODULES [=y])

 

去掉该选项后,再用上面的步骤,可以编过module。

 

Rusty Russell提到modversions是为了不使一个没有版本的module插入一个修改版的内核


Don't allow a module built without versions altogether to be inserted into a kernel which expects modversions.

modprobe --force will strip vermagic as well as modversions, so it won't be effected, but this will make sure that a non-CONFIG_MODVERSIONS module won't be accidentally inserted into a CONFIG_MODVERSIONS kernel.

 

http://lkml.indiana.edu/hypermail/linux/kernel/0805.1/0588.html

 

还有一个密切相关的地方是include/linux/vermagic.h,里面定义了所有magic的生成:

#define VERMAGIC_STRING                         /
    UTS_RELEASE " "                         /
    MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT             /
    MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS   /
    MODULE_ARCH_VERMAGIC

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值