Commit 60d18d3fe9d1a5db663711063cd0d5c915af377a

Authored by Simon Glass
1 parent e7be18225f

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>

Showing 3 changed files with 49 additions and 0 deletions Inline Diff

include/linux/crc8.h
File was created 1 /*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7
8 #ifndef __linux_crc8_h
9 #define __linux_crc8_h
10
11 /**
12 * crc8() - Calculate and return CRC-8 of the data
13 *
14 * This uses an x^8 + x^2 + x + 1 polynomial. A table-based algorithm would
15 * be faster, but for only a few bytes it isn't worth the code size
16 *
17 * @vptr: Buffer to checksum
18 * @len: Length of buffer in bytes
19 * @return CRC8 checksum
20 */
21 unsigned int crc8(const unsigned char *vptr, int len);
22
23 #endif
24
1 # 1 #
2 # (C) Copyright 2000-2006 2 # (C) Copyright 2000-2006
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. 3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 # 4 #
5 # SPDX-License-Identifier: GPL-2.0+ 5 # SPDX-License-Identifier: GPL-2.0+
6 # 6 #
7 7
8 ifndef CONFIG_SPL_BUILD 8 ifndef CONFIG_SPL_BUILD
9 9
10 obj-$(CONFIG_RSA) += rsa/ 10 obj-$(CONFIG_RSA) += rsa/
11 obj-$(CONFIG_LZMA) += lzma/ 11 obj-$(CONFIG_LZMA) += lzma/
12 obj-$(CONFIG_LZO) += lzo/ 12 obj-$(CONFIG_LZO) += lzo/
13 obj-$(CONFIG_ZLIB) += zlib/ 13 obj-$(CONFIG_ZLIB) += zlib/
14 obj-$(CONFIG_TIZEN) += tizen/ 14 obj-$(CONFIG_TIZEN) += tizen/
15 15
16 obj-$(CONFIG_AES) += aes.o 16 obj-$(CONFIG_AES) += aes.o
17 obj-$(CONFIG_BZIP2) += bzlib.o 17 obj-$(CONFIG_BZIP2) += bzlib.o
18 obj-$(CONFIG_BZIP2) += bzlib_crctable.o 18 obj-$(CONFIG_BZIP2) += bzlib_crctable.o
19 obj-$(CONFIG_BZIP2) += bzlib_decompress.o 19 obj-$(CONFIG_BZIP2) += bzlib_decompress.o
20 obj-$(CONFIG_BZIP2) += bzlib_randtable.o 20 obj-$(CONFIG_BZIP2) += bzlib_randtable.o
21 obj-$(CONFIG_BZIP2) += bzlib_huffman.o 21 obj-$(CONFIG_BZIP2) += bzlib_huffman.o
22 obj-$(CONFIG_USB_TTY) += circbuf.o 22 obj-$(CONFIG_USB_TTY) += circbuf.o
23 obj-y += crc7.o 23 obj-y += crc7.o
24 obj-y += crc8.o
24 obj-y += crc16.o 25 obj-y += crc16.o
25 obj-$(CONFIG_OF_CONTROL) += fdtdec.o 26 obj-$(CONFIG_OF_CONTROL) += fdtdec.o
26 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o 27 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
27 obj-$(CONFIG_GZIP) += gunzip.o 28 obj-$(CONFIG_GZIP) += gunzip.o
28 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o 29 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
29 obj-y += initcall.o 30 obj-y += initcall.o
30 obj-$(CONFIG_LMB) += lmb.o 31 obj-$(CONFIG_LMB) += lmb.o
31 obj-y += ldiv.o 32 obj-y += ldiv.o
32 obj-$(CONFIG_MD5) += md5.o 33 obj-$(CONFIG_MD5) += md5.o
33 obj-y += net_utils.o 34 obj-y += net_utils.o
34 obj-$(CONFIG_PHYSMEM) += physmem.o 35 obj-$(CONFIG_PHYSMEM) += physmem.o
35 obj-y += qsort.o 36 obj-y += qsort.o
36 obj-$(CONFIG_SHA1) += sha1.o 37 obj-$(CONFIG_SHA1) += sha1.o
37 obj-$(CONFIG_SHA256) += sha256.o 38 obj-$(CONFIG_SHA256) += sha256.o
38 obj-y += strmhz.o 39 obj-y += strmhz.o
39 obj-$(CONFIG_TPM) += tpm.o 40 obj-$(CONFIG_TPM) += tpm.o
40 obj-$(CONFIG_RBTREE) += rbtree.o 41 obj-$(CONFIG_RBTREE) += rbtree.o
41 obj-$(CONFIG_BITREVERSE) += bitrev.o 42 obj-$(CONFIG_BITREVERSE) += bitrev.o
42 endif 43 endif
43 44
44 ifdef CONFIG_SPL_BUILD 45 ifdef CONFIG_SPL_BUILD
45 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o 46 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o
46 obj-$(CONFIG_SPL_NET_SUPPORT) += net_utils.o 47 obj-$(CONFIG_SPL_NET_SUPPORT) += net_utils.o
47 endif 48 endif
48 obj-$(CONFIG_ADDR_MAP) += addr_map.o 49 obj-$(CONFIG_ADDR_MAP) += addr_map.o
49 obj-y += hashtable.o 50 obj-y += hashtable.o
50 obj-y += errno.o 51 obj-y += errno.o
51 obj-y += display_options.o 52 obj-y += display_options.o
52 obj-$(CONFIG_BCH) += bch.o 53 obj-$(CONFIG_BCH) += bch.o
53 obj-y += crc32.o 54 obj-y += crc32.o
54 obj-y += ctype.o 55 obj-y += ctype.o
55 obj-y += div64.o 56 obj-y += div64.o
56 obj-y += hang.o 57 obj-y += hang.o
57 obj-y += linux_string.o 58 obj-y += linux_string.o
58 obj-$(CONFIG_REGEX) += slre.o 59 obj-$(CONFIG_REGEX) += slre.o
59 obj-y += string.o 60 obj-y += string.o
60 obj-y += time.o 61 obj-y += time.o
61 obj-$(CONFIG_TRACE) += trace.o 62 obj-$(CONFIG_TRACE) += trace.o
62 obj-$(CONFIG_BOOTP_PXE) += uuid.o 63 obj-$(CONFIG_BOOTP_PXE) += uuid.o
63 obj-y += vsprintf.o 64 obj-y += vsprintf.o
64 obj-$(CONFIG_RANDOM_MACADDR) += rand.o 65 obj-$(CONFIG_RANDOM_MACADDR) += rand.o
65 obj-$(CONFIG_BOOTP_RANDOM_DELAY) += rand.o 66 obj-$(CONFIG_BOOTP_RANDOM_DELAY) += rand.o
66 obj-$(CONFIG_CMD_LINK_LOCAL) += rand.o 67 obj-$(CONFIG_CMD_LINK_LOCAL) += rand.o
67 68
68 # SEE README.arm-unaligned-accesses 69 # SEE README.arm-unaligned-accesses
69 $(obj)bzlib.o: CFLAGS += $(PLATFORM_NO_UNALIGNED) 70 $(obj)bzlib.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
70 71
File was created 1 /*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include "linux/crc8.h"
8
9 unsigned int crc8(const unsigned char *vptr, int len)
10 {
11 const unsigned char *data = vptr;
12 unsigned int crc = 0;
13 int i, j;
14
15 for (j = len; j; j--, data++) {
16 crc ^= (*data << 8);
17 for (i = 8; i; i--) {
18 if (crc & 0x8000)
19 crc ^= (0x1070 << 3);
20 crc <<= 1;
21 }
22 }
23
24 return (crc >> 8) & 0xff;
25 }
26