出问题的函数如下:

 1 char *calc_file_md5(const char* fw_name)
 2 {
 3     FRESULT result;
 4     FIL File;
 5     uint32_t BytesRead = 0,offset = 0,file_size = 0;
 6     MD5_CTX context;   //MD5
 7     unsigned char digest[16];
 8     uint8_t i = 0;
 9     
10     result = f_open(&File,fw_name,FA_OPEN_EXISTING|FA_READ);        //打开文件
11     if(FR_OK  != result)
12     {
13         DEBUG_LOG(DEBUG_FW,("Not Find %s\n",fw_name));
14         return 0;
15     }
16    file_size = File.obj.objsize;//结束地址为起始地址加上文件大小。
17    MD5Init(&context);
18    while(1)
19    {
20        f_lseek(&File,offset);
21        result = f_read(&File,file_buffer,2048,&BytesRead);
22        if(result || BytesRead==0)
23        {
24             DEBUG_LOG(DEBUG_FW,("read %s error!\n",fw_name));
25             return 0;
26        }
27        MD5Update(&context, file_buffer, BytesRead);
28        
29        offset+=BytesRead;
30        if(offset==file_size)
31              break;
32    }
33     
34     MD5Final(digest, &context);
35     f_close(&File);
36     for (i = 0; i < 16; i++)
37         rt_sprintf(cal_md5_str+(i*2),"%02X",digest[i]);
38     
39     DEBUG_LOG(DEBUG_FW,("cal_md5:%s\n",cal_md5_str));
40     
41     return cal_md5_str;
42 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
  • 2021-11-14
  • 2021-09-24
猜你喜欢
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-12-29
  • 2021-11-01
  • 2021-06-22
  • 2021-09-02
相关资源
相似解决方案