Changeset 20523


Ignore:
Timestamp:
2010-03-27T18:38:30+01:00 (8 years ago)
Author:
juhosg
Message:

package/mtd: reuse existing crc32 stuff in the trx code

  • patch by Bernhard Loos
  • note: fixed compiler error on brcm47xx
Location:
trunk/package/mtd/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/mtd/src/crc32.h

    r8444 r20523  
    88/* Return a 32-bit CRC of the contents of the buffer. */ 
    99 
    10         static inline uint32_t 
     10static inline uint32_t 
    1111crc32(uint32_t val, const void *ss, int len) 
    1212{ 
     
    1717} 
    1818 
     19static inline unsigned int crc32buf(char *buf, size_t len) 
     20{ 
     21        return crc32(0xFFFFFFFF, buf, len); 
     22} 
     23 
     24 
     25 
    1926#endif 
  • trunk/package/mtd/src/trx.c

    r12655 r20523  
    3232#include "mtd-api.h" 
    3333#include "mtd.h" 
     34#include "crc32.h" 
    3435 
    3536#define TRX_MAGIC       0x30524448      /* "HDR0" */ 
     
    4142        unsigned offsets[3];    /* Offsets of partitions from start of header */ 
    4243}; 
    43  
    44 static unsigned long *crc32 = NULL; 
    45  
    46 static void init_crc32() 
    47 { 
    48         unsigned long crc; 
    49         unsigned long poly = 0xEDB88320L; 
    50         int n, bit; 
    51  
    52         if (crc32) 
    53                 return; 
    54  
    55         crc32 = (unsigned long *) malloc(256 * sizeof(unsigned long)); 
    56         if (!crc32) { 
    57                 perror("malloc"); 
    58                 exit(1); 
    59         } 
    60  
    61         for (n = 0; n < 256; n++) { 
    62                 crc = (unsigned long) n; 
    63                 for (bit = 0; bit < 8; bit++) 
    64                         crc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1); 
    65                 crc32[n] = crc; 
    66         } 
    67 } 
    68  
    69 static unsigned int crc32buf(char *buf, size_t len) 
    70 { 
    71         unsigned int crc = 0xFFFFFFFF; 
    72         for (; len; len--, buf++) 
    73                 crc = crc32[(crc ^ *buf) & 0xff] ^ (crc >> 8); 
    74         return crc; 
    75 } 
    7644 
    7745int 
Note: See TracChangeset for help on using the changeset viewer.