2022-12-22 linux /proc/version 获取版本号的实现流程,添加一个获取固件版本号的接口

一、用cat /proc/version命令可以获取到版本号。

二、实现过程

1、驱动在kernel/fs/proc/version.c

#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/utsname.h>
#include <generated/compile.h>

static int version_proc_show(struct seq_file *m, void *v)
{
	seq_printf(m, linux_proc_banner,
		utsname()->sysname,
		utsname()->release,
		utsname()->version);
	return 0;
}

static int firmware_version_proc_show(struct seq_file *m, void *v)
{
	seq_printf(m, "V1.0 Date:%s",FIRMWARE_VERSION);
	return 0;
}

static int version_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, version_proc_show, NULL);
}

static int firmware_version_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, firmware_version_proc_show, NULL);
}

static const struct file_operations version_proc_fops = {
	.open		= version_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};

static const struct file_operations firmware_version_proc_fops = {
	.open		= firmware_version_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};
static int __init proc_version_init(void)
{
	proc_create("version", 0, NULL, &version_proc_fops);
	proc_create("firmware_version", 0, NULL, &firmware_version_proc_fops);
	return 0;
}
fs_initcall(proc_version_init);


2、kernel/scripts/mkcompile_h 调用脚本获取时间等版本信息

  echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"
  echo \#define FIRMWARE_VERSION \"`echo $FIRMWARE_VERSION`\"
  echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
  echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"

 3、执行上面的脚本后会生成\kernel\include\generated\compile.h

/* This file is auto generated, version 15 */
/* SMP */
#define UTS_MACHINE "arm64"
#define UTS_VERSION "#15 SMP Thu Dec 22 19:18:58 CST 2022"
#define FIRMWARE_VERSION "Thu Dec 22 19:18:58 CST 2022"
#define LINUX_COMPILE_BY "xxx"
#define LINUX_COMPILE_HOST "xxx"
#define LINUX_COMPILER "gcc version 6.3.1 20170404 (Linaro GCC 6.3-2017.05) "

 4、那mkcompile_h脚本在哪里调用到呢?

 5、上面的多加了一个获取固件版本号的firmware_version

三、参考文章

/proc/version 的生成过程_tanghui19900420的博客-CSDN博客_/proc/version 是如何生成的

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值