insmod版本不匹配问题

insmod xxxdrv.ko时候出现如下错误:

1
2
[   55.775651] xxxdrv: version magic '3.14.19+ SMP mod_unload ARMv7 p2v8 ' should be '3.14.19 SMP mod_unload ARMv7 p2v8 '
insmod: init_module '/system/lib/modules/xxxdrv.ko' failed (Exec format error)

很明显,版本号3.14.19+后面多了个+号,+是为了标记说这个kernel是不干净的。这个+号是scripts/setlocalversion文件中调用scm_version()函数检查Kernel_SrcDir/目录下的.scmversion文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# CONFIG_LOCALVERSION and LOCALVERSION (if set)
res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"

# scm version string if not at a tagged commit
if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
# full scm version string
res="$res$(scm_version)"
else
# append a plus sign if the repository is not in a clean
# annotated or signed tagged state (as git describe only
# looks at signed or annotated tags - git tag -a/-s) and
# LOCALVERSION= is not specified
if test "${LOCALVERSION+set}" != "set"; then
scm=$(scm_version --short)
#res="$res${scm:++}"
fi
fi

如果要去除掉+号,需要设置

  • LOCALVERSION设为为空;
  • defconfig中设置CONFIG_LOCALVERSION_AUTO is not set
  • Kernel_SrcDir/目录下创建空的.scmversion文件。