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

来源:互联网 发布:mac os x lion 最新版 编辑:程序博客网 时间:2024/04/29 04:31

最开始下载的内核源码和机子的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的生成