内核模块编译时怎样绕过insmod时的版本检查
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修改 /arch/arm/include/asm/module.h
/* Add __virt_to_phys patching state as well */
/*#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
#define MODULE_ARCH_VERMAGIC_P2V "p2v16 "
#else
#define MODULE_ARCH_VERMAGIC_P2V "p2v8 "
#endif
#else*/
#define MODULE_ARCH_VERMAGIC_P2V ""
//#endif
内核模块编译时怎样绕过insmod时的版本检查的更多相关文章
- [转]maven编译时出现读取XXX时出错invalid LOC header (bad signature)
maven编译时出现读取XXX时出错invalid LOC header (bad signature) 一.发现问题右击pom.xml,run as —> maven install,会看到c ...
- Stack overflow 编译能通过,运行时出现Stack overflow
Stack overflow 编译能通过,运行时出现Stack overflow 大家都知道,Windows程序的内存机制大概是这样的,全局变量(局部的静态变量本质也属于此范围)存储于堆内存,该段内存 ...
- swig编译GDAL的C#库时遇到的代码安全问题及解决方法
之前一直用的是别人编译好的gdal库开发,今天自己编译了gdal的2.0.0版本,踩了不少坑,但总算解决了. 编译方法主要参考http://blog.csdn.net/liminlu0314/arti ...
- linux内核模块编译makefile
linux内核可加载模块的makefile 在开发linux内核驱动时,免不了要接触到makefile的编写和修改,尽管网上的makefile模板一大堆,做一些简单的修改就能用到自己的项目上,但是,对 ...
- VC C运行时库(CRTL)的几个版本及选用
分类: Windows 2008-12-23 10:01 987人阅读 评论(0) 收藏 举报ciostreammfclibrary多线程import最近做项目碰到了一个关于在动态库中使用MFC以及在 ...
- linux/module.h: No such file or directory 内核模块编译过程
1.缺少Linux kernel头文件 To install just the headers in Ubuntu: sudo apt-get install linux-headers-$(unam ...
- 购买阿里云的云服务器时选择镜像centos时应该选择哪个版本
购买阿里云的云服务器时选择镜像centos时应该选择哪个版本 方法/步骤首先,我们要清楚的便是每个系统之间的差别,以及在阿里云上的差别:1. Windows1.1) 系统内含正版激活.1.2) 适合于 ...
- 更新新网卡驱动,修复win7雷凌网卡Ralink RT3290在电脑睡眠时和启动网卡时出现蓝屏netr28x.sys驱动文件错误
更新新网卡驱动,修复win7雷凌网卡Ralink RT3290在电脑睡眠时和启动网卡时出现蓝屏netr28x.sys驱动文件错误 我的本本是win7,雷凌网卡Ralink RT3290 802.1 ...
- cocos项目导入其它源文件时加入依赖库时,头文件提示找不到文件夹中的文件
cocos项目导入其它源文件时加入依赖库时,头文件提示找不到文件夹中的文件解决方法: 选择项目属性->c/c++->常规,在附加包括项目中加上对应的文件夹 cocos test项目的库(所 ...
随机推荐
- php 循环简写
<?php class a{ public function news($news){ $articles = array(); foreach ($news as $key => $va ...
- windows下mysql区分大小写敏感问题
默认情况下,表别名在Unix上区分大小写,但在Windows或macOS上不是这样.以下语句在Unix上不起作用,因为它引用别名as a和as A: mysql> SELECT col_name ...
- 回顾下WinMain
我们在学习标准C++的时候,都知道每个应用程序运行时都会先进入入口点函数main,而当从main函数跳出时程序就结束了.在Windows编程里面,也是一样的,只是我们的入口点函数不叫main,叫Win ...
- Python中的图像处理
第 1 章 基本的图像操作和处理 本章讲解操作和处理图像的基础知识,将通过大量示例介绍处理图像所需的 Python 工具包,并介绍用于读取图像.图像转换和缩放.计算导数.画图和保存结果等的基本工具.这 ...
- POJ 1861 & ZOJ 1542 Network(最小生成树之Krusal)
题目链接: PKU:http://poj.org/problem?id=1861 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- T-SQL Table-valued Function使用分隔符将字符串转换为表
)=' ') RETURNS @Strings TABLE ( ITEM_VALUE VARCHAR(MAX) ) AS BEGIN DECLARE @index INT ) BEGIN SET @i ...
- Strange Optimization(扩展欧几里得)
Strange Optimization Accepted : 67 Submit : 289 Time Limit : 1000 MS Memory Limit : 65536 KB Str ...
- isnull在order by中的使用——让我长见识了
select * from VisitLogorder by ISNULL(NextVisitDate,'2299-01-01') 此sql的作用是查找表中的数据,并按照NextVisitDate字段 ...
- Sublime Text 3如何快速生成HTML5的头部信息和常用的快捷键
一.快速生成HTML5的头部信息的步骤: 1.Ctrl + N,新建一个文档: 2.Ctrl + Shift + P,打开命令模式,再输入 sshtml 进行模糊匹配,将语法切换到html模式: 3. ...
- 批量索引以提高索引速度 -d --data-binary
index create update 第1.2行分别为:信息行.数据行,在索引中增加或更换文档delete 移除文档,只包含信息行 Bulk API | Elasticsearch Referenc ...