mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-27 05:23:34 +00:00
456ecd08ec
To make the usage of this function more flexible, lets add the CRC start value as parameter to this function. This way it can be used by other functions requiring different start values than 0 as well. For non-zero CRC start values to work, I've reworked the function a bit. The new implementation is copied from the Linux version in drivers/i2c/i2c-core.c / i2c_smbus_pec(). Which supports non-zero CRC stating values. I've double-checked that the results for zero starting values are identical to the results from the original version of this function. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
24 lines
548 B
C
24 lines
548 B
C
/*
|
|
* Copyright (c) 2013 Google, Inc
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
*/
|
|
|
|
|
|
#ifndef __linux_crc8_h
|
|
#define __linux_crc8_h
|
|
|
|
/**
|
|
* crc8() - Calculate and return CRC-8 of the data
|
|
*
|
|
* This uses an x^8 + x^2 + x + 1 polynomial. A table-based algorithm would
|
|
* be faster, but for only a few bytes it isn't worth the code size
|
|
*
|
|
* @crc_start: CRC8 start value
|
|
* @vptr: Buffer to checksum
|
|
* @len: Length of buffer in bytes
|
|
* @return CRC8 checksum
|
|
*/
|
|
unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len);
|
|
|
|
#endif
|