X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fcrc32.c;h=eee21f8d73988e6eb015a680af0dae37eec022da;hb=9ab0bdd9fe13d311269ddda60191cbc37136f998;hp=76205da4f3060028508d4f39974b673ea52c898a;hpb=412665b46134f93464c09405e02f08ac9c62526d;p=oweals%2Fu-boot.git diff --git a/lib/crc32.c b/lib/crc32.c index 76205da4f3..eee21f8d73 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -8,8 +8,11 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#ifndef USE_HOSTCC +#ifdef USE_HOSTCC +#include +#else #include +#include #endif #include #include @@ -19,16 +22,18 @@ #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 +59,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 +87,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 +161,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 +180,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 +222,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 +231,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; @@ -256,5 +261,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)); }