当前位置:   article > 正文

内核模块编译时怎样绕过insmod时的版本检查_insmod ko取消版本校验

insmod ko取消版本校验

------------------------------------------------------------------------------------------添加---------------------------------------------------------------------------------------------------

1、Uboot:每个arm芯片或者海斯芯片都有各自的uboot。

2、但他们的内核版本可以是一样的,主要是跟各自内核的进行的编译选项有关, 31的内核版本里加了版本检查选项“Kernel type->Symmetrical Multi-Processing”,而21的内核版本没有设置该选项。

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

在开发kernel driver时,总是会遇到讨人厌的vermagic检查,只要目前在run的kernel版本跟driver编译时用的kernel版本不一致,就没办法insmod。

bash-3.2# insmod sdio.ko

sdio: version magic '2.6.28-271-gec75a15 preempt mod_unload modversions ARMv7 '

should be '2.6.28 preempt mod_unload ARMv7 '

insmod: init_module 'sdio.ko' failed (Exec format error)

这大大降低了开发速度,尤其是当你拿不到客户在用的kernel时,又要开发driver给他用,真的是很麻烦……

那麼要怎麼利用恶心的方式绕过去呢???

一、先把 Moudle version 检查关掉。

user@host # ARCH=arm make menuconfig

--- Enable loadable module support                                             │ │

│ │         [ ]   Forced module loading                                      │ │

│ │         [*]   Module unloading                                           │ │

│ │         [*]     Forced module unloading                                  │ │

│ │         [ ]   Module versioning support                                  │ │

│ │         [ ]   Source checksum for all modules

二、 使用modinfo时,可以看到目前这driver的vermagic

filename: external_drivers/omap3530/Linux/sdio/sdio.ko
author: Texas Instruments Inc
alias: TIWLAN_SDIO
license: GPL
description: TI WLAN SDIO driver
depends:
vermagic: 2.6.28-271-gec75a15 preempt mod_unload ARMv7
parm: g_sdio_debug_level:debug level (int)

三、 修改 kernel 的 vermagic,再重新编译driver

vermagic 的第一个值 2.6.28-noneed 是由这 include/linux/utsrelease.h里的 UTS_RELEASE 所定义。

#define UTS_RELEASE "2.6.28-271-gec75a15"

之后再由 include/linux/vermagic.h 里的 macro
去组合出 VERMAGIC_STRING , 也就是 kernel 的vermagic。

#include
#include


#ifdef CONFIG_SMP
#define MODULE_VERMAGIC_SMP "SMP "
#else
#define MODULE_VERMAGIC_SMP ""
#endif
#ifdef CONFIG_PREEMPT
#define MODULE_VERMAGIC_PREEMPT "preempt "
#else
#define MODULE_VERMAGIC_PREEMPT ""
#endif完成编译后,你就可以得
#ifdef CONFIG_MODULE_UNLOAD
#define MODULE_VERMAGIC_MODULE_UNLOAD "mod_unload "
#else
#define MODULE_VERMAGIC_MODULE_UNLOAD ""
#endif
#ifndef CONFIG_MODVERSIONS
#define MODULE_VERMAGIC_MODVERSIONS "modversions "
#else
#define MODULE_VERMAGIC_MODVERSIONS ""
#endif
#ifndef MODULE_ARCH_VERMAGIC
#define MODULE_ARCH_VERMAGIC ""
#endif

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

所以, 我们只要把 UTS_RELEASE 改成我们的数字即可,当然若是懒得去try组合后的字串,也可以直接将VERMAGIC_STRING改成你要的字串

建议修改完 vermagic.h, utsrelease.h后,还是把kernel重编完再编kernel,比较保险。

以下是修改后,用modinfo看的结果

filename: external_drivers/omap3530/Linux/sdio/sdio.ko
author: Texas Instruments Inc
alias: TIWLAN_SDIO
license: GPL
description: TI WLAN SDIO driver
depends:
vermagic: 2.6.28 preempt mod_unload ARMv7
parm: g_sdio_debug_level:debug level (int)

------------------------------------------------------------------------------------------

 另外若你是用git 做版本控制 , 那就会出现git的版本号在kernel 编号上
 所以要把他关掉
 
 
General setup  --->
 [ ] Automatically append version information to the version strin

解释;
CONFIG_LOCALVERSION_AUTO:                                                   │ 
  │                                                                         │ 
  │ This will try to automatically determine if the current tree is a       │ 
  │ release tree by looking for git tags that belong to the current         │ 
  │ top of tree revision.                                                   │ 
  │                                                                         │ 
  │ A string of the format -gxxxxxxxx will be added to the localversion     │ 
  │ if a git-based tree is found.  The string generated by this will be     │ 
  │ appended after any matching localversion* files, and after the value    │ 
  │ set in CONFIG_LOCALVERSION.                                             │ 
  │                                                                         │ 
  │ (The actual string used here is the first eight characters produced     │ 
  │ by running the command:                                                 │ 
  │                                                                 
  │ which is done within the script "scripts/setlocalversion".)             │ 
  │                                                                         │ 
  │ Symbol: LOCALVERSION_AUTO [=y]                                          │ 
  │ Prompt: Automatically append version information to the version string  │ 
  │   Defined at init/Kconfig:84                                            │ 
  │   Location:                                                             │ 
  │ ingT

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/308510
推荐阅读
相关标签
  

闽ICP备14008679号