colibri_imx6: fix video stdout in default environment
[oweals/u-boot.git] / lib / crc32.c
index 76205da4f3060028508d4f39974b673ea52c898a..e9be3bf386e7bc3c86847a73320a0747c5830b56 100644 (file)
@@ -8,8 +8,12 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-#ifndef USE_HOSTCC
+#ifdef USE_HOSTCC
+#include <arpa/inet.h>
+#include <u-boot/crc.h>
+#else
 #include <common.h>
+#include <efi_loader.h>
 #endif
 #include <compiler.h>
 #include <u-boot/crc.h>
 #endif
 #include "u-boot/zlib.h"
 
-#define local static
-#define ZEXPORT        /* empty */
+#ifdef USE_HOSTCC
+#define __efi_runtime
+#define __efi_runtime_data
+#endif
 
 #define tole(x) cpu_to_le32(x)
 
-#ifdef DYNAMIC_CRC_TABLE
+#ifdef CONFIG_DYNAMIC_CRC_TABLE
 
-local int crc_table_empty = 1;
-local uint32_t crc_table[256];
-local void make_crc_table OF((void));
+static int __efi_runtime_data crc_table_empty = 1;
+static uint32_t __efi_runtime_data crc_table[256];
+static void __efi_runtime make_crc_table OF((void));
 
 /*
   Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
@@ -54,13 +60,14 @@ local void make_crc_table OF((void));
   the information needed to generate CRC's on data a byte at a time for all
   combinations of CRC register values and incoming bytes.
 */
-local void make_crc_table()
+static void __efi_runtime make_crc_table(void)
 {
   uint32_t c;
   int n, k;
   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};
+  static Byte __efi_runtime_data p[] = {
+               0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26};
 
   /* make exclusive-or pattern from polynomial (0xedb88320L) */
   poly = 0L;
@@ -81,7 +88,7 @@ local void make_crc_table()
  * Table of CRC-32's of all single-byte values (made by make_crc_table)
  */
 
-local const uint32_t crc_table[256] = {
+static const uint32_t __efi_runtime_data crc_table[256] = {
 tole(0x00000000L), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
 tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
 tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),
@@ -155,7 +162,7 @@ tole(0xb40bbe37L), tole(0xc30c8ea1L), tole(0x5a05df1bL), tole(0x2d02ef8dL)
  */
 const uint32_t * ZEXPORT get_crc_table()
 {
-#ifdef DYNAMIC_CRC_TABLE
+#ifdef CONFIG_DYNAMIC_CRC_TABLE
   if (crc_table_empty) make_crc_table();
 #endif
   return (const uint32_t *)crc_table;
@@ -174,12 +181,12 @@ const uint32_t * ZEXPORT get_crc_table()
 /* No ones complement version. JFFS2 (and other things ?)
  * don't use ones compliment in their CRC calculations.
  */
-uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
+uint32_t __efi_runtime crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 {
     const uint32_t *tab = crc_table;
     const uint32_t *b =(const uint32_t *)buf;
     size_t rem_len;
-#ifdef DYNAMIC_CRC_TABLE
+#ifdef CONFIG_DYNAMIC_CRC_TABLE
     if (crc_table_empty)
       make_crc_table();
 #endif
@@ -216,7 +223,7 @@ uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 }
 #undef DO_CRC
 
-uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *p, uInt len)
+uint32_t __efi_runtime crc32(uint32_t crc, const Bytef *p, uInt len)
 {
      return crc32_no_comp(crc ^ 0xffffffffL, p, len) ^ 0xffffffffL;
 }
@@ -225,9 +232,8 @@ uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *p, uInt len)
  * 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)
+uint32_t 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;
@@ -239,12 +245,12 @@ uint32_t ZEXPORT crc32_wd (uint32_t crc,
                chunk = end - curr;
                if (chunk > chunk_sz)
                        chunk = chunk_sz;
-               crc = crc32 (crc, curr, chunk);
+               crc = crc32(crc, curr, chunk);
                curr += chunk;
                WATCHDOG_RESET ();
        }
 #else
-       crc = crc32 (crc, buf, len);
+       crc = crc32(crc, buf, len);
 #endif
 
        return crc;
@@ -256,5 +262,6 @@ void crc32_wd_buf(const unsigned char *input, unsigned int ilen,
        uint32_t crc;
 
        crc = crc32_wd(0, input, ilen, chunk_sz);
+       crc = htonl(crc);
        memcpy(output, &crc, sizeof(crc));
 }