]>
Commit | Line | Data |
---|---|---|
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 SG |
8 | #endif |
9 | #include <u-boot/crc.h> | |
60d18d3f | 10 | |
456ecd08 SR |
11 | #define POLY (0x1070U << 3) |
12 | ||
13 | static unsigned char _crc8(unsigned short data) | |
60d18d3f | 14 | { |
456ecd08 SR |
15 | int i; |
16 | ||
17 | for (i = 0; i < 8; i++) { | |
18 | if (data & 0x8000) | |
19 | data = data ^ POLY; | |
20 | data = data << 1; | |
60d18d3f SG |
21 | } |
22 | ||
456ecd08 SR |
23 | return (unsigned char)(data >> 8); |
24 | } | |
25 | ||
26 | unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len) | |
27 | { | |
28 | int i; | |
29 | ||
30 | for (i = 0; i < len; i++) | |
31 | crc = _crc8((crc ^ vptr[i]) << 8); | |
32 | ||
33 | return crc; | |
60d18d3f | 34 | } |