summaryrefslogtreecommitdiffstats
path: root/lib/crc8.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2013-11-10 10:26:47 -0700
committerSimon Glass <sjg@chromium.org>2014-01-08 17:20:34 -0700
commit60d18d3fe9d1a5db663711063cd0d5c915af377a (patch)
tree82f1144ddcc272992f4999fac37bda8a816ec991 /lib/crc8.c
parente7be18225fbea76d1f0034b224f0d1e60f07cfcf (diff)
downloadtalos-obmc-uboot-60d18d3fe9d1a5db663711063cd0d5c915af377a.tar.gz
talos-obmc-uboot-60d18d3fe9d1a5db663711063cd0d5c915af377a.zip
Add crc8 routine
Add an implementation of the CRC8 algorithm. This is required by the TPM emulation, but is probably useful to U-Boot in general. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/crc8.c')
-rw-r--r--lib/crc8.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/crc8.c b/lib/crc8.c
new file mode 100644
index 0000000000..8b68a29e40
--- /dev/null
+++ b/lib/crc8.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "linux/crc8.h"
+
+unsigned int crc8(const unsigned char *vptr, int len)
+{
+ const unsigned char *data = vptr;
+ unsigned int crc = 0;
+ int i, j;
+
+ for (j = len; j; j--, data++) {
+ crc ^= (*data << 8);
+ for (i = 8; i; i--) {
+ if (crc & 0x8000)
+ crc ^= (0x1070 << 3);
+ crc <<= 1;
+ }
+ }
+
+ return (crc >> 8) & 0xff;
+}
OpenPOWER on IntegriCloud