From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Babic Date: Tue, 06 May 2014 10:11:30 +0200 Subject: [U-Boot] [PATCH 2/2] mkimage: Refactor mxsimage to use common crc32 code In-Reply-To: <1399330006-3376-3-git-send-email-cdhmanning@gmail.com> References: <1399330006-3376-1-git-send-email-cdhmanning@gmail.com> <1399330006-3376-3-git-send-email-cdhmanning@gmail.com> Message-ID: <53689932.9060803@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Charles, On 06/05/2014 00:46, Charles Manning wrote: > mxsimage uses the same crc32 function as pblimage. > > Signed-off-by: Charles Manning > --- > tools/mxsimage.c | 28 +++------------------------- > 1 file changed, 3 insertions(+), 25 deletions(-) > > diff --git a/tools/mxsimage.c b/tools/mxsimage.c > index 045b35a..0c4348c 100644 > --- a/tools/mxsimage.c > +++ b/tools/mxsimage.c > @@ -19,6 +19,7 @@ > > #include "imagetool.h" > #include "mxsimage.h" > +#include "pbl_crc32.h" > #include > > > @@ -231,29 +232,6 @@ static int sb_aes_reinit(struct sb_image_ctx *ictx, int enc) > } > > /* > - * CRC32 > - */ > -static uint32_t crc32(uint8_t *data, uint32_t len) > -{ > - const uint32_t poly = 0x04c11db7; > - uint32_t crc32 = 0xffffffff; > - unsigned int byte, bit; > - > - for (byte = 0; byte < len; byte++) { > - crc32 ^= data[byte] << 24; > - > - for (bit = 8; bit > 0; bit--) { > - if (crc32 & (1UL << 31)) > - crc32 = (crc32 << 1) ^ poly; > - else > - crc32 = (crc32 << 1); > - } > - } > - > - return crc32; > -} > - > -/* > * Debug > */ > static void soprintf(struct sb_image_ctx *ictx, const char *fmt, ...) > @@ -998,7 +976,7 @@ static int sb_build_command_load(struct sb_image_ctx *ictx, > > ccmd->load.address = dest; > ccmd->load.count = cctx->length; > - ccmd->load.crc32 = crc32(cctx->data, cctx->length); > + ccmd->load.crc32 = pbl_crc32(0, cctx->data, cctx->length); > > cctx->size = sizeof(*ccmd) + cctx->length; > > @@ -1834,7 +1812,7 @@ static int sb_verify_command(struct sb_image_ctx *ictx, > EVP_DigestUpdate(&ictx->md_ctx, cctx->data, asize); > sb_aes_crypt(ictx, cctx->data, cctx->data, asize); > > - if (ccmd->load.crc32 != crc32(cctx->data, asize)) { > + if (ccmd->load.crc32 != pbl_crc32(0, cctx->data, asize)) { > fprintf(stderr, > "ERR: SB LOAD command payload CRC32 invalid!\n"); > return -EINVAL; > Good idea to factorize these functions, thanks ! Acked-by: Stefano Babic Best regards, Stefano Babic -- ===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================