diff options
author | Charles Manning <cdhmanning@gmail.com> | 2014-05-14 14:45:01 +1200 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-06-05 14:38:38 -0400 |
commit | 25308f45e11527cbfc7ff6d9dced7800e4b976e4 (patch) | |
tree | 1788de35e7fe6c2b9948dbf6349662ff5de0a019 | |
parent | abbc67eedf37a240fe6cdd1ce46eedd12cd3a13f (diff) | |
download | u-boot-imx-25308f45e11527cbfc7ff6d9dced7800e4b976e4.zip u-boot-imx-25308f45e11527cbfc7ff6d9dced7800e4b976e4.tar.gz u-boot-imx-25308f45e11527cbfc7ff6d9dced7800e4b976e4.tar.bz2 |
tools: Refactor mxsimage to use pbl_crc32
Both pblimage and mxsimage use the same crc algorithm, so refactor.
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
-rw-r--r-- | tools/mxsimage.c | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/tools/mxsimage.c b/tools/mxsimage.c index 045b35a..81c7f2d 100644 --- a/tools/mxsimage.c +++ b/tools/mxsimage.c @@ -19,6 +19,7 @@ #include "imagetool.h" #include "mxsimage.h" +#include "pbl_crc32.h" #include <image.h> @@ -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,9 @@ 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, + (const char *)cctx->data, + cctx->length); cctx->size = sizeof(*ccmd) + cctx->length; @@ -1834,7 +1814,9 @@ 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, + (const char *)cctx->data, + asize)) { fprintf(stderr, "ERR: SB LOAD command payload CRC32 invalid!\n"); return -EINVAL; |