Commit 89cdab788f3716b335fefb60b836ebcf975aceab

Authored by Mike Frysinger
Committed by Wolfgang Denk
1 parent 58c5376ba6

crc32: use uint32_t rather than unsigned long

The envcrc.c does sizeof(unsigned long) when calculating the crc, but
this is done with the build toolchain instead of the target tool
chain, so if the build is a 64bit system but the target is 32bits,
the size will obviously be wrong. This converts all unsigned long
stuff related to crc32 to uint32_t types. Compile tested only: output
of ./tools/envcrc when run on a 32bit build system matches that of a
64bit build system.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Showing 7 changed files with 32 additions and 21 deletions Side-by-side Diff

... ... @@ -2992,7 +2992,7 @@
2992 2992 $(obj)cscope.* $(obj)*.*~
2993 2993 @rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
2994 2994 @rm -f $(obj)tools/{crc32.c,environment.c,env/crc32.c,md5.c,sha1.c,inca-swap-bytes}
2995   - @rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c}
  2995 + @rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c,zlib.h}
2996 2996 @rm -f $(obj)tools/{fdt_wip.c,libfdt_internal.h}
2997 2997 @rm -f $(obj)cpu/mpc824x/bedbug_603e.c
2998 2998 @rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
... ... @@ -155,7 +155,7 @@
155 155 { -1, "", "", },
156 156 };
157 157  
158   -unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
  158 +uint32_t crc32 (uint32_t, const unsigned char *, uint);
159 159 static void genimg_print_size (uint32_t size);
160 160 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
161 161 static void genimg_print_time (time_t timestamp);
... ... @@ -604,8 +604,8 @@
604 604 int vsprintf(char *buf, const char *fmt, va_list args);
605 605  
606 606 /* lib_generic/crc32.c */
607   -ulong crc32 (ulong, const unsigned char *, uint);
608   -ulong crc32_no_comp (ulong, const unsigned char *, uint);
  607 +uint32_t crc32 (uint32_t, const unsigned char *, uint);
  608 +uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
609 609  
610 610 /* common/console.c */
611 611 int console_init_f(void); /* Before relocation; uses the serial stuff */
include/environment.h
... ... @@ -84,18 +84,23 @@
84 84 # endif
85 85 #endif /* CFG_ENV_IS_IN_NAND */
86 86  
  87 +#ifdef USE_HOSTCC
  88 +# include <stdint.h>
  89 +#else
  90 +# include <linux/types.h>
  91 +#endif
87 92  
88 93 #ifdef CFG_REDUNDAND_ENVIRONMENT
89   -# define ENV_HEADER_SIZE (sizeof(unsigned long) + 1)
  94 +# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
90 95 #else
91   -# define ENV_HEADER_SIZE (sizeof(unsigned long))
  96 +# define ENV_HEADER_SIZE (sizeof(uint32_t))
92 97 #endif
93 98  
94 99  
95 100 #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
96 101  
97 102 typedef struct environment_s {
98   - unsigned long crc; /* CRC32 over data bytes */
  103 + uint32_t crc; /* CRC32 over data bytes */
99 104 #ifdef CFG_REDUNDAND_ENVIRONMENT
100 105 unsigned char flags; /* active/obsolete flags */
101 106 #endif
... ... @@ -10,18 +10,19 @@
10 10  
11 11 #ifndef USE_HOSTCC /* Shut down "ANSI does not permit..." warnings */
12 12 #include <common.h>
  13 +#else
  14 +#include <stdint.h>
13 15 #endif
14 16  
15 17 #include "zlib.h"
16 18  
17 19 #define local static
18 20 #define ZEXPORT /* empty */
19   -unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
20 21  
21 22 #ifdef DYNAMIC_CRC_TABLE
22 23  
23 24 local int crc_table_empty = 1;
24   -local uLongf crc_table[256];
  25 +local uint32_t crc_table[256];
25 26 local void make_crc_table OF((void));
26 27  
27 28 /*
... ... @@ -50,7 +51,7 @@
50 51 */
51 52 local void make_crc_table()
52 53 {
53   - uLong c;
  54 + uint32_t c;
54 55 int n, k;
55 56 uLong poly; /* polynomial exclusive-or pattern */
56 57 /* terms of polynomial defining this crc (except x^32): */
... ... @@ -74,7 +75,7 @@
74 75 /* ========================================================================
75 76 * Table of CRC-32's of all single-byte values (made by make_crc_table)
76 77 */
77   -local const uLongf crc_table[256] = {
  78 +local const uint32_t crc_table[256] = {
78 79 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
79 80 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
80 81 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
81 82  
... ... @@ -134,12 +135,12 @@
134 135 /* =========================================================================
135 136 * This function can be used by asm versions of crc32()
136 137 */
137   -const uLongf * ZEXPORT get_crc_table()
  138 +const uint32_t * ZEXPORT get_crc_table()
138 139 {
139 140 #ifdef DYNAMIC_CRC_TABLE
140 141 if (crc_table_empty) make_crc_table();
141 142 #endif
142   - return (const uLongf *)crc_table;
  143 + return (const uint32_t *)crc_table;
143 144 }
144 145 #endif
145 146  
... ... @@ -150,8 +151,8 @@
150 151 #define DO8(buf) DO4(buf); DO4(buf);
151 152  
152 153 /* ========================================================================= */
153   -uLong ZEXPORT crc32(crc, buf, len)
154   - uLong crc;
  154 +uint32_t ZEXPORT crc32(crc, buf, len)
  155 + uint32_t crc;
155 156 const Bytef *buf;
156 157 uInt len;
157 158 {
... ... @@ -178,7 +179,7 @@
178 179 /* No ones complement version. JFFS2 (and other things ?)
179 180 * don't use ones compliment in their CRC calculations.
180 181 */
181   -uLong ZEXPORT crc32_no_comp(uLong crc, const Bytef *buf, uInt len)
  182 +uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
182 183 {
183 184 #ifdef DYNAMIC_CRC_TABLE
184 185 if (crc_table_empty)
... ... @@ -236,7 +236,11 @@
236 236 $(obj)environment.o: $(obj)environment.c
237 237 $(CC) -g $(HOST_ENVIRO_CFLAGS) $(CPPFLAGS) -c -o $@ $<
238 238  
239   -$(obj)crc32.c:
  239 +$(obj)zlib.h:
  240 + @rm -f $@
  241 + ln -s $(src)../include/zlib.h $@
  242 +
  243 +$(obj)crc32.c: $(obj)zlib.h
240 244 @rm -f $(obj)crc32.c
241 245 ln -s $(src)../lib_generic/crc32.c $(obj)crc32.c
242 246  
... ... @@ -22,6 +22,7 @@
22 22 */
23 23  
24 24 #include <stdio.h>
  25 +#include <stdint.h>
25 26 #include <stdlib.h>
26 27 #include <unistd.h>
27 28  
28 29  
29 30  
... ... @@ -58,15 +59,15 @@
58 59 #endif /* CFG_ENV_IS_IN_FLASH */
59 60  
60 61 #ifdef CFG_REDUNDAND_ENVIRONMENT
61   -# define ENV_HEADER_SIZE (sizeof(unsigned long) + 1)
  62 +# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
62 63 #else
63   -# define ENV_HEADER_SIZE (sizeof(unsigned long))
  64 +# define ENV_HEADER_SIZE (sizeof(uint32_t))
64 65 #endif
65 66  
66 67 #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
67 68  
68 69  
69   -extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
  70 +extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int);
70 71  
71 72 #ifdef ENV_IS_EMBEDDED
72 73 extern unsigned int env_size;
... ... @@ -76,7 +77,7 @@
76 77 int main (int argc, char **argv)
77 78 {
78 79 #ifdef ENV_IS_EMBEDDED
79   - int crc;
  80 + uint32_t crc;
80 81 unsigned char *envptr = &environment,
81 82 *dataptr = envptr + ENV_HEADER_SIZE;
82 83 unsigned int datasize = ENV_SIZE;