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.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 脚本如下:

	# 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在后面

相关推荐

  1. kernelmodule目录名疑问

    2023-12-31 08:10:01       53 阅读
  2. 【React】常见疑问整理

    2023-12-31 08:10:01       60 阅读
  3. 关于ARINC653疑问

    2023-12-31 08:10:01       36 阅读
  4. .net 实现 Webscoket 对象一些细节和疑问

    2023-12-31 08:10:01       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-31 08:10:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-31 08:10:01       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-31 08:10:01       82 阅读
  4. Python语言-面向对象

    2023-12-31 08:10:01       91 阅读

热门阅读

  1. Linux驱动开发之杂项设备注册和Linux2.6设备注册

    2023-12-31 08:10:01       40 阅读
  2. LeetCode 1185. 一周中的第几天

    2023-12-31 08:10:01       54 阅读
  3. python------Pymysql模块

    2023-12-31 08:10:01       49 阅读
  4. 16. Mysql 自定义函数

    2023-12-31 08:10:01       56 阅读