93 lines
2.2 KiB
Bash
93 lines
2.2 KiB
Bash
#!/bin/sh
|
|
|
|
log="/tmp/nicsensor_debug.log"
|
|
|
|
INFO="Info"
|
|
WARNING="Warning"
|
|
ERROR="Error"
|
|
|
|
# fru 烧录的起始地址
|
|
fru_offset="0x00 0x00"
|
|
|
|
fru_write_size=0
|
|
fru_write_data=""
|
|
|
|
# 将传入的fru文件解析为可被i2cransfer直接写入的数据
|
|
parse_fru_write_data(){
|
|
# 判断fru文件是否存在于当前目录
|
|
if [ -e $fru_file_name ];then
|
|
format_log_print $INFO "Fru file exist!"
|
|
else
|
|
format_log_print $ERROR "Fru file not exist!"
|
|
format_print $WARNING "Fru file not exist in current directory!"
|
|
format_print $ERROR "Operation Failed!"
|
|
exit 1
|
|
fi
|
|
|
|
# 计算需要写入的fru文件大小
|
|
fru_write_size=`ls -lht | grep $fru_file_name | awk '{print $5}'`
|
|
format_print $INFO "Fru File [$fru_file_name] size = $fru_write_size Bytes"
|
|
format_log_print $INFO "Fru File [$fru_file_name] size = $fru_write_size Bytes"
|
|
|
|
# 获取fru文件的 raw data
|
|
fru_raw_data=`hexdump -C $fru_file_name | awk '{
|
|
for(i=2;i<18;i++){
|
|
print $i
|
|
}
|
|
}'`
|
|
format_log_print $INFO "Fru Raw Data: $fru_raw_data"
|
|
|
|
# 将raw data解析为可被 i2ctransfer 写入的数据
|
|
fru_write_data=`echo $fru_raw_data | awk -v size=$fru_write_size '{
|
|
for(i=1;i<=size;i++){
|
|
printf "0x%s ",$i
|
|
}
|
|
}'`
|
|
}
|
|
|
|
# 支持FRU读取
|
|
read_fru(){
|
|
|
|
res_fru=`i2ctransfer -y $i2c_bus w2@$chip_slave $fru_offset r256`
|
|
|
|
# 将FRU数据按照每行16个字符输出
|
|
echo "The Fru Data :"
|
|
echo "$res_fru" | \
|
|
awk '{
|
|
line="";
|
|
count=0;
|
|
|
|
for(i=1; i<=NF; i++){
|
|
hex=substr($i, 3);
|
|
|
|
if(line != ""){
|
|
line = line " ";
|
|
}
|
|
line = line hex;
|
|
|
|
count++;
|
|
if (count == 16){
|
|
print line;
|
|
line = "";
|
|
count = 0;
|
|
}
|
|
}
|
|
|
|
if(line != ""){
|
|
print line;
|
|
}
|
|
}'
|
|
|
|
}
|
|
|
|
# 20240926 支持写板卡FRU
|
|
write_fru(){
|
|
|
|
i2c_write_byte=$(($fru_write_size+2))
|
|
# 组装command并发送
|
|
write_command="i2ctransfer -y $i2c_bus w$i2c_write_byte@$chip_slave $fru_offset $fru_write_data"
|
|
write_res=`$write_command`
|
|
format_log_print $INFO "Exec Command: $write_command"
|
|
|
|
}
|