linux 内核版本中自动加入 git 版本信息

在编译linux内核结束的时候 会使用mkiamge工具将 zImage 制作成 uImage,

OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
Image Name: Linux-3.14.0
Created: Thu Nov 29 01:21:16 2018
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2998624 Bytes = 2928.34 kB = 2.86 MB
Load Address: 40008000
Entry Point: 40008000
Image arch/arm/boot/uImage is ready
本文要提及的就是 Image Name: Linux-3.14.0 是怎么加上 git 仓库的号的。
当你本地的linux 内核上传到 git 仓库后, 再编译linux, Image Name: 就会发生变化

OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
Image Name: Linux-3.14.0-g589ec8b-dirty
Created: Thu Nov 29 01:34:27 2018
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2998640 Bytes = 2928.36 kB = 2.86 MB
Load Address: 40008000
Entry Point: 40008000
Image arch/arm/boot/uImage is ready
Linux-3.14.0-g589ec8b-dirty 后面多余出来的-g589ec8b-dirty 是怎么产生的呢。

和git仓库有关系, 执行 $ git log --oneline

xxx@xxx-pc:~/linux-3.14$ git log --oneline
589ec8b xxxxxxxxx
53439ff xxxxxxxxx
fdcc4e8 yyyyyyyyy
xxx@xxx-pc:~/linux-3.14$
g589ec8b-dirty和 打印出来的 589ec8b一模一样。 说明linux版本号3.14.0 后面追加了git 相关版本信息。

那么是在编译的什么时候 追加的呢?

xxx@xxx-pc:~/linux-3.14/scripts$ vi 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

将 if test -z “$(git rev-parse --show-cdup 2>/dev/null)” && 修改为

if test -n “$(git rev-parse --show-cdup 2>/dev/null)” &&

就可以不追加 -g589ec8b-dirty 了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值