#define _DELETE_FILE
#define FALSE 0
#define TRUE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
typedef struct biosinfo
{
char Product_Name[255];
char Bios_Config_File[255];
char Bios_P_N[255];
char Bios_Version[255];
char Bios_Date[255];
}BISIF;
void ReadLogInfo(char *FileName,BISIF &Bisinfo);
bool ReadLineStr(char *FccStr,char *LineStr);
char *ProStr(char *str);
bool WriteLog(BISIF &Bisinfo,char *LgFileName);
bool BisInfoStrCmp(char *str,char *cmpstr);
void title();
void help();
int main(int argc,char *argv[])
{
/*title();*/
if(argc==3)
{
BISIF str={NULL,NULL,NULL,NULL,NULL};
ReadLogInfo("BiosInfo.log",str);
if(WriteLog(str,"BsIf.log")==FALSE)return 1;
if(strcmp(argv[1],"/PN")==0)
{
if(BisInfoStrCmp(str.Product_Name,argv[2])==TRUE)
{
printf("\033[32m Bios Name:%s Check Pass\n\033[0m",argv[2]);
return 0;
}
else
{
printf("\033[31m Bios Name:%s Check Fail\n\033[0m",argv[2]);
return 1;
}
}
else if(strcmp(argv[1],"/BC")==0)
{
if(BisInfoStrCmp(str.Bios_Config_File,argv[2])==TRUE)
{
printf("\033[32m Bios Config:%s Check Pass\n\033[0m",argv[2]);
return 0;
}
else
{
printf("\033[31m Bios Config:%s Check Fail\n\033[0m",argv[2]);
return 1;
}
}
else if(strcmp(argv[1],"/BPN")==0)
{
if(BisInfoStrCmp(str.Bios_P_N,argv[2])==TRUE)
{
printf("\033[32m Bios P_N %s Check Pass\n\033[0m",argv[2]);
return 0;
}
else
{
printf("\033[31m Bios P_N %s Check Fail\n\033[0m",argv[2]);
return 1;
}
}
else if(strcmp(argv[1],"/BV")==0)
{
if(BisInfoStrCmp(str.Bios_Version,argv[2])==TRUE)
{
printf("\033[32m Bios Version %s Check Pass\n\033[0m",argv[2]);
return 0;
}
else
{
printf("\033[31m Bios Date %s Check Fail\n\033[0m",argv[2]);
return 1;
}
}
else if(strcmp(argv[1],"/BD")==0)
{
if(BisInfoStrCmp(str.Bios_Date,argv[2])==TRUE)
{
printf("\033[32m Bios Date %s Check Pass\n\033[0m",argv[2]);
return 0;
}
else
{
printf("\033[31m Bios Date %s Check Fail\n\033[0m",argv[2]);
return 1;
}
}
return 1;
}
title();
help();
return 1;
}
void help()
{
system("clear");
printf("==========================================================================================================\n");
printf("LINUX GPU CHECKBIOS Program Tool -Ferex Incorporation,By Shenbo,2008-03-19\n");
printf("Usage :CHKBIOS[Parameter]\n");
printf("[Command]:\n");
printf(" \033[37;44m CHKBIOS /PN String ------------>Check Bios Name. \033[0m\n");
printf(" \033[37;44m CHKBIOS /BC String ------------>Check Bios Config File.\033[0m\n");
printf(" \033[37;44m CHKBIOS /BPN String ------------>Check Bios P/N. \033[0m\n");
printf(" \033[37;44m CHKBIOS /BV String ------------>Check Bios Version. \033[0m\n");
printf(" \033[37;44m CHKBIOS /BD String ------------>Check Bios Date. \033[0m\n");
printf("[Example]:\n");
printf(" CHKBIOS /PN \"E366 Polaris20 XTX A1 GDDR5 256Mx32 8GB\"\n");
}
void title()
{
system("clear");
printf(" Build Date:2018-03-19\n");
printf("FEREX EnvirSet Copyright by SHENBO CHECKBIOS V1.00\n");
printf("=========================================================================================================\n");
}
bool BisInfoStrCmp(char *str,char *cmpstr)
{
int n=0,y=0;
char cmpstr2[255];
memset(cmpstr2,0,sizeof(cmpstr));
while(str[n]!=':')n++;
n=n+3;
for(y=0;y<strlen(str);y++,n++)
{
cmpstr2[y]=str[n];
}
cmpstr2[strlen(cmpstr)]='\0';
if(strcmp(cmpstr2,cmpstr)==0)return TRUE;
return FALSE;
}
char *ProStr(char *str)
{
int n,x,total=0;
char buffstr[255];
memset(buffstr,0,sizeof(buffstr));
while(str[total]!='\n')total++;
for(n=0,x=4;x<total;x++,n++)
{
buffstr[n]=str[x];
}
buffstr[n]='\0';
return buffstr;
}
bool WriteLog(BISIF &Bisinfo,char *LgFileName)
{
FILE *fp;
fp=fopen(LgFileName,"w");
if(fp==NULL)
{
printf("\033[31m Write Bios Log File %s Err!!\n\033[0m",LgFileName);
getchar();
return FALSE;
}
fputs(Bisinfo.Product_Name,fp);
fputs("\n",fp);
fputs(Bisinfo.Bios_Config_File,fp);
fputs("\n",fp);
fputs(Bisinfo.Bios_P_N,fp);
fputs("\n",fp);
fputs(Bisinfo.Bios_Version,fp);
fputs("\n",fp);
fputs(Bisinfo.Bios_Date,fp);
fclose(fp);
return TRUE;
}
void ReadLogInfo(char *FileName,BISIF &Bisinfo)
{
FILE *fp;
char Temp[255];
memset(Temp,0,sizeof(Temp));
fp=fopen(FileName,"r");
if(fp==NULL)
{
printf("\033[31m Read File %s Not Found\n\033[0m",FileName);
getchar();
exit(1);
}
while((fgets(Temp,sizeof(Temp),fp))!=NULL)
{
if(ReadLineStr("Product Name",Temp)==TRUE)
{
strcpy(Bisinfo.Product_Name,ProStr(Temp));
}
else if(ReadLineStr("Bios Config File",Temp)==TRUE)
{
strcpy(Bisinfo.Bios_Config_File,ProStr(Temp));
}
else if(ReadLineStr("Bios P/N",Temp)==TRUE)
{
strcpy(Bisinfo.Bios_P_N,ProStr(Temp));
}
else if(ReadLineStr("Bios Version",Temp)==TRUE)
{
strcpy(Bisinfo.Bios_Version,ProStr(Temp));
}
else if(ReadLineStr("Bios Date",Temp)==TRUE)
{
strcpy(Bisinfo.Bios_Date,ProStr(Temp));
}
}
fclose(fp);
}
bool ReadLineStr(char *FccStr,char *LineStr)
{
int Flen=0;
int n,x;
char buf[255];
Flen=strlen(FccStr);
for(x=0,n=4;x<Flen;x++,n++)
{
buf[x]=LineStr[n];
}
buf[Flen]='\0';
if(strcmp(buf,FccStr)==0) return TRUE;
return FALSE;
}
refail ()
{
echo -e "\033[31m ******************************************* \033[0m"
echo -e "\033[31m *********** $BiosInfo Read Fail *********** \033[0m"
echo -e "\033[31m ******************************************* \033[0m"
read -n 1
exit 0
}
bffail ()
{
echo -e "\033[31m ****************************************** \033[0m"
echo -e "\033[31m *********** Check Bios Info Fail ********* \033[0m"
echo -e "\033[31m ****************************************** \033[0m"
read -n 1
exit 0
}
bfpass ()
{
echo -e "\033[32m ******************************************* \033[0m"
echo -e "\033[32m ********** Check Bios_1 Info Pass ********* \033[0m"
echo -e "\033[32m ******************************************* \033[0m"
exit 0
}
chmod 777 agt atiflash chkbios.sh CHKBIOS CHKBIOS.C
clear
path1=$PWD/BiosInfo.log
if [ -f $path1 ];then
rm $path1
fi
#-----------------------------------------Read Bios Info
BiosInfo=ReadBiosInfo
./atiflash -ai>BiosInfo.log
if [ $? -ne 0 ];then
refail
fi
#----------------------------------------Read vctfstatus
BiosInfo=vctfstatus
./agt -vctfstatus>>BiosInfo.log
if [ $? -ne 0 ];then
refail
fi
#---------------------------------------Read pciestatus
BiosInfo=pcestatus
./agt -pciestatus>>BiosInfo.log
if [ $? -ne 0 ];then
refail
fi
#-------------------------------------Read pplist
BiosInfo=pplist
./agt -pplist=short>>BiosInfo.log
if [ $? -ne 0 ];then
refail
fi
#------------------------------------Check Bios Info
./CHKBIOS /PN "E366 Polaris20 XTX A1 GDDR5 256Mx32 8GB"
if [ $? -ne 0 ];then
bffail
fi
./CHKBIOS /BC "366Y6MBU.S5S"
if [ $? -ne 0 ];then
bffail
fi
./CHKBIOS /BPN "113-1E366CU-S5S"
if [ $? -ne 0 ];then
bffail
fi
./CHKBIOS /BV "015.050.002.001.000000"
if [ $? -ne 0 ];then
bffail
fi
./CHKBIOS /BD "10/19/17 06:37"
if [ $? -ne 0 ];then
bffail
else
bfpass
fi