Changeset 20437


Ignore:
Timestamp:
2010-03-26T11:12:30+01:00 (8 years ago)
Author:
florian
Message:

[tools] revert r18760 since it prevents people from building working eva images

File:
1 edited

Legend:

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

    r18760 r20437  
    2323#include <zlib.h> /* crc32 */ 
    2424 
    25  
    26 #define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0])) 
    27  
    2825#define checksum_add32(csum, data) \ 
    29   do { \ 
    30     csum += (((data) >> 0)  & 0x000000FF); \ 
    31     csum += (((data) >> 8)  & 0x000000FF); \ 
    32     csum += (((data) >> 16) & 0x000000FF); \ 
    33     csum += (((data) >> 24) & 0x000000FF); \ 
    34   } while (0) 
     26  csum += ((uint8_t *)&data)[0]; \ 
     27  csum += ((uint8_t *)&data)[1]; \ 
     28  csum += ((uint8_t *)&data)[2]; \ 
     29  csum += ((uint8_t *)&data)[3]; 
    3530 
    3631void 
     
    4843} 
    4944 
    50 /* Read an 8bit value */ 
    51 static int fread_8(uint8_t *buf, FILE *fd) 
    52 { 
    53   return (fread(buf, sizeof(*buf), 1, fd) == 1) ? 0 : -1; 
    54 } 
    55  
    56 /* Read a 32bit little endian value and convert to host endianness. */ 
    57 static int fread_le32(uint32_t *buf, FILE *fd) 
    58 { 
    59   size_t count; 
    60   uint8_t tmp[4]; 
    61   unsigned int i; 
    62  
    63   if (fread(tmp, sizeof(tmp), 1, fd) != 1) 
    64     return -1; 
    65   *buf = 0; 
    66   for (i = 0; i < ARRAY_SIZE(tmp); i++) 
    67     *buf |= (uint32_t)(tmp[i]) << (i * 8); 
    68  
    69   return 0; 
    70 } 
    71  
    72 /* Read a 64bit little endian value and convert to host endianness. */ 
    73 static int fread_le64(uint64_t *buf, FILE *fd) 
    74 { 
    75   size_t count; 
    76   uint8_t tmp[8]; 
    77   unsigned int i; 
    78  
    79   if (fread(tmp, sizeof(tmp), 1, fd) != 1) 
    80     return -1; 
    81   *buf = 0; 
    82   for (i = 0; i < ARRAY_SIZE(tmp); i++) 
    83     *buf |= (uint64_t)(tmp[i]) << (i * 8); 
    84  
    85   return 0; 
    86 } 
    87  
    88 /* Write an 8bit value */ 
    89 static int fwrite_8(uint8_t buf, FILE *fd) 
    90 { 
    91   return (fwrite(&buf, sizeof(buf), 1, fd) == 1) ? 0 : -1; 
    92 } 
    93  
    94 /* Convert to little endian and write a 32bit value */ 
    95 static int fwrite_le32(uint32_t buf, FILE *fd) 
    96 { 
    97   size_t count; 
    98   uint8_t tmp[4]; 
    99   unsigned int i; 
    100  
    101   for (i = 0; i < ARRAY_SIZE(tmp); i++) 
    102     tmp[i] = buf >> (i * 8); 
    103   if (fwrite(tmp, sizeof(tmp), 1, fd) != 1) 
    104     return -1; 
    105  
    106   return 0; 
    107 } 
    108  
    10945int 
    11046main(int argc, char *argv[]) 
    11147{ 
     48 
    11249  const char *infile, *outfile; 
    11350  FILE *in, *out; 
     
    13168  uint32_t datacrc32 = crc32(0, 0, 0); 
    13269 
     70  uint32_t zero = 0; 
    13371  uint32_t entry = 0; 
    13472 
     
    15088 
    15189  /* read LZMA header */ 
    152   if (fread_8(&properties, in)) 
     90  if (1 != fread(&properties, sizeof properties, 1, in)) 
    15391    pexit("fread"); 
    154   if (fread_le32(&dictsize, in)) 
     92  if (1 != fread(&dictsize, sizeof dictsize, 1, in)) 
    15593    pexit("fread"); 
    156   if (fread_le64(&datasize, in)) 
     94  if (1 != fread(&datasize, sizeof datasize, 1, in)) 
    15795    pexit("fread"); 
    15896 
    15997  /* write EVA header */ 
    160   if (fwrite_le32(magic, out)) 
     98  if (1 != fwrite(&magic, sizeof magic, 1, out)) 
    16199    pexit("fwrite"); 
    162100  if (fgetpos(out, &reclengthpos)) 
    163101    pexit("fgetpos"); 
    164   if (fwrite_le32(reclength, out)) 
     102  if (1 != fwrite(&reclength, sizeof reclength, 1, out)) 
    165103    pexit("fwrite"); 
    166   if (fwrite_le32(loadaddress, out)) 
     104  if (1 != fwrite(&loadaddress, sizeof loadaddress, 1, out)) 
    167105    pexit("fwrite"); 
    168   if (fwrite_le32(type, out)) 
     106  if (1 != fwrite(&type, sizeof type, 1, out)) 
    169107    pexit("fwrite"); 
    170108 
     
    172110  if (fgetpos(out, &compsizepos)) 
    173111    pexit("fgetpos"); 
    174   if (fwrite_le32(compsize, out)) 
     112  if (1 != fwrite(&compsize, sizeof compsize, 1, out)) 
    175113    pexit("fwrite"); 
    176114  /* XXX check length */ 
    177115  datasize32 = (uint32_t)datasize; 
    178   if (fwrite_le32(datasize32, out)) 
     116  if (1 != fwrite(&datasize32, sizeof datasize32, 1, out)) 
    179117    pexit("fwrite"); 
    180   if (fwrite_le32(datacrc32, out)) 
     118  if (1 != fwrite(&datacrc32, sizeof datacrc32, 1, out)) 
    181119    pexit("fwrite"); 
    182120 
    183121  /* write modified LZMA header */ 
    184   if (fwrite_8(properties, out)) 
     122  if (1 != fwrite(&properties, sizeof properties, 1, out)) 
    185123    pexit("fwrite"); 
    186   if (fwrite_le32(dictsize, out)) 
     124  if (1 != fwrite(&dictsize, sizeof dictsize, 1, out)) 
    187125    pexit("fwrite"); 
    188   if (fwrite_le32(0, out)) 
     126  if (1 != fwrite(&zero, 3, 1, out)) 
    189127    pexit("fwrite"); 
    190128 
     
    204142  if (fsetpos(out, &reclengthpos)) 
    205143    pexit("fsetpos"); 
    206   if (fwrite_le32(reclength, out)) 
     144  if (1 != fwrite(&reclength, sizeof reclength, 1, out)) 
    207145    pexit("fwrite"); 
    208146 
     
    210148  if (fsetpos(out, &compsizepos)) 
    211149    pexit("fsetpos"); 
    212   if (fwrite_le32(compsize, out)) 
     150  if (1 != fwrite(&compsize, sizeof compsize, 1, out)) 
    213151    pexit("fwrite"); 
    214   if (fwrite_le32(datasize32, out)) 
     152  if (1 != fwrite(&datasize32, sizeof datasize32, 1, out)) 
    215153    pexit("fwrite"); 
    216   if (fwrite_le32(datacrc32, out)) 
     154  if (1 != fwrite(&datacrc32, sizeof datacrc32, 1, out)) 
    217155    pexit("fwrite"); 
    218156 
     
    237175 
    238176  checksum = ~checksum + 1; 
    239   if (fwrite_le32(checksum, out)) 
     177  if (1 != fwrite(&checksum, sizeof checksum, 1, out)) 
    240178    pexit("fwrite"); 
    241179 
    242180  /* write entry record */ 
    243   if (fwrite_le32(0, out)) 
     181  if (1 != fwrite(&zero, sizeof zero, 1, out)) 
    244182    pexit("fwrite"); 
    245   if (fwrite_le32(entry, out)) 
     183  if (1 != fwrite(&entry, sizeof entry, 1, out)) 
    246184    pexit("fwrite"); 
    247185 
Note: See TracChangeset for help on using the changeset viewer.