Firefly开源社区

标题: 哪位大佬知道update.img的头部信息如何修改 [打印本页]

作者: gyjk    时间: 2021-3-3 14:19
标题: 哪位大佬知道update.img的头部信息如何修改
  1. //解析固件,获得固件头部信息
  2. int analyticImage(const char *filepath, PRKIMAGE_HDR phdr) {
  3.     long long ulFwSize;
  4.     STRUCT_RKIMAGE_HEAD rkimage_head;
  5.     unsigned char m_md5[32];


  6.     int fd = open(filepath, O_RDONLY);
  7.     if (fd < 0) {
  8.         LOGE("Can't open %s\n", filepath);
  9.         return -2;
  10.     }

  11.     //1. image 头部信息读取
  12.     if (read(fd, &rkimage_head, sizeof(STRUCT_RKIMAGE_HEAD)) != sizeof(STRUCT_RKIMAGE_HEAD)) {
  13.         LOGE("Can't read %s\n(%s)\n", filepath, strerror(errno));
  14.         close(fd);
  15.         return -2;
  16.     }

  17.    [color=Red] if ((rkimage_head.reserved[14]=='H')&&(rkimage_head.reserved[15]=='I'))[/color] {
  18.         ulFwSize = *((DWORD *)(&rkimage_head.reserved[16]));
  19.         ulFwSize <<= 32;
  20.         ulFwSize += rkimage_head.dwFWOffset;
  21.         ulFwSize += rkimage_head.dwFWSize;
  22.     } else {
  23.         ulFwSize = rkimage_head.dwFWOffset + rkimage_head.dwFWSize;
  24.     }
  25.     rkimage_head.dwFWSize = ulFwSize - rkimage_head.dwFWOffset;
  26.     display_head(&rkimage_head);

  27.     //2. 固件md5 校验
  28.     long long fileSize;
  29.     int nMd5DataSize;

  30.     fileSize = lseek64(fd, 0L, SEEK_END);
  31.     nMd5DataSize = fileSize - ulFwSize;
  32.     if (nMd5DataSize >= 160) {
  33.         LOGE("md5 : not support sign image.\n");
  34.         //sign image
  35.         //m_bSignFlag = true;
  36.         //m_signMd5Size = nMd5DataSize-32;
  37.         //fseeko64(m_pFile,ulFwSize,SEEK_SET);
  38.         //fread(m_md5,1,32,m_pFile);
  39.         //fread(m_signMd5,1,nMd5DataSize-32,m_pFile);
  40.     } else {
  41.         lseek64(fd, -32, SEEK_END);
  42.         if ( read(fd, m_md5, 32) != 32) {
  43.             LOGE("lseek failed.\n");
  44.             return -2;
  45.         }
  46.     }

  47.     //3. image 地址信息读取
  48.     if (lseek64(fd, rkimage_head.dwFWOffset, SEEK_SET) == -1) {
  49.         LOGE("lseek failed.\n");
  50.         return -2;
  51.     }

  52.     if (read(fd, phdr, sizeof(RKIMAGE_HDR)) != sizeof(RKIMAGE_HDR)) {
  53.         LOGE("Can't read %s\n(%s)\n", filepath, strerror(errno));
  54.         close(fd);
  55.         return -2;
  56.     }

  57.     if (phdr->tag != RKIMAGE_TAG) {
  58.         LOGE("tag: %x\n", phdr->tag);
  59.         LOGE("Invalid image\n");
  60.         return -3;
  61.     }

  62.     if (rkimage_head.dwFWOffset) {
  63.         adjustFileOffset(phdr, rkimage_head.dwFWOffset, rkimage_head.dwBootOffset, rkimage_head.dwBootSize);
  64.     }

  65.     display_hdr(phdr);

  66.     close(fd);
  67.     #if 1
  68.     if (!compareMd5sum((char*)filepath, m_md5, 0, fileSize-32)) {
  69.         LOGE("Md5Check update.img fwSize:%ld", fileSize-32);
  70.         return -1;
  71.     }
  72.     #endif
  73.     LOGI("analyticImage ok.\n");
  74.     return 0;
  75. }
复制代码





欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) Powered by Discuz! X3.1