• 自定义打包工具对应的解析代码


    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!
    ");
            return -1;
        } 
    
        // check header md5
        ak_print_normal("file data len=%d
    ",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
    ",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!
    ");
            return -1;
        }
        ak_print_normal("check sum ok
    ");
        
        // 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
    ",file->version);
        ak_date_to_string(&file->date, str_temp);
        ak_print_notice("release date: %s
    ",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!
    ");
            return -1;
        }
    
        ret = ak_get_update_cfg(&upcfg);
        if(ret) {
            ak_print_error_ex("ak_get_update_cfg err!
    ");
            return -1;
        }
        
        ak_print_notice("
    write flash,pl wait and keep power on
    "); 
    
        upcfg.flg = 1;
        ret = ak_set_update_cfg(&upcfg);
        if(ret) {
            ak_print_error_ex("ak_set_update_cfg err!
    ");
            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!
    ");
                return -1;
            }
        }
        
        if(mcu_up_flg)
        {
            akp_sense_close();
            mcu_update(mcu_buf,mcu_len);//mcu will reset ak
        }
        return ret;
    }
  • 相关阅读:
    js append()和appendChild()和insertBefore()的区别
    webpack打包工具简单案例
    Vue $ref 的用法
    Vue学习笔记-作用域插槽
    Vue学习笔记-插槽基本使用
    Vue学习笔记-父子通信案例
    Echarts案例-折线图
    Echarts案例-柱状图
    软件构造实验三-递归下降分析分析法
    软件构造实验二-拷贝一个c文件 将其中的关键字int替换成float
  • 原文地址:https://www.cnblogs.com/mic-chen/p/9925482.html
Copyright © 2020-2023  润新知