Changeset 26543


Ignore:
Timestamp:
2011-04-09T17:06:01+02:00 (7 years ago)
Author:
hauke
Message:

firmware-utils: fix endianness bugs in firmware generation program.

Should make it work on big endian systems again, I do not have such a system.

This closes #9093.

File:
1 edited

Legend:

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

    r25472 r26543  
    66#include <errno.h> 
    77#include <unistd.h> 
     8 
     9#if __BYTE_ORDER == __BIG_ENDIAN 
     10#define STORE32_LE(X)           bswap_32(X) 
     11#define LOAD32_LE(X)            bswap_32(X) 
     12#elif __BYTE_ORDER == __LITTLE_ENDIAN 
     13#define STORE32_LE(X)           (X) 
     14#define LOAD32_LE(X)            (X) 
     15#else 
     16#error unkown endianness! 
     17#endif 
     18 
    819/**********************************************************************/ 
    920/* from trxhdr.h */ 
     
    2233}; 
    2334 
     35 
     36struct edimax_header { 
     37        uint32_t sign;                  /* signature for header */ 
     38        uint32_t length;                /* start address but doesn't seems to be used... */ 
     39        uint32_t start_addr;            /* length of data, not used too ...*/ 
     40}; 
    2441 
    2542 
     
    94111        FILE *fpIn = NULL; 
    95112        FILE *fpOut = NULL; 
    96         long  nImgSize; 
    97         uint32_t sign = EDIMAX_PS16;            /* signature for header */ 
    98         uint32_t start_addr = 0x80500000;       /* start address but doesn't seems to be used... */ 
    99         uint32_t length;                        /* length of data, not used too ...*/ 
     113        struct edimax_header eh; 
    100114        size_t res; 
     115        int length; 
    101116 
    102117        char *buf; 
    103118        struct trx_header *p; 
    104  
    105119 
    106120        if (argc != 3) { 
     
    129143 
    130144        p = (struct trx_header *)buf; 
    131         if (p->magic != TRX_MAGIC) { 
    132                 fprintf(stderr, "Not a trx file...%x\n", p->magic); 
     145        if (LOAD32_LE(p->magic) != TRX_MAGIC) { 
     146                fprintf(stderr, "Not a trx file...%x\n", LOAD32_LE(p->magic)); 
    133147                return EXIT_FAILURE; 
    134148        } 
     
    142156        } 
    143157        /* make the 3 partition beeing 12 bytes closer from the header */ 
    144         memcpy(buf + p->offsets[2] - EDIMAX_HDR_LEN, buf + p->offsets[2], length - p->offsets[2]); 
     158        memcpy(buf + LOAD32_LE(p->offsets[2]) - EDIMAX_HDR_LEN, buf + LOAD32_LE(p->offsets[2]), length - LOAD32_LE(p->offsets[2])); 
    145159        /* recompute the crc32 check */ 
    146         p->crc32 = crc32buf((char *) &p->flag_version, length - offsetof(struct trx_header, flag_version)); 
     160        p->crc32 = STORE32_LE(crc32buf((char *) &(LOAD32_LE(p->flag_version)), length - offsetof(struct trx_header, flag_version))); 
     161 
     162        eh.sign = STORE32_LE(EDIMAX_PS16); 
     163        eh.length = STORE32_LE(length); 
     164        eh.start_addr = STORE32_LE(0x80500000); 
     165 
    147166        /* write the modified file */ 
    148         fwrite(&sign,  sizeof(uint32_t), 1, fpOut); 
    149         fwrite(&length, sizeof(uint32_t), 1, fpOut); 
    150         fwrite(&start_addr, sizeof(uint32_t), 1, fpOut); 
     167        fwrite(&eh, sizeof(struct edimax_header), 1, fpOut); 
    151168        fwrite(buf, sizeof(char), length, fpOut); 
    152169        fclose(fpOut); 
Note: See TracChangeset for help on using the changeset viewer.