• 自定义的打包工具源码


    // main.c
    // packet.h
    #ifndef __PCKET_PRO_H__
    #define __PCKET_PRO_H__
        
    #include <stdint.h>
    
    struct ak_date {
        int year;         //4 number
        int month;        //1-12
        int day;         //1-31
        int hour;         //0-23
        int minute;     //0-59
        int second;     //0-59
        int timezone;     //local time zone 0-23
    };
    
    
    #define UPDATE_FILE_NUM_MAX         (20)
    #define UPDATE_FILE_MAGIC_LEN       (32)
    #define UPDATE_MD5_CHECK_LEN        (16)
    #define UPDATE_VERSION_LEN          (16)
    
    
    
    #define UPDATE_NAME_LEN             (6+1)           // burntool use 6,add ''
    typedef struct update_sub_file_info{
        char            name[UPDATE_NAME_LEN];          // name
        char            version[UPDATE_VERSION_LEN];    // file version
        unsigned int    addr;                           // bin data offset addr
        unsigned int    len;                            // bin data len
    }update_sub_file_info_t;
    
    typedef struct update_file              
    {
        // header
        char                magic[UPDATE_FILE_MAGIC_LEN];                   // fix to "anyka update"
        unsigned char       md5_check[UPDATE_MD5_CHECK_LEN];                // md5 check for all after this
        
        char                version[UPDATE_VERSION_LEN];
        struct ak_date      date;                                           // file time
        unsigned int        file_num;                                       //                 
        update_sub_file_info_t  psub_file_info[UPDATE_FILE_NUM_MAX];
    
        // body
        unsigned int                data_len;
        char                        data[];                                 // dynamic array                          
    }update_file_t;
    
    
    #endif
    
    
    /* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
     */
     
    /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
    rights reserved.
    License to copy and use this software is granted provided that it
    is identified as the "RSA Data Security, Inc. MD5 Message-Digest
    Algorithm" in all material mentioning or referencing this software
    or this function.
    License is also granted to make and use derivative works provided
    that such works are identified as "derived from the RSA Data
    Security, Inc. MD5 Message-Digest Algorithm" in all material
    mentioning or referencing the derived work.
    RSA Data Security, Inc. makes no representations concerning either
    the merchantability of this software or the suitability of this
    software for any particular purpose. It is provided "as is"
    without express or implied warranty of any kind.
    These notices must be retained in any copies of any part of this
    documentation and/or software.
     */
    #include "md5c.h"
    #include <string.h>
    #include <stdio.h>
     
    /* Constants for MD5Transform routine.
    */
     
     
    #define S11 7
    #define S12 12
    #define S13 17
    #define S14 22
    #define S21 5
    #define S22 9
    #define S23 14
    #define S24 20
    #define S31 4
    #define S32 11
    #define S33 16
    #define S34 23
    #define S41 6
    #define S42 10
    #define S43 15
    #define S44 21
     
    static void MD5_memcpy (POINTER output, POINTER input, unsigned int len);
    static void MD5Transform (UINT4 state[4], unsigned char block[64]);
    static void Encode (unsigned char *output, UINT4 *input, unsigned int len);
    static void MD5_memset (POINTER output, int value, unsigned int len);
    static void Decode (UINT4 *output, unsigned char *input, unsigned int len);
     
    static unsigned char PADDING[64] = {
        0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
     
    /* F, G, H and I are basic MD5 functions.
    */
    #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
    #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
    #define H(x, y, z) ((x) ^ (y) ^ (z))
    #define I(x, y, z) ((y) ^ ((x) | (~z)))
     
    /* ROTATE_LEFT rotates x left n bits.
    */
    #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
     
    /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
    Rotation is separate from addition to prevent recomputation.
    */
    #define FF(a, b, c, d, x, s, ac) { 
        (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); 
        (a) = ROTATE_LEFT ((a), (s)); 
        (a) += (b); 
        }
    #define GG(a, b, c, d, x, s, ac) { 
        (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); 
        (a) = ROTATE_LEFT ((a), (s)); 
        (a) += (b); 
        }
    #define HH(a, b, c, d, x, s, ac) { 
        (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); 
        (a) = ROTATE_LEFT ((a), (s)); 
        (a) += (b); 
        }
    #define II(a, b, c, d, x, s, ac) { 
        (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); 
        (a) = ROTATE_LEFT ((a), (s)); 
        (a) += (b); 
        }
     
    /* MD5 initialization. Begins an MD5 operation, writing a new context.
     */
    void MD5Init (MD5_CTX *context)                                     /* context */
    {
        context->count[0] = context->count[1] = 0;
        /* Load magic initialization constants.
        */
        context->state[0] = 0x67452301;
        context->state[1] = 0xefcdab89;
        context->state[2] = 0x98badcfe;
        context->state[3] = 0x10325476;
    }
     
    /* MD5 block update operation. Continues an MD5 message-digest
      operation, processing another message block, and updating the
      context.
     */
    void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen)
     
    {
        unsigned int i, index, partLen;
     
        /* Compute number of bytes mod 64 */
        index = (unsigned int)((context->count[0] >> 3) & 0x3F);
     
        /* Update number of bits */
        if ((context->count[0] += ((UINT4)inputLen << 3))
            < ((UINT4)inputLen << 3))
            context->count[1]++;
        context->count[1] += ((UINT4)inputLen >> 29);
     
        partLen = 64 - index;
     
        /* Transform as many times as possible.
        */
        if (inputLen >= partLen) {
            MD5_memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
            MD5Transform (context->state, context->buffer);
     
            for (i = partLen; i + 63 < inputLen; i += 64)
                MD5Transform (context->state, &input[i]);
     
            index = 0;
        }
        else
            i = 0;
     
        /* Buffer remaining input */
        MD5_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i],inputLen-i);
    }
     
    /* MD5 finalization. Ends an MD5 message-digest operation, writing the
      the message digest and zeroizing the context.
     */
    void MD5Final (unsigned char digest[16], MD5_CTX *context)                                 
    {
        unsigned char bits[8];
        unsigned int index, padLen;
     
        /* Save number of bits */
        Encode (bits, context->count, 8);
     
        /* Pad out to 56 mod 64.
        */
        index = (unsigned int)((context->count[0] >> 3) & 0x3f);
        padLen = (index < 56) ? (56 - index) : (120 - index);
        MD5Update (context, PADDING, padLen);
     
        /* Append length (before padding) */
        MD5Update (context, bits, 8);
     
        /* Store state in digest */
        Encode (digest, context->state, 16);
     
        /* Zeroize sensitive information.
        */
        MD5_memset ((POINTER)context, 0, sizeof (*context));
    }
     
    /* MD5 basic transformation. Transforms state based on block.
     */
    static void MD5Transform (UINT4 state[4], unsigned char block[64])
    {
        UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
     
        Decode (x, block, 64);
     
        /* Round 1 */
        FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
        FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
        FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
        FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
        FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
        FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
        FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
        FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
        FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
        FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
        FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
        FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
        FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
        FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
        FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
        FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
     
        /* Round 2 */
        GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
        GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
        GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
        GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
        GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
        GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
        GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
        GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
        GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
        GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
        GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
        GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
        GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
        GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
        GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
        GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
     
        /* Round 3 */
        HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
        HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
        HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
        HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
        HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
        HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
        HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
        HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
        HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
        HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
        HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
        HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
        HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
        HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
        HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
        HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
     
        /* Round 4 */
        II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
        II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
        II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
        II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
        II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
        II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
        II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
        II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
        II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
        II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
        II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
        II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
        II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
        II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
        II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
        II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
     
        state[0] += a;
        state[1] += b;
        state[2] += c;
        state[3] += d;
     
        /* Zeroize sensitive information.
        */
        MD5_memset ((POINTER)x, 0, sizeof (x));
    }
     
    /* Encodes input (UINT4) into output (unsigned char). Assumes len is
      a multiple of 4.
     */
    static void Encode (unsigned char *output, UINT4 *input, unsigned int len)
    {
        unsigned int i, j;
     
        for (i = 0, j = 0; j < len; i++, j += 4) {
            output[j] = (unsigned char)(input[i] & 0xff);
            output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
            output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
            output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
        }
    }
     
    /* Decodes input (unsigned char) into output (UINT4). Assumes len is
      a multiple of 4.
     */
    static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
    {
        unsigned int i, j;
     
        for (i = 0, j = 0; j < len; i++, j += 4)
            output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
            (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
    }
     
    /* Note: Replace "for loop" with standard memcpy if possible.
     */
     
    static void MD5_memcpy (POINTER output, POINTER input, unsigned int len)
    {
        unsigned int i;
     
        for (i = 0; i < len; i++)
            output[i] = input[i];
    }
     
    /* Note: Replace "for loop" with standard memset if possible.
     */
    static void MD5_memset (POINTER output, int value, unsigned int len)
    {
        unsigned int i;
     
        for (i = 0; i < len; i++)
            ((char *)output)[i] = (char)value;
    }
    
    /* Digests a memory and prints the result.
     */
    void MDMemory (char *pdata,unsigned char digest[16],unsigned int len)
    {
        MD5_CTX context;
     
        MD5Init (&context);
        MD5Update (&context, (unsigned char *)pdata, len);
        MD5Final (digest, &context);
    }
    
    
    /* Digests a string and prints the result.
     */
    void MDString (char *string,unsigned char digest[16])
    {
        MD5_CTX context;
        unsigned int len = strlen (string);
     
        MD5Init (&context);
        MD5Update (&context, (unsigned char *)string, len);
        MD5Final (digest, &context);
    }
    /* Digests a file and prints the result.
     */
    int MD5File (char *filename,unsigned char digest[16])
    {
        FILE *file;
        MD5_CTX context;
        int len;
        unsigned char buffer[1024];
     
        if ((file = fopen (filename, "rb")) == NULL)
            return -1;
        else {
            MD5Init (&context);
            while (len = fread (buffer, 1, 1024, file))
                MD5Update (&context, buffer, len);
            MD5Final (digest, &context);
     
            fclose (file);
        }
        return 0;
    }
    void MD5UpdaterString(MD5_CTX *context,const char *string)
    {
        unsigned int len = strlen (string);
        MD5Update (context, (unsigned char *)string, len);
    }
    int MD5FileUpdateFile (MD5_CTX *context,char *filename)
    {
        FILE *file;
        int len;
        unsigned char buffer[1024];
     
        if ((file = fopen (filename, "rb")) == NULL)
            return -1;
        else {
            while (len = fread (buffer, 1, 1024, file))
                MD5Update (context, buffer, len);
            fclose (file);
        }
        return 0;
    }
    
    void md5_demo(int argc, char** argv)
    {
        unsigned char digest[16];  //瀛樻斁缁撴灉
        int i;
    
        if(2 != argc) {
            printf("usage : md5 [text]
    ");
            return;
        }
               
        MDString(argv[1],digest); //鐩存帴杈撳叆瀛楃�涓插苟寰楀嚭缁撴灉
        for( i=0; i<5; i++) {
            printf("%02x", digest[i]);
        }
        printf("
    ");
    }
    /* POINTER defines a generic pointer type */
    typedef unsigned char * POINTER;
     
    /* UINT2 defines a two byte word */
    //typedef unsigned short int UINT2;
     
    /* UINT4 defines a four byte word */
    typedef unsigned long int UINT4;
     
     
    /* MD5 context. */
    typedef struct {
        UINT4 state[4];                                   /* state (ABCD) */
        UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
        unsigned char buffer[64];                         /* input buffer */
    } MD5_CTX;
     
    void MD5Init (MD5_CTX *context);
    void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen);
    void MD5UpdaterString(MD5_CTX *context,const char *string);
    int MD5FileUpdateFile (MD5_CTX *context,char *filename);
    void MD5Final (unsigned char digest[16], MD5_CTX *context);
    void MDMemory (char *pdata,unsigned char digest[16],unsigned int len);
    void MDString (char *string,unsigned char digest[16]);
    int MD5File (char *filename,unsigned char digest[16]);
    // make file
    fwPacket : main.c
        gcc md5c.c main.c -o fwPacket
    
        cp fwPacket ../../tools/packet_tool/
        cp packet.conf ../../tools/packet_tool/
        chmod +x ../../tools/packet_tool/fwPacket
    
    clean : 
        rm -f fwPacket
    // packet.conf 配置文件
    KERNEL,0.0.8,sky39ev300.bin
    #ISPCFG,1.0.0,ispcfg
    APPINI,1.0.0,anyka_cfg.ini
    #add before this
    MCU,1.0.23,ak_stm8.bin

    #include
    <stdio.h> #include <string.h> #include <stdint.h> #include <malloc.h> #include <sys/stat.h> #include "time.h" #include "md5c.h" #include "ak_update_packet_pro.h" #define UPDATE_BAG_SIZE_MAX (10*1024*1024) #define UPDATE_CFG_INFO_LEN 256 static char out_file_version[UPDATE_VERSION_LEN]; static char cfg_file_temp[UPDATE_FILE_NUM_MAX][UPDATE_CFG_INFO_LEN]; // input file infomation temp static char in_file_name[UPDATE_FILE_NUM_MAX][UPDATE_VERSION_LEN]; static char in_file_version[UPDATE_FILE_NUM_MAX][UPDATE_VERSION_LEN]; static char in_file_patch[UPDATE_FILE_NUM_MAX][UPDATE_VERSION_LEN]; static update_file_t *pout_buf; int get_local_time(struct ak_date* date) { time_t now; struct tm *t; time(&now); t = localtime(&now); date->year = t->tm_year+1900; date->month = t->tm_mon+1; date->day = t->tm_mday; date->hour = t->tm_hour; date->minute = t->tm_min; date->second = t->tm_sec; } int read_cfg_file(const char *file_name) { FILE *file_cfg; file_cfg = fopen(file_name, "r"); if(NULL == file_cfg) { printf("open config file error "); return -1; } int i = 0; while (!feof(file_cfg)) { memset(cfg_file_temp[i],0,UPDATE_CFG_INFO_LEN); // get one line fgets(cfg_file_temp[i],UPDATE_CFG_INFO_LEN,file_cfg); // filter '#' ' ', '' if('#' != cfg_file_temp[i][0] && ' ' != cfg_file_temp[i][0] && ' ' != cfg_file_temp[i][0] && '' != cfg_file_temp[i][0]) { // delete ' ' int str_len = strlen(cfg_file_temp[i]); if(cfg_file_temp[i][str_len-1] == ' ') { cfg_file_temp[i][str_len-1] = ''; str_len--; } if(cfg_file_temp[i][str_len-1] == ' ') { cfg_file_temp[i][str_len-1] = ''; } printf("%s ", cfg_file_temp[i]); i++; } if(i >= UPDATE_FILE_NUM_MAX) { printf("file is too many,max=%d ",UPDATE_FILE_NUM_MAX); break; } } if(i == 0) { printf("no any file need to update "); fclose(file_cfg); return -1; } fclose(file_cfg); return i; } int get_cfg_info(int file_num) { int i = 0; char *p = NULL; char info_temp[UPDATE_CFG_INFO_LEN]; memset(in_file_name,0,sizeof(in_file_name)); memset(in_file_version,0,sizeof(in_file_version)); memset(in_file_patch,0,sizeof(in_file_patch)); for(i = 0; i < file_num; i++) { memcpy(info_temp,cfg_file_temp[i],UPDATE_CFG_INFO_LEN); //printf("info_temp: %s ",info_temp); p=strtok(info_temp,","); printf("strtok file info, name: %s ",p); if(NULL != p) strcpy(in_file_name[i],p); else return -1; p=strtok(NULL,","); printf("version: %s ",p); if(NULL != p) strcpy(in_file_version[i],p); else return -1; p=strtok(NULL,","); printf("patch: %s ",p); if(NULL != p) strcpy(in_file_patch[i],p); else return -1; } return 0; } int packet_update_bag(int file_num) { int ret = 0; int i = 0; FILE *file_in; FILE *file_out; #define PATCH_LEN_MAX 256 char out_file_patch[PATCH_LEN_MAX]; char patch[PATCH_LEN_MAX]; update_sub_file_info_t *file_info; static unsigned int addr_offset = 0; // clean buffer pout_buf = malloc(UPDATE_BAG_SIZE_MAX); memset(pout_buf,0,UPDATE_BAG_SIZE_MAX); memset(patch,0,sizeof(patch)); // fill main file magic/version/date/file num. memcpy(pout_buf->magic,"anyka update",strlen("anyka update")); memcpy(pout_buf->version,out_file_version,strlen(out_file_version)); get_local_time(&pout_buf->date); pout_buf->file_num = file_num; // get out file patch with date,version and prefix. sprintf(patch, "sky39ev300_%s_%.4d%.2d%.2d_%.2d%.2d%.2d.bin",pout_buf->version, (pout_buf->date.year), (pout_buf->date.month), pout_buf->date.day, pout_buf->date.hour, pout_buf->date.minute, pout_buf->date.second); printf("out file patch: %s ",patch); file_out = fopen(patch,"w+"); memcpy(out_file_patch,patch,PATCH_LEN_MAX); for(i = 0; i < pout_buf->file_num; i++) { if(strlen(in_file_patch[i]) != 0) { // fill file name/version/addr offset. file_info = &(pout_buf->psub_file_info[i]); memcpy(file_info->name,in_file_name[i],strlen(in_file_name[i])); memcpy(file_info->version,in_file_version[i],strlen(in_file_version[i])); file_info->addr= addr_offset; // open file in memset(patch,0,sizeof(patch)); memcpy(patch,"srcfile/",sizeof("srcfile/")); strcat(patch,in_file_patch[i]); //memcpy(patch,in_file_patch[i],strlen(in_file_patch[i])); printf("in file%d patch: %s, ",i,patch); struct stat file_sta; memset(&file_sta,0,sizeof(file_sta)); stat(patch,&file_sta); int file_len = file_sta.st_size; printf("len=%d addr_offset=%d ",file_len,addr_offset); file_in = fopen(patch, "r+"); if(NULL == file_in) { printf("33[1;31m""open file %s fail! ""33[m",patch); ret = -1; break; } // read file into dynamic array fread(&pout_buf->data[addr_offset],file_len,1,file_in); fclose(file_in); //printf("read file ok "); #if 0 int j = 0; printf("file detail:"); for(j = 0; j < 16; j++) { printf("%x",*(pout_buf->pdata+addr_offset)); } printf(" "); #endif // fill sub file length addr_offset += file_len; file_info->len= file_len; if(addr_offset >= UPDATE_BAG_SIZE_MAX) { printf("bag size bigger than %d,exit ",UPDATE_BAG_SIZE_MAX); ret = -1; break; } } } if(!ret) { // fill total lenght and check sum pout_buf->data_len = addr_offset; unsigned int total_len = (char *)&pout_buf->data-(char *)&pout_buf->magic[0]+ addr_offset; unsigned int check_len = (char *)&pout_buf->data-(char *)&pout_buf->version[0] + addr_offset; printf("check sum addr_offset=%d total len=%d ",addr_offset,check_len); MDMemory(pout_buf->version,pout_buf->md5_check,check_len); //md5sum_buffer_hex(pout_buf->version, len, pout_buf->md5_check, sizeof(pout_buf->md5_check)); fwrite(pout_buf,total_len,1,file_out); } fclose(file_out); free(pout_buf); if(!ret){ printf("33[1;32m""packet update bag ok, %s ""33[m",out_file_patch); } else{ remove(out_file_patch); printf("33[1;31m""packet update bag fail ""33[m"); } return ret; } int main(int argc, char** argv) { int i; int ret; FILE *file_in1; FILE *file_in2; FILE *file_out; #if 0 for(i=0; i<argc; i++) { printf("%s ", argv[i]); } #endif if(argc <= 2) { if(1 == argc) { memcpy(out_file_version,"0.x.x",sizeof("0.x.x")); } else { memcpy(out_file_version,argv[1],strlen(argv[1])+1); printf("version: %s ",out_file_version); } } else { printf("33[1;31m""input para error,exit! ""33[m"); printf("./fwPacket <version>\n"); return -1; } // read config file printf("read config file: "); int file_num = read_cfg_file("packet.conf"); if(file_num < 0) { printf("33[1;31m""read config file error,exit! ""33[m"); return -1; } else { printf("read config file num=%d ",file_num); } // get info to temp if(get_cfg_info(file_num)) { printf("33[1;31m""get config file info error, exit! ""33[m"); return -1; } // biuld update bag packet_update_bag(file_num); }
  • 相关阅读:
    复利计算-做汉堡,结对2.0
    复利计算-结对
    《构建之法》第四章读后感
    复利计算单元测试
    实验一 命令解释程序的编写
    《构建之法》前三章章读后感
    1.0 2.0 3.0复利计算器
    实验0:了解和熟悉操作系统
    学习进度条
    0302思考并回答一些问题
  • 原文地址:https://www.cnblogs.com/mic-chen/p/9925470.html
Copyright © 2020-2023  润新知