summaryrefslogtreecommitdiff
path: root/include/crc.h
diff options
context:
space:
mode:
authorDerek Huang <derekhuang@google.com>2023-02-04 08:03:35 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-08 03:52:12 +0000
commit4f33b3bdd8024de044b70229aa19de553b78fc47 (patch)
tree6dc5151b775b68f81964445028d62256837cb8e2 /include/crc.h
parent3f96653b1d74bc45d272777f8656396a9bf3910c (diff)
downloadchrome-ec-4f33b3bdd8024de044b70229aa19de553b78fc47.tar.gz
crc16: Add CRC-16 utility functions
crc-16 is required for CPS8200 firmware update to validate the correctness of the firmware after programming the firmware to CPS8200 flash. This patch add CRC-16 utility functions and the test. BUG=b:195708351 BRANCH=none TEST=make -j buildall; make run-crc Change-Id: I198993387833464e151acd19531e18c6d077b8f1 Signed-off-by: Derek Huang <derekhuang@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4269952 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'include/crc.h')
-rw-r--r--include/crc.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/crc.h b/include/crc.h
index 85d389e506..04ddfed0c9 100644
--- a/include/crc.h
+++ b/include/crc.h
@@ -11,6 +11,9 @@
#if defined(CONFIG_HW_CRC) && !defined(HOST_TOOLS_BUILD)
#include "crc_hw.h"
#else
+#ifdef CONFIG_ZEPHYR
+#include <stdint.h>
+#endif /* CONFIG_ZEPHYR */
/* Use software implementation */
@@ -53,6 +56,17 @@ void crc32_ctx_hash8(uint32_t *ctx, uint8_t val);
uint32_t crc32_ctx_result(uint32_t *ctx);
+/**
+ * Return CRC-16 of the data using X^16 + X^15 + X^2 + 1 polynomial, based
+ * upon pre-calculated partial CRC of previous data.
+ * @param data uint8_t *, input, a pointer to input data
+ * @param len int, input, size of input data in bytes
+ * @param previous_crc uint16_t, input, pre-calculated CRC of previous data.
+ * Seed with zero for a new calculation.
+ * @return the crc-16 of the input data.
+ */
+uint16_t cros_crc16(const uint8_t *data, int len, uint16_t previous_crc);
+
#endif /* CONFIG_HW_CRC && !HOST_TOOLS_BUILD */
#endif /* __CROS_EC_CRC_H */