Linux-笔记 全志平台镜像中添加git提交号

引言

        通过在镜像中某个位置添加git提交号,可以方便排查与追溯是哪个提交编译出来的。 这里使用的全志T113平台,SDK为Tina5.0。

实现的办法有:

1、内核/proc/cpuinfo的打印信息及设备树中查看提交号

2、从设备树查看提交号

3、从uboot启动版本号查看提交号

实现:
内核/proc/cpuinfo查看提交号

        1、添加打印函数

        前面说到可以通过cpuinfo去查看git提交号,cpuinfo的实现函数位于 <SDK>/kernel/linux-5.4/arch/arm/kernel/setup.c 中的c_show函数,我们想要打印的信息可以放到函数里面去,如下图所示,添加了一行打印提交号。

static int c_show(struct seq_file *m, void *v)
{  char mac_eth[20] = {0};
    char name[20] = {0};
	int i, j;
	u32 cpuid;

	seq_printf(m, "Version: %s\n", GIT_COMMIT_INFO);	// 打印提交号

	for_each_online_cpu(i) {
		//省略
	}
   
	get_custom_mac_address(1, name, mac_eth);
	seq_printf(m, "Hardware\t: %s\n", machine_name);
	seq_printf(m, "Revision\t: %04x\n", system_rev);
	seq_printf(m, "Serial\t\t: %s\n", tqserialnum);
	seq_printf(m, "Mac\t\t: %s\n", macnum);

	return 0;
}

        GIT_COMMIT_INFO是一个宏,使用宏的原因是因为如果一直有新的提交,那这个提交号就需要修改,源码修改了必定会产生新的提交和提交号,就会一直无法对应提交号,将宏定义在一个被git忽略的头文件内,编译就自动获取提交号并生成头文件以解决问题。

        2、获取提交号

        git提交号是在<sdk>/kernel/linux-5.4/scriptsscripts/setlocalversion中获取的,由顶层makefile调用,生成内核版本号,我们可以利用源码脚本来实现我们的目的,该函数会判断是否使用git进行版本控制,如果是会输出提交号,反之为空,我们主要关注脚本内的scm_version()函数即可。

scm_version()
{
	local short
	short=false

	cd "$srctree"
	if test -e .scmversion; then
		cat .scmversion
		return
	fi
	if test "$1" = "--short"; then
		short=true
	fi

	# 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 [ -n "$android_release" ] && [ -n "$kmi_generation" ]; then
			printf '%s' "-$android_release-$kmi_generation"
		fi

		# 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{commitis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值