diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2023-12-12 09:16:21 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-12-13 07:53:57 +0100 |
commit | 0c1475dc016e9bfb99f119d61928d388c8cfc19d (patch) | |
tree | 3fa719348a4b26b28809fbc798b8e76866cab737 /scripts | |
parent | 7c851b5f4afce584e9eb850d70f77a4d18e9eb4f (diff) | |
download | barebox-0c1475dc016e9bfb99f119d61928d388c8cfc19d.tar.gz barebox-0c1475dc016e9bfb99f119d61928d388c8cfc19d.tar.xz |
scripts: pblimage: re-use crc32 implementation from crypto/crc32.c
We already have crc32_be in the tree, so re-use that.
Link: https://lore.barebox.org/20231212081623.1548734-2-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/pblimage.c | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/scripts/pblimage.c b/scripts/pblimage.c index 3c3625cdd5..df5d7aef69 100644 --- a/scripts/pblimage.c +++ b/scripts/pblimage.c @@ -15,6 +15,10 @@ #include <endian.h> #include <byteswap.h> +#include "common.h" +#include "common.c" +#include "../crypto/crc32.c" + #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) #define PBL_ACS_CONT_CMD 0x81000000 #define PBL_ADDR_24BIT_MASK 0x00ffffff @@ -68,52 +72,9 @@ static char *outfile; static unsigned long loadaddr = 0x10000000; static char *infile; -static uint32_t crc_table[256]; -static int crc_table_valid; - -static void make_crc_table(void) -{ - uint32_t mask; - int i, j; - uint32_t poly; /* polynomial exclusive-or pattern */ - - if (crc_table_valid) - return; - - /* - * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10 - * + x11 + x12 + x16 + x22 + x23 + x26 + x32. - */ - poly = 0x04c11db7; - - for (i = 0; i < 256; i++) { - mask = i << 24; - for (j = 0; j < 8; j++) { - if (mask & 0x80000000) - mask = (mask << 1) ^ poly; - else - mask <<= 1; - } - crc_table[i] = mask; - } - - crc_table_valid = 1; -} - static uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len) { - uint32_t crc32_val; - int i; - - make_crc_table(); - - crc32_val = ~in_crc; - - for (i = 0; i < len; i++) - crc32_val = (crc32_val << 8) ^ - crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)]; - - return crc32_val; + return crc32_be(~in_crc, buf, len); } /* |