pci设备更新硬件设备详细厂商信息

修改lspci显示内容,说白了就是pcie设备在系统有一个配置文件,然后去修改配置文件。
cenOS该文件为/usr/share/hwdata/pci.ids ,
Ubuntu为 /usr/share/misc/pci.ids

make install

#Makefile
SRC_DIR=$(shell pwd)

install:
	@$(SRC_DIR)pci.update $(SRC_DIR)/pci.ids

pci.ids

#这里厂商号自己随便写的,如果雷同,请见谅 1fff
1fff  MY_COMPANY
	0001 first dev
	0002 second dev
	0003 third dev

pci.update

#! /bin/bash
# Copyright (C) 2017 Inter Corporation
# For licensing information, see the file 'LICENSE' in the root	folder
# $1 = system pci.ids file to update
# $2 = system pcitable file to update
# $3 = file with new entries in pci.ids file format
# $4 = pci.ids output file
# $5 = pcitable output file
# $6 = driver name for use in pcitable file

if [ -e "/etc/yum" ];then
	pci_ids_path=/usr/share/hwdata/pci.ids 
	pci_ids_path_tmp=/usr/share/hwdata/pci.ids.tmp
else
	pci_ids_path=/usr/share/misc/pci.ids 
	pci_ids_path_tmp=/usr/share/misc/pci.ids.tmp
fi

exec 3<$pci_ids_path
exec 4<$1
exec 5>$pci_ids_path_tmp

driver="hello_world"

# pattern matching strings
ID="[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]"
VEN="${ID}*"

line=
vendor=
scr_vendor=
arry=()
cnt=0
count=0
notes=
write_flag=1

while true
do
	#pci.update
	exec 0<&4
	while read -r line
	do
		if [[ $line == $VEN ]]
		then
			src_vendor=0x${line:0:4}
			#echo $src_vendor
		fi
		
		arry[$count]=$line
		#echo "${arry[$count]}"
		count=$(( $count + 1 ))
	done
	
	exec 0<&3
	exec 1>&5
	while read -r line
	do
		if [[ '#' == ${line:0:1} ]]
		then 
			notes=$line
			read -r line
		else
			notes=''
		fi	
		if [[ $line == $VEN ]]
		then
			write_flag=1
			#add pci.update
			vendor=0x${line:0:4}
			if [[ $src_vendor == $vendor ]]
			then 
				write_flag=0
			fi
			
			if [[ $src_vendor -lt $vendor ]]
			then
				while [[ "$cnt" -ne "$count" ]]
				do
					echo "${arry[$cnt]}"
					cnt=$(( $cnt + 1 ))
				done
			fi
		fi
		
		if [[ '#' == ${notes:0:1} ]]
		then
			echo "$notes"
		fi
		if [[ '1' == $write_flag ]]
		then 
			echo $line
		fi
	done
	break
done

exec 3<&-
exec 4<&-
exec 5>&-
mv $pci_ids_path_tmp $pci_ids_path
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值