lib_generic/crc32.c: fix compile problem
[oweals/u-boot.git] / lib_generic / crc32.c
index b882daa10d62c2fc5168b1a9935228a61b10901c..32e72f999ae0eacb1a66d21957141e0a6d23e9fd 100644 (file)
@@ -151,10 +151,7 @@ const uint32_t * ZEXPORT get_crc_table()
 #define DO8(buf)  DO4(buf); DO4(buf);
 
 /* ========================================================================= */
-uint32_t ZEXPORT crc32(crc, buf, len)
-    uint32_t 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)
@@ -198,3 +195,32 @@ uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 }
 
 #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;
+}