Changeset 22414


Ignore:
Timestamp:
2010-07-29T20:14:10+02:00 (8 years ago)
Author:
mb
Message:

firmware-utils/trx: Endianness fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/firmware-utils/src/trx.c

    r22398 r22414  
    5454#if __BYTE_ORDER == __BIG_ENDIAN 
    5555#define STORE32_LE(X)           bswap_32(X) 
     56#define LOAD32_LE(X)            bswap_32(X) 
    5657#elif __BYTE_ORDER == __LITTLE_ENDIAN 
    5758#define STORE32_LE(X)           (X) 
     59#define LOAD32_LE(X)            (X) 
    5860#else 
    5961#error unkown endianness! 
     
    263265        /* for TRXv2 set bin-header Flags to 0xFF for CRC calculation like CFE does */  
    264266        if (trx_version == 2) { 
    265                 if(cur_len - p->offsets[3] < sizeof(binheader)) { 
     267                if(cur_len - LOAD32_LE(p->offsets[3]) < sizeof(binheader)) { 
    266268                        fprintf(stderr, "TRXv2 binheader too small!\n"); 
    267269                        return EXIT_FAILURE; 
    268270                } 
    269                 memcpy(binheader, buf + p->offsets[3], sizeof(binheader)); /* save header */ 
    270                 memset(buf + p->offsets[3] + 22, 0xFF, 8); /* set stable and try1-3 to 0xFF */ 
     271                memcpy(binheader, buf + LOAD32_LE(p->offsets[3]), sizeof(binheader)); /* save header */ 
     272                memset(buf + LOAD32_LE(p->offsets[3]) + 22, 0xFF, 8); /* set stable and try1-3 to 0xFF */ 
    271273        } 
    272274 
     
    276278 
    277279        p->len = (fsmark)?fsmark:cur_len - offsetof(struct trx_header, flag_version); 
     280        p->len = STORE32_LE(p->len); 
    278281 
    279282        /* restore TRXv2 bin-header */ 
    280283        if (trx_version == 2) { 
    281                 memcpy(buf + p->offsets[3], binheader, sizeof(binheader)); 
     284                memcpy(buf + LOAD32_LE(p->offsets[3]), binheader, sizeof(binheader)); 
    282285        } 
    283286 
Note: See TracChangeset for help on using the changeset viewer.