mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 15:14:43 +00:00
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>
This commit is contained in:
parent
58c5376ba6
commit
89cdab788f
7 changed files with 32 additions and 21 deletions
2
Makefile
2
Makefile
|
@ -2992,7 +2992,7 @@ clobber: clean
|
|||
$(obj)cscope.* $(obj)*.*~
|
||||
@rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
|
||||
@rm -f $(obj)tools/{crc32.c,environment.c,env/crc32.c,md5.c,sha1.c,inca-swap-bytes}
|
||||
@rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c}
|
||||
@rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c,zlib.h}
|
||||
@rm -f $(obj)tools/{fdt_wip.c,libfdt_internal.h}
|
||||
@rm -f $(obj)cpu/mpc824x/bedbug_603e.c
|
||||
@rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
|
||||
|
|
|
@ -155,7 +155,7 @@ static table_entry_t uimage_comp[] = {
|
|||
{ -1, "", "", },
|
||||
};
|
||||
|
||||
unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
|
||||
uint32_t crc32 (uint32_t, const unsigned char *, uint);
|
||||
static void genimg_print_size (uint32_t size);
|
||||
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
|
||||
static void genimg_print_time (time_t timestamp);
|
||||
|
|
|
@ -604,8 +604,8 @@ int sprintf(char * buf, const char *fmt, ...);
|
|||
int vsprintf(char *buf, const char *fmt, va_list args);
|
||||
|
||||
/* lib_generic/crc32.c */
|
||||
ulong crc32 (ulong, const unsigned char *, uint);
|
||||
ulong crc32_no_comp (ulong, const unsigned char *, uint);
|
||||
uint32_t crc32 (uint32_t, const unsigned char *, uint);
|
||||
uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
|
||||
|
||||
/* common/console.c */
|
||||
int console_init_f(void); /* Before relocation; uses the serial stuff */
|
||||
|
|
|
@ -84,18 +84,23 @@
|
|||
# endif
|
||||
#endif /* CFG_ENV_IS_IN_NAND */
|
||||
|
||||
#ifdef USE_HOSTCC
|
||||
# include <stdint.h>
|
||||
#else
|
||||
# include <linux/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef CFG_REDUNDAND_ENVIRONMENT
|
||||
# define ENV_HEADER_SIZE (sizeof(unsigned long) + 1)
|
||||
# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
|
||||
#else
|
||||
# define ENV_HEADER_SIZE (sizeof(unsigned long))
|
||||
# define ENV_HEADER_SIZE (sizeof(uint32_t))
|
||||
#endif
|
||||
|
||||
|
||||
#define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
|
||||
|
||||
typedef struct environment_s {
|
||||
unsigned long crc; /* CRC32 over data bytes */
|
||||
uint32_t crc; /* CRC32 over data bytes */
|
||||
#ifdef CFG_REDUNDAND_ENVIRONMENT
|
||||
unsigned char flags; /* active/obsolete flags */
|
||||
#endif
|
||||
|
|
|
@ -10,18 +10,19 @@
|
|||
|
||||
#ifndef USE_HOSTCC /* Shut down "ANSI does not permit..." warnings */
|
||||
#include <common.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "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,7 +51,7 @@ 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 */
|
||||
/* terms of polynomial defining this crc (except x^32): */
|
||||
|
@ -74,7 +75,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 +135,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,8 +151,8 @@ const uLongf * ZEXPORT get_crc_table()
|
|||
#define DO8(buf) DO4(buf); DO4(buf);
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT crc32(crc, buf, len)
|
||||
uLong crc;
|
||||
uint32_t ZEXPORT crc32(crc, buf, len)
|
||||
uint32_t crc;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
|
@ -178,7 +179,7 @@ uLong ZEXPORT crc32(crc, buf, len)
|
|||
/* 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)
|
||||
|
|
|
@ -236,7 +236,11 @@ $(obj)environment.c:
|
|||
$(obj)environment.o: $(obj)environment.c
|
||||
$(CC) -g $(HOST_ENVIRO_CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||
|
||||
$(obj)crc32.c:
|
||||
$(obj)zlib.h:
|
||||
@rm -f $@
|
||||
ln -s $(src)../include/zlib.h $@
|
||||
|
||||
$(obj)crc32.c: $(obj)zlib.h
|
||||
@rm -f $(obj)crc32.c
|
||||
ln -s $(src)../lib_generic/crc32.c $(obj)crc32.c
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -58,15 +59,15 @@
|
|||
#endif /* CFG_ENV_IS_IN_FLASH */
|
||||
|
||||
#ifdef CFG_REDUNDAND_ENVIRONMENT
|
||||
# define ENV_HEADER_SIZE (sizeof(unsigned long) + 1)
|
||||
# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
|
||||
#else
|
||||
# define ENV_HEADER_SIZE (sizeof(unsigned long))
|
||||
# define ENV_HEADER_SIZE (sizeof(uint32_t))
|
||||
#endif
|
||||
|
||||
#define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
|
||||
|
||||
|
||||
extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
|
||||
extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int);
|
||||
|
||||
#ifdef ENV_IS_EMBEDDED
|
||||
extern unsigned int env_size;
|
||||
|
@ -76,7 +77,7 @@ extern unsigned char environment;
|
|||
int main (int argc, char **argv)
|
||||
{
|
||||
#ifdef ENV_IS_EMBEDDED
|
||||
int crc;
|
||||
uint32_t crc;
|
||||
unsigned char *envptr = &environment,
|
||||
*dataptr = envptr + ENV_HEADER_SIZE;
|
||||
unsigned int datasize = ENV_SIZE;
|
||||
|
|
Loading…
Reference in a new issue