EDID介绍 https://blog.csdn.net/Gplusplus/article/details/52597033?locationNum=1&fps=1
客户要求经常修改 厂商名,产品ID,生产年周,屏尺寸,屏名称。制作脚本批量修改EDID文件
#!/bin/bash
function ManufacturerNameTrans()
{
echo "ManufacturerNameTrans $1"
manuName=`echo "$1"| tr -d "\n" | od -An -t dC | awk 'BEGIN{FS=" ";total=0} {if(NR<=1){for(i =1;i<4;i++){c=$i-65+1;if(c>26){c=26};if(c<0){c=1};total=lshift(total, 5);total=c+total}}} END{printf "%.4x", total}'`
}
function ProductCodeTrans()
{
echo "ProductCodeTrans $1"
tmp=$1
len=`echo $1 | wc -L `
#echo $len
if [ $len -lt 4 ];then
echo "less then 4 byte"
for((i = 1; i <= $[ 4 - $len ]; i++))
do
tmp="0"$tmp
done
fi
proCode=`echo ${tmp:2:2}${tmp:0:2}`
}
function WeekTrans()
{
echo "WeekTrans $1"
tmp=`printf "%.2x" $1`
week=`echo $tmp`
}
function YearTrans()
{
echo "YearTrans $1"
tmp=`printf "%.2x" $[ $1 - 1990 ]`
year=`echo $tmp`
}
function ScreenSizeHTrans()
{
echo "ScreenSizeHTrans $1"
tmp=`printf "%.2x" $1`
scSizeH=`echo $tmp`
}
function ScreenSizeVTrans()
{
echo "ScreenSizeVTrans $1"
tmp=`printf "%.2x" $1`
scSizeV=`echo $tmp`
}
function MonitorNameTrans()
{
echo "MonitorNameTrans $1"
moniName=`echo "$1"| tr -d "\n" | od -An -t xC |tr -d " "`
}
#param -dexfile
function WriteManufacturerName()
{
tmp=`echo 0x${manuName:0:2}`;
sed -i "9c${tmp}" $1
tmp=`echo 0x${manuName:2:2}`;
sed -i "10c${tmp}" $1
}
function WriteProductCode()
{
tmp=`echo 0x${proCode:0:2}`;
sed -i "11c${tmp}" $1
tmp=`echo 0x${proCode:2:2}`;
sed -i "12c${tmp}" $1
}
function WriteWeek()
{
tmp=`echo 0x${week:0:2}`;
sed -i "17c${tmp}" $1
}
function WriteYear()
{
tmp=`echo 0x${year:0:2}`;
sed -i "18c${tmp}" $1
}
function WriteScreenSizeH()
{
tmp=`echo 0x${scSizeH:0:2}`;
sed -i "22c${tmp}" $1
}
function WriteScreenSizeV()
{
tmp=`echo 0x${scSizeV:0:2}`;
sed -i "23c${tmp}" $1
}
function WriteMonitorName()
{
sed -i "91c0x00" $1
sed -i "92c0x00" $1
sed -i "93c0x00" $1
sed -i "94c0xFC" $1
sed -i "95c0x00" $1
len=`echo ${#moniName}`
len=$[ $len / 2 ]
for((i = 1; i <= 13; i++))
do
if [ $i = $[ $len + 1 ] ];then
tmp=0x0A
elif [ $i -gt $len ];then
tmp=0x20
else
tmp=`echo 0x${moniName:$[ $i - 1 ]*2:2}`
fi
sed -i "$[ $i + 95 ]c${tmp}" $1
done
}
function WriteInfo()
{
if [ "${manuName}" != "" ];then
WriteManufacturerName $1
fi
if [ "${proCode}" != "" ];then
WriteProductCode $1
fi
if [ "${week}" != "" ];then
WriteWeek $1
fi
if [ "${year}" != "" ];then
WriteYear $1
fi
if [ "${scSizeH}" != "" ];then
WriteScreenSizeH $1
fi
if [ "${scSizeV}" != "" ];then
WriteScreenSizeV $1
fi
if [ "${moniName}" != "" ];then
WriteMonitorName $1
fi
}
function WriteBinFile()
{
extension=
rm -f $file_txt
rm -f $file_txt"_1"
rm -f $file_txt"_2"
#change to ASCII Txt
od -An -v -tx1 $1 > $file_txt
awk 'BEGIN{FS=" ";total = "0x"} {if(NR<=16){for(i =1;i<17;i++){c = (total""$i);print c}} }' $file_txt > $file_txt"_1"
#replace keyword
WriteInfo $file_txt"_1"
extension=`sed -n '127p' $file_txt"_1"`
echo "extension $extension"
#
awk --non-decimal-data -F, '{printf "%d\n",$1}' $file_txt"_1" >> $file_txt"_2"
#calculate the checksum
checksum=`awk 'BEGIN{FS=" ";total = 0} {if(NR<=127){for(i=1;i<2;i++){total+=$i;}} }END{printf "%d\n",(256-(total%256))}' $file_txt"_2"`
if [ ${checksum} -eq 256 ];then
checksum=0
fi
sed -i "128s/.*/$checksum/" $file_txt"_2"
echo "New checksum "$checksum
#write back to the original files
filen=$1
tim=`stat -c %y $1 | cut -d '.' -f 1`
filebk=$1".`date -d "${tim}" +%Y%m%d%H%M%S`"
#echo "filebk ${filebk}"
mv ${filen} ${filebk}
binarry=""
filelen=`wc -l $file_txt"_2" | cut -d " " -f 1`
echo "$filelen"
if [ $filelen = "256" ];then
echo "Get HDMI bin file."
elif [ $filelen = "128" ];then
echo "Get VGA bin file."
else
echo "???"
fi
for((i = 0; i < $filelen ; i++))
do
byte=`sed -n "$[ $i + 1 ]p" $file_txt"_2"`
tmp=`printf "%.2x" $byte`
#echo "$i. $tmp $byte"
binarry=$binarry"\x$tmp"
done
#echo $binarry
printf $binarry | dd of=$1 bs=$filelen count=$filelen conv=notrunc seek=0
rm -f $file_txt
rm -f $file_txt"_1"
rm -f $file_txt"_2"
echo ""
}
file_txt=test
read -p "Manufacturer Name(A~Z): " manuName;
read -p "Product Code(4byte): " proCode;
read -p "Week of Manufacture(0~255): " week;
read -p "Year of Manufacture: " year;
read -p "Screen Size Horizontal(0~255):" scSizeH;
read -p "Screen Size Vertical(0~255):" scSizeV;
read -p "Monitor Name(13byte):" moniName;
echo "----------------------"
if [ "${manuName}" != "" ];then
ManufacturerNameTrans $manuName
echo "--"$manuName
fi
if [ "${proCode}" != "" ];then
ProductCodeTrans $proCode
echo "--"$proCode
fi
if [ "${week}" != "" ];then
WeekTrans $week
echo "--"$week
fi
if [ "${year}" != "" ];then
YearTrans $year
echo "--"$year
fi
if [ "${scSizeH}" != "" ];then
ScreenSizeHTrans $scSizeH
echo "--"$scSizeH
fi
if [ "${scSizeV}" != "" ];then
ScreenSizeVTrans $scSizeV
echo "--"$scSizeV
fi
if [ "${moniName}" != "" ];then
MonitorNameTrans $moniName
echo "--"$moniName
fi
echo
while read -p "Set Bin File Name('exit' to stop):" filename
do
tmp=`echo ${filename##*.} | tr [a-z] [A-Z]`
#echo "tmp $tmp"
if [ ${filename}x = "exit"x ];then
exit
elif [ ${tmp}x = "BIN"x ];then
if [ -f $filename ];then
echo $filename
WriteBinFile $filename
else
echo "$filename not find."
fi
else
continue;
fi
done