本文主要是介绍kernel的module目录名疑问,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
kernel的module目录名疑问
遇到的问题:
当修改内核后重新编译后烧到设备上,启动后发现kernel的module名和uname -r对不上了,导致驱动无法加载,出现如下的错误信息
modprobe: can't change directory to '4.1.15-g8b02ff45-dirty': No such file or directory
原因:kernel的module目录匹配是由kernel编译时生成的版本决定的,本来制作rootfs时创建module文件夹名字是4.1.15,但是修改了内核,内核的version生成信息变了,相应的源码如下:
# Read KERNELRELEASE from include/config/kernel.release (if it exists)
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
....
define filechk_kernel.releaseecho "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
endef# Store (new) KERNELRELEASE string in include/config/kernel.release
include/config/kernel.release: include/config/auto.conf FORCE$(call filechk,kernel.release)
$(KERNELRELEASE)
就是最终生成的4.1.15-g8b02ff45-dirty
, 它由$(KERNELVERSION)
和setlocalversion
脚本执行的结果拼接而成,其中$(KERNELVERSION)就是内核原本的版本号4.1.15,而
-g8b02ff45-dirty
就是脚本的输出, setlocalversion 脚本如下:
# Check for git and a git repo.if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&head=`git rev-parse --verify --short HEAD 2>/dev/null`; then# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore# it, because this version is defined in the top level Makefile.if [ -z "`git describe --exact-match 2>/dev/null`" ]; then# If only the short version is requested, don't bother# running further git commandsif $short; thenecho "+"returnfi# If we are past a tagged commit (like# "v2.6.30-rc5-302-g72357d5"), we pretty print it.if atag="`git describe 2>/dev/null`"; thenecho "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'# If we don't have a tag at all we print -g{commitish}.elseprintf '%s%s' -g $headfifi# Is this git on svn?if git config --get svn-remote.svn.url >/dev/null; thenprintf -- '-svn%s' "`git svn find-rev $head`"fi# Check for uncommitted changesif git diff-index --name-only HEAD | grep -qv "^scripts/package"; thenprintf '%s' -dirtyfi# All done with gitreturnfi
这里主要分为两个部分
- 获取当前这一份源码对应的内核版本的git tag信息(没有tag就输出commit-id), 然后拼接在内核主版本号后面,也就是上面的
g8b02ff45
- 获取kernel仓库当前是否存在git或者svn仓库是否存在自己的修改提交,如果存在则拼接
-dirty
在后面
这篇关于kernel的module目录名疑问的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!