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生成信息变了,相应的源码如下:(kernel的顶层Makefile)

# Read KERNELRELEASE from include/config/kernel.release (if it exists)
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
....
define filechk_kernel.release
	echo "$(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 脚本如下:(kernel/scripts/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 commands
			if $short; then
				echo "+"
				return
			fi
			# 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`"; then
				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'

			# If we don't have a tag at all we print -g{commitish}.
			else
				printf '%s%s' -g $head
			fi
		fi

		# Is this git on svn?
		if git config --get svn-remote.svn.url >/dev/null; then
			printf -- '-svn%s' "`git svn find-rev $head`"
		fi

		# Check for uncommitted changes
		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
			printf '%s' -dirty
		fi

		# All done with git
		return
	fi

这里主要分为两个部分

  1. 获取当前这一份源码对应的内核版本的git tag信息(没有tag就输出commit-id), 然后拼接在内核主版本号后面,也就是上面的g8b02ff45
  2. 获取kernel仓库当前是否存在git或者svn仓库是否存在自己的修改提交,如果存在则拼接-dirty在后面

那么,是否显示,或者显示什么内容,就可以自己修改了。

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坂田民工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值