本帖最后由 wowu 于 2021-8-4 19:26 编辑
unsigned int sample_index = 0; //从TEST_data采集64位个字节
unsigned int data_index = 0; //bin文件字符索引,固件bin文件大小不要超过65K
unsigned int read_times = 0;
unsigned int BIN_location = 0;
void data_reset()
{
sample_index = 0;
data_index = 0;
read_times = 0;
BIN_location = 0;
A=0x67452301;
B=0xefcdab89;
C=0x98badcfe;
D=0x10325476;
a=0;
b=0;
c=0;
d=0;
memset(flen,0x00,sizeof(flen));
memset(x,0x00,sizeof(x));
}
void read_group_tempbuf(unsigned long fileSize)
{
memset(x,0,64);
sample_index = 0;
for(j = 0;j < 16;j++)//fread(&x,4,16,fp) 以4字节为一组,共16组往x写入数据
{
for(k = 0;k < 4;k++)
{
if((read_times >= fileSize/1024)&&(data_index >= fileSize%1024)) break;//当对最后一部分小于1K的bin文件处理
((char*)x)[sample_index] = Temp_Ex_Flash[data_index];
data_index++;
sample_index++;
}
}
}
void get_bin_md5(unsigned long fileSize,char *result)
{
unsigned short i = 0;
UINT br;
FIL file;
data_reset();
f_open(&file,"/car.bin",FA_READ);
for(read_times = 0;read_times < fileSize/1024;read_times++)//对整K进行md5计算
{
f_read (&file, &Temp_Ex_Flash,1024, &br);
BIN_location += 1024;
for(i = 0;i < 16;i++)//刚好对读出的1Kbin文件进行md5计算
{
read_group_tempbuf(fileSize);
md5();
}
data_index = 0;//最大只到1023
}
memset(Temp_Ex_Flash,0,1025);
f_read (&file, &Temp_Ex_Flash,fileSize%1024, &br);
read_group_tempbuf(fileSize);
for(i = 0;i < (fileSize%1024)/64;i++)
{
md5();
read_group_tempbuf(fileSize);
}
((char*)x)[fileSize%64]=128;//文件结束补1,0操作 10000000
flen[1]=fileSize/0x20000000; //转换二进制文件大小(byte->bit)
flen[0]=(fileSize%0x20000000)*8;
if(fileSize%64>55) md5(),memset(x,0,64);
memcpy(x+14,flen,8);
md5();
sprintf(result,"%08x%08x%08x%08x",PP(A),PP(B),PP(C),PP(D));
}
|