How the kernel module compiles when it bypasses the Insmod version check

Source: Internet
Author: User
Tags using git

1, Uboot: Each arm chip or Uboot chip has its own.

2, but their kernel version can be the same, mainly related to the compilation options of the respective kernel, 31 of the kernel version Riga version check option "Kernel type->symmetrical multi-processing", The kernel version of 21 does not have this option set.

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

In the development of kernel driver, always encounter annoying vermagic check, as long as the current kernel version of run with driver compile with kernel version inconsistent, there is no way to 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)

This greatly reduces the development speed, especially when you do not have the customer in the use of the kernel, but also to develop driver to him, really is very troublesome ...

Then how to use the disgusting way to bypass it???

First, turn off the moudle version check.

[Email protected] # Arch=arm make Menuconfig

---Enable loadable module support││

││[] Forced module loading││

││[*] Module unloading││

││[*] Forced module unloading││

││[] Module Versioning support││

││[] Source checksum for all modules

Second, the use of modinfo, you can see the current 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)

Third, modify the kernel vermagic, and then recompile driver

The first value of the Vermagic 2.6.28-noneed is defined by the uts_release in this include/linux/utsrelease.h.

#define Uts_release "2.6.28-271-GEC75A15"

And then by the macro in include/linux/vermagic.h.
To assemble the vermagic_string, which is the vermagic of kernel.

#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完成编译后, you're going to have to
#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

So, we just change the uts_release to our numbers, of course, if you are too lazy to try the combination of strings, you can also directly change the vermagic_string to the string you want

Suggested modified vermagic.h, after utsrelease.h, or kernel re-compiled kernel, more insurance.

The following is the result of the modified modinfo look

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)

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

Plus, if you're using Git for versioning, then Git's version number is on the kernel number.
So I'm going to turn him off.


General Setup--->
[] Automatically append version information to the version Strin

Explain
Config_localversion_auto:│
││
│this would try to automatically determine if the current tree is a│
│release tree by looking for git tags this belong to the current│
│top of the tree revision. │
││
│a string of the format-gxxxxxxxx is added to the localversion│
│if a git-based tree is found. The string generated by this would be│
│appended after a 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

How the kernel module compiles when it bypasses the Insmod version check

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.