From 96c4ac1bb791c889aa73b56c8ce4a9f2a8e58c8f Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Wed, 21 Oct 2015 22:03:35 +0200 Subject: [PATCH] Replace crc32 with tinf_crc32 everywhere. --- u-boot/common/cmd_bootm.c | 5 +++-- u-boot/common/env_common.c | 3 ++- u-boot/common/env_flash.c | 9 +++++---- u-boot/include/common.h | 6 ------ u-boot/lib_bootstrap/bootstrap_board.c | 3 ++- u-boot/tools/envcrc.c | 5 ++--- u-boot/tools/mkimage.c | 14 +++++--------- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/u-boot/common/cmd_bootm.c b/u-boot/common/cmd_bootm.c index d8fd262..3c11b59 100644 --- a/u-boot/common/cmd_bootm.c +++ b/u-boot/common/cmd_bootm.c @@ -31,6 +31,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -464,7 +465,7 @@ static int image_info(ulong addr){ checksum = ntohl(hdr->ih_hcrc); hdr->ih_hcrc = 0; - if(crc32(0, (uchar *)data, len) != checksum){ + if(tinf_crc32((uchar *)data, len) != checksum){ puts("## Error: bad header checksum!\n"); return 1; } @@ -477,7 +478,7 @@ static int image_info(ulong addr){ puts(" Verifying checksum... "); - if(crc32(0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)){ + if(tinf_crc32((uchar *)data, len) != ntohl(hdr->ih_dcrc)){ puts("bad data CRC!\n"); return(1); } diff --git a/u-boot/common/env_common.c b/u-boot/common/env_common.c index 155e4d0..f73fb32 100644 --- a/u-boot/common/env_common.c +++ b/u-boot/common/env_common.c @@ -29,6 +29,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -134,7 +135,7 @@ int default_environment_size = sizeof(default_environment); #endif void env_crc_update(void){ - env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE); + env_ptr->crc = tinf_crc32(env_ptr->data, ENV_SIZE); } static uchar env_get_char_init(int index){ diff --git a/u-boot/common/env_flash.c b/u-boot/common/env_flash.c index e49b600..1398fbe 100644 --- a/u-boot/common/env_flash.c +++ b/u-boot/common/env_flash.c @@ -34,6 +34,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -99,8 +100,8 @@ int env_init(void){ ulong addr1 = (ulong)&(flash_addr->data); ulong addr2 = (ulong)&(flash_addr_new->data); - crc1_ok = (crc32(0, flash_addr->data, ENV_SIZE) == flash_addr->crc); - crc2_ok = (crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc); + crc1_ok = (tinf_crc32(flash_addr->data, ENV_SIZE) == flash_addr->crc); + crc2_ok = (tinf_crc32(flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc); if(crc1_ok && !crc2_ok){ gd->env_addr = addr1; @@ -193,7 +194,7 @@ Done: #else /* ! CFG_ENV_ADDR_REDUND */ int env_init(void){ - if(crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc){ + if(tinf_crc32(env_ptr->data, ENV_SIZE) == env_ptr->crc){ gd->env_addr = (ulong)&(env_ptr->data); gd->env_valid = 1; @@ -273,7 +274,7 @@ void env_relocate_spec(void){ end_addr_new = ltmp; } - if(flash_addr_new->flags != OBSOLETE_FLAG && crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc){ + if(flash_addr_new->flags != OBSOLETE_FLAG && tinf_crc32(flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc){ char flag = OBSOLETE_FLAG; gd->env_valid = 2; diff --git a/u-boot/include/common.h b/u-boot/include/common.h index 82d6614..bb08d77 100644 --- a/u-boot/include/common.h +++ b/u-boot/include/common.h @@ -534,12 +534,6 @@ long simple_strtol(const char *cp,char **endp,unsigned int base); int sprintf(char * buf, const char *fmt, ...); int vsprintf(char *buf, const char *fmt, va_list args); -/* lib_generic/crc32.c */ -/* Hack: Forces compilation failure if must_be_zero is not zero. */ -#define crc32(must_be_zero, buf, len) \ - tinf_crc32(buf, len*(sizeof(char[1 - 2*!!(must_be_zero)]))) -uint tinf_crc32(const void *data, uint length); - /* common/console.c */ int console_init_f(void); /* Before relocation; uses the serial stuff */ int console_init_r(void); /* After relocation; uses the console stuff */ diff --git a/u-boot/lib_bootstrap/bootstrap_board.c b/u-boot/lib_bootstrap/bootstrap_board.c index 8cc6dd3..25e160a 100644 --- a/u-boot/lib_bootstrap/bootstrap_board.c +++ b/u-boot/lib_bootstrap/bootstrap_board.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "LzmaWrapper.h" //#define DEBUG_ENABLE_BOOTSTRAP_PRINTF @@ -243,7 +244,7 @@ void bootstrap_board_init_r(gd_t *id, ulong dest_addr){ checksum = ntohl(hdr->ih_hcrc); hdr->ih_hcrc = 0; - if(crc32(0, (unsigned char *)data, len) != checksum){ + if(tinf_crc32((unsigned char *)data, len) != checksum){ return; } diff --git a/u-boot/tools/envcrc.c b/u-boot/tools/envcrc.c index 7b77183..179e44b 100644 --- a/u-boot/tools/envcrc.c +++ b/u-boot/tools/envcrc.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifndef __ASSEMBLY__ #define __ASSEMBLY__ /* Dirty trick to get only #defines */ @@ -66,8 +67,6 @@ #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE) -extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int); - #ifdef ENV_IS_EMBEDDED extern unsigned int env_size; extern unsigned char environment; @@ -81,7 +80,7 @@ int main (int argc, char **argv) *dataptr = envptr + ENV_HEADER_SIZE; unsigned int datasize = ENV_SIZE; - crc = crc32 (0, dataptr, datasize); + crc = tinf_crc32 (dataptr, datasize); /* Check if verbose mode is activated passing a parameter to the program */ if (argc > 1) { diff --git a/u-boot/tools/mkimage.c b/u-boot/tools/mkimage.c index de8af90..2d4ab04 100644 --- a/u-boot/tools/mkimage.c +++ b/u-boot/tools/mkimage.c @@ -32,6 +32,7 @@ #include #include #include +#include #if defined(__BEOS__) || defined(__NetBSD__) || defined(__APPLE__) #include @@ -68,11 +69,6 @@ extern int errno; char *cmdname; -#include -/* Hack: Forces compilation failure if must_be_zero is not zero. */ -#define crc32(must_be_zero, buf, len) \ - tinf_crc32(buf, len*(sizeof(char[1 - 2*!!(must_be_zero)]))) - typedef struct table_entry { int val; /* as defined in image.h */ char *sname; /* short (input) name */ @@ -349,7 +345,7 @@ NXTARG: ; checksum = ntohl(hdr->ih_hcrc); hdr->ih_hcrc = htonl(0); /* clear for re-calculation */ - if (crc32 (0, data, len) != checksum) { + if (tinf_crc32 (data, len) != checksum) { fprintf (stderr, "*** Warning: \"%s\" has bad header checksum!\n", imagefile); @@ -358,7 +354,7 @@ NXTARG: ; data = (char *)(ptr + sizeof(image_header_t)); len = sbuf.st_size - sizeof(image_header_t) ; - if (crc32 (0, data, len) != ntohl(hdr->ih_dcrc)) { + if (tinf_crc32 (data, len) != ntohl(hdr->ih_dcrc)) { fprintf (stderr, "*** Warning: \"%s\" has corrupted data!\n", imagefile); @@ -467,7 +463,7 @@ NXTARG: ; hdr = (image_header_t *)ptr; - checksum = crc32 (0, + checksum = tinf_crc32 ( (const char *)(ptr + sizeof(image_header_t)), sbuf.st_size - sizeof(image_header_t) ); @@ -486,7 +482,7 @@ NXTARG: ; strncpy((char *)hdr->ih_name, name, IH_NMLEN); - checksum = crc32(0,(const char *)hdr,sizeof(image_header_t)); + checksum = tinf_crc32((const char *)hdr,sizeof(image_header_t)); hdr->ih_hcrc = htonl(checksum); -- 2.25.1