diff options
author | Derek Huang <derekhuang@google.com> | 2023-02-04 08:03:35 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-08 03:52:12 +0000 |
commit | 4f33b3bdd8024de044b70229aa19de553b78fc47 (patch) | |
tree | 6dc5151b775b68f81964445028d62256837cb8e2 /test | |
parent | 3f96653b1d74bc45d272777f8656396a9bf3910c (diff) | |
download | chrome-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 'test')
-rw-r--r-- | test/crc.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/crc.c b/test/crc.c index 9943a7ac0c..cd0ad0f1cc 100644 --- a/test/crc.c +++ b/test/crc.c @@ -83,6 +83,21 @@ static int test_cros_crc8(void) return EC_SUCCESS; } +static int test_crc16(void) +{ + uint8_t buffer[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 8 }; + + int crc = cros_crc16(buffer, 10, 0); + + /* + * Verifies polynomial values of 0x1021 representing X^16 + X^15 + X^2 + + * 1 + */ + TEST_EQ(crc, 60681, "%d"); + + return EC_SUCCESS; +} + void run_test(int argc, const char **argv) { test_reset(); @@ -91,6 +106,7 @@ void run_test(int argc, const char **argv) RUN_TEST(test_8); RUN_TEST(test_kat0); RUN_TEST(test_cros_crc8); + RUN_TEST(test_crc16); test_print_result(); } |