summaryrefslogtreecommitdiffstats
path: root/tools/pbl_crc32.c
diff options
context:
space:
mode:
authorCharles Manning <cdhmanning@gmail.com>2014-05-14 14:45:00 +1200
committerTom Rini <trini@ti.com>2014-06-05 14:38:38 -0400
commitabbc67eedf37a240fe6cdd1ce46eedd12cd3a13f (patch)
tree36ea84685bf3f44cdb5da9dccb4afc85c073c567 /tools/pbl_crc32.c
parent4eb580b780057413ddc82855d913ea2f1cbc9dd2 (diff)
downloadtalos-obmc-uboot-abbc67eedf37a240fe6cdd1ce46eedd12cd3a13f.tar.gz
talos-obmc-uboot-abbc67eedf37a240fe6cdd1ce46eedd12cd3a13f.zip
mkimage : Split out and clean pbl_crc32 for use by other image types
The crc32 used by pblimgae is NOT the same as zlib crc32. The pbl_crc32 is useful for other purposes in mkimage so split it out. While we are about it, clean up redundant and confusing code. Signed-off-by: Charles Manning <cdhmanning@gmail.com>
Diffstat (limited to 'tools/pbl_crc32.c')
-rw-r--r--tools/pbl_crc32.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/pbl_crc32.c b/tools/pbl_crc32.c
new file mode 100644
index 0000000000..6e6735acde
--- /dev/null
+++ b/tools/pbl_crc32.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * Cleaned up and refactored by Charles Manning.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include "pblimage.h"
+
+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;
+}
+
+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;
+}
OpenPOWER on IntegriCloud