1. 程式人生 > >Trick on the Version Magic Number of Linux Kernel

Trick on the Version Magic Number of Linux Kernel

Trick on the Verson Magic Number of Linux Kernel

MAR 15TH, 2013 |
COMMENTS

Recently, I was working on building a modified wireless driver for Nexus
7 to support monitor mode. There are quite a few things that are very
subtle and easy to get confused. I’ll just write down the steps in case
that I forgot and might need them again.

This
is actually a very good guide for building customized kernel module
except the issue I will talk about below.

Kernel vermagic

The version magic number of the kernel that being used to build the
externel module has to be exactly the same as the kernel running on the
device. It won’t be a problem if you build the module and kernel, then
load both of them to the device. However, in this case, I would like to
avoid to build and replace the whole kernel. The wireless driver is the
only kernel module that I want to build. Therefore, the kernel version
magic has to be modified. The vermagic for the device is
“3.1.10-g05b777c SMP preempt mod_unload ARMv7”, while my source code
gives “3.1.10-g22b4fcd-dirty SMP preempt mod_unload ARMv7”. So “3.1.10”
is the kernel version, it should match with the version of the kernel
source. It consists of the following four parts which can be found at
the beginning of Makefile:

這裡寫圖片描述

The guide
indicates that modifying the Makefile as shown below, simply use the VC
number as EXTRAVERSION which is originaly omitted will solve the
problem. However, you will end up with something like
“3.1.10-g05b777c-g22b4fcd-dirty SMP preempt mod_unload ARMv7”.

這裡寫圖片描述

“-g05b777c” is the number of current version generated by the version
control system(git, svn, etc.). After a little dig into Makefile, it
turns out version number is stored in the file
include/config/kernel.release and the local version is generated by the
script scripts/setlocalversion. By default, it will check if version
control system is available. If so, then it will append “dirty” to local
version after the commit number if the commit haven’t been submitted.
That is where “-g22b4fcd-dirty” comes from. We could simply supplement a
parameter as scripts/setlocalversion –save-scmversion and it won’t
generate the local version number.

kernel source root path:Makefile

這裡寫圖片描述