X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib_generic%2Fcrc32.c;h=b27048ceebf2f07075457aedc5f1b0a3cb6db381;hb=bcb324d68f7955c1136dafc944eb55db8ebaa601;hp=3db224a3649981bec3b5705014ed5467bd51c26f;hpb=34a7ceeff449be015a37d0e3f3178ca313618349;p=oweals%2Fu-boot.git diff --git a/lib_generic/crc32.c b/lib_generic/crc32.c index 3db224a364..b27048ceeb 100644 --- a/lib_generic/crc32.c +++ b/lib_generic/crc32.c @@ -9,19 +9,23 @@ */ #ifndef USE_HOSTCC /* Shut down "ANSI does not permit..." warnings */ -#include /* to get command definitions like CFG_CMD_JFFS2 */ +#include +#else +#include #endif -#include "zlib.h" +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) +#include +#endif +#include "u-boot/zlib.h" #define local static #define ZEXPORT /* empty */ -unsigned long crc32 (unsigned long, const unsigned char *, unsigned int); #ifdef DYNAMIC_CRC_TABLE local int crc_table_empty = 1; -local uLongf crc_table[256]; +local uint32_t crc_table[256]; local void make_crc_table OF((void)); /* @@ -50,9 +54,9 @@ local void make_crc_table OF((void)); */ local void make_crc_table() { - uLong c; + uint32_t c; int n, k; - uLong poly; /* polynomial exclusive-or pattern */ + uLong poly; /* polynomial exclusive-or pattern */ /* terms of polynomial defining this crc (except x^32): */ static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; @@ -74,7 +78,7 @@ local void make_crc_table() /* ======================================================================== * Table of CRC-32's of all single-byte values (made by make_crc_table) */ -local const uLongf crc_table[256] = { +local const uint32_t crc_table[256] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, @@ -134,12 +138,12 @@ local const uLongf crc_table[256] = { /* ========================================================================= * This function can be used by asm versions of crc32() */ -const uLongf * ZEXPORT get_crc_table() +const uint32_t * ZEXPORT get_crc_table() { #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) make_crc_table(); #endif - return (const uLongf *)crc_table; + return (const uint32_t *)crc_table; } #endif @@ -150,10 +154,7 @@ const uLongf * ZEXPORT get_crc_table() #define DO8(buf) DO4(buf); DO4(buf); /* ========================================================================= */ -uLong ZEXPORT crc32(crc, buf, len) - uLong crc; - const Bytef *buf; - uInt len; +uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *buf, uInt len) { #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) @@ -171,13 +172,12 @@ uLong ZEXPORT crc32(crc, buf, len) return crc ^ 0xffffffffL; } -#if ((CONFIG_COMMANDS & CFG_CMD_JFFS2) || (CONFIG_COMMANDS & CFG_CMD_NAND)) \ - && !defined(CFG_NAND_LEGACY) +#if defined(CONFIG_CMD_JFFS2) || defined(CONFIG_CMD_NAND) /* No ones complement version. JFFS2 (and other things ?) * don't use ones compliment in their CRC calculations. */ -uLong ZEXPORT crc32_no_comp(uLong crc, const Bytef *buf, uInt len) +uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len) { #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) @@ -195,4 +195,33 @@ uLong ZEXPORT crc32_no_comp(uLong crc, const Bytef *buf, uInt len) return crc; } -#endif /* CFG_CMD_JFFS2 */ +#endif + +/* + * Calculate the crc32 checksum triggering the watchdog every 'chunk_sz' bytes + * of input. + */ +uint32_t ZEXPORT crc32_wd (uint32_t crc, + const unsigned char *buf, + uInt len, uInt chunk_sz) +{ +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + const unsigned char *end, *curr; + int chunk; + + curr = buf; + end = buf + len; + while (curr < end) { + chunk = end - curr; + if (chunk > chunk_sz) + chunk = chunk_sz; + crc = crc32 (crc, curr, chunk); + curr += chunk; + WATCHDOG_RESET (); + } +#else + crc = crc32 (crc, buf, len); +#endif + + return crc; +}