自定義打包工具對應的解析程式碼
阿新 • • 發佈:2018-11-07
int akp_update_firmware(update_file_t *file,long size) { int i = 0; int ret = -1; T_SYSUPDATE_DATA upcfg; // parse file header: "anyka update" if(strcmp(file->magic,"anyka update") != 0) {\ ak_print_error("file header error!\n"); return -1; } // check header md5ak_print_normal("file data len=%d\n",file->data_len); char check_sum[UPDATE_MD5_CHECK_LEN]; void *check_addr = &file->version[0]; int check_len = file->data_len+((unsigned int)&file->data[0]-(unsigned int)&file->version[0]); MDMemory(check_addr, check_sum,check_len);//ak_print_normal("check_len=%d\n",check_len); //LOG_DATA_DETAIL("sum", check_sum, UPDATE_MD5_CHECK_LEN); if(0 != memcmp(&file->md5_check,check_sum,sizeof(check_sum))) { ak_print_error("file data check sum error!\n"); return -1; } ak_print_normal("check sum ok\n");// print version and date char str_temp[64]; #if 0 int version_main = file->version_main; int version_middle = file->version_middle; int version_minimum = file->version_minimum; memset(str_temp,0,sizeof(str_temp)); sprintf(str_temp,"%d.%d.%d",version_main,version_middle,version_minimum); #endif ak_print_notice("update verion %s\n",file->version); ak_date_to_string(&file->date, str_temp); ak_print_notice("release date: %s\n",str_temp); // check file num unsigned int file_num = file->file_num; if(file_num > UPDATE_FILE_NUM_MAX) { ak_print_error("file num too many!\n"); return -1; } ret = ak_get_update_cfg(&upcfg); if(ret) { ak_print_error_ex("ak_get_update_cfg err!\n"); return -1; } ak_print_notice("\nwrite flash,pl wait and keep power on\n"); upcfg.flg = 1; ret = ak_set_update_cfg(&upcfg); if(ret) { ak_print_error_ex("ak_set_update_cfg err!\n"); return -1; } char *paddr = NULL; unsigned int mcu_len = 0,len = 0; update_sub_file_info_t *sub_file_info = NULL; char mcu_up_flg = 0; char *mcu_buf = NULL; for(i = 0; i < file_num; i++) { sub_file_info = &file->psub_file_info[i]; paddr = &file->data[sub_file_info->addr]; len = sub_file_info->len; ak_print_normal("sub file name %s",sub_file_info->name); if(strcmp(sub_file_info->name,"MCU") == 0){ mcu_up_flg = 1; mcu_buf = paddr; mcu_len = len; ret = ak_update(paddr,len,sub_file_info->name); if(ret) { break; } } else { //if(strcmp(sub_file_info->name,"KERNEL") == 0) ret = ak_update(paddr,len,sub_file_info->name); if(ret) { break; } } } if(ret == 0) { upcfg.flg = 0; ret = ak_set_update_cfg(&upcfg); if(ret) { ak_print_error_ex("ak_set_update_cfg err!\n"); return -1; } } if(mcu_up_flg) { akp_sense_close(); mcu_update(mcu_buf,mcu_len);//mcu will reset ak } return ret; }