]> git.ipfire.org Git - thirdparty/u-boot.git/blame - lib/crc8.c
mx6sabresd: Reduce U-Boot proper size to fix boot regression
[thirdparty/u-boot.git] / lib / crc8.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
60d18d3f
SG
2/*
3 * Copyright (c) 2013 Google, Inc
60d18d3f
SG
4 */
5
c3a4d1c3
SG
6#ifdef USE_HOSTCC
7#include <arpa/inet.h>
c3a4d1c3 8#endif
3b52337c 9#include <asm/sections.h>
c3a4d1c3 10#include <u-boot/crc.h>
60d18d3f 11
456ecd08
SR
12#define POLY (0x1070U << 3)
13
3b52337c 14__rcode static unsigned char _crc8(unsigned short data)
60d18d3f 15{
456ecd08
SR
16 int i;
17
18 for (i = 0; i < 8; i++) {
19 if (data & 0x8000)
20 data = data ^ POLY;
21 data = data << 1;
60d18d3f
SG
22 }
23
456ecd08
SR
24 return (unsigned char)(data >> 8);
25}
26
3b52337c 27__rcode unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len)
456ecd08
SR
28{
29 int i;
30
31 for (i = 0; i < len; i++)
32 crc = _crc8((crc ^ vptr[i]) << 8);
33
34 return crc;
60d18d3f 35}
6f1b27a7
SG
36
37void crc8_wd_buf(const unsigned char *input, unsigned int len,
38 unsigned char output[1], unsigned int chunk_sz)
39{
40 *output = crc8(0, input, len);
41}