Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 2 | /* |
3 | * Copyright (c) 2013 Google, Inc | ||||
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 4 | */ |
5 | |||||
Simon Glass | ca9b0af | 2019-11-14 12:57:14 -0700 | [diff] [blame] | 6 | #ifdef USE_HOSTCC |
7 | #include <arpa/inet.h> | ||||
Simon Glass | ca9b0af | 2019-11-14 12:57:14 -0700 | [diff] [blame] | 8 | #endif |
Simon Glass | 973dd9c | 2025-01-26 11:43:21 -0700 | [diff] [blame] | 9 | #include <asm/sections.h> |
Simon Glass | ca9b0af | 2019-11-14 12:57:14 -0700 | [diff] [blame] | 10 | #include <u-boot/crc.h> |
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 11 | |
Stefan Roese | a0d9b99 | 2016-04-08 15:56:29 +0200 | [diff] [blame] | 12 | #define POLY (0x1070U << 3) |
13 | |||||
Simon Glass | 973dd9c | 2025-01-26 11:43:21 -0700 | [diff] [blame] | 14 | __rcode static unsigned char _crc8(unsigned short data) |
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 15 | { |
Stefan Roese | a0d9b99 | 2016-04-08 15:56:29 +0200 | [diff] [blame] | 16 | int i; |
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 17 | |
Stefan Roese | a0d9b99 | 2016-04-08 15:56:29 +0200 | [diff] [blame] | 18 | for (i = 0; i < 8; i++) { |
19 | if (data & 0x8000) | ||||
20 | data = data ^ POLY; | ||||
21 | data = data << 1; | ||||
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 22 | } |
23 | |||||
Stefan Roese | a0d9b99 | 2016-04-08 15:56:29 +0200 | [diff] [blame] | 24 | return (unsigned char)(data >> 8); |
25 | } | ||||
26 | |||||
Simon Glass | 973dd9c | 2025-01-26 11:43:21 -0700 | [diff] [blame] | 27 | __rcode unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len) |
Stefan Roese | a0d9b99 | 2016-04-08 15:56:29 +0200 | [diff] [blame] | 28 | { |
29 | int i; | ||||
30 | |||||
31 | for (i = 0; i < len; i++) | ||||
32 | crc = _crc8((crc ^ vptr[i]) << 8); | ||||
33 | |||||
34 | return crc; | ||||
Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame] | 35 | } |
Simon Glass | dc020a2 | 2024-12-19 11:29:07 -0700 | [diff] [blame] | 36 | |
37 | void 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 | } |