From 2cd1b57220697ac47e4a63fb6a0a79eda2217f9d Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 5 Dec 2013 12:08:09 -0700 Subject: time: fix usec_to_tick() Commit 8dfafdde88eb ("Introduce common timer functions") created a common definition of usec_to_tick() which had a couple problems: static unsigned long long usec_to_tick(unsigned long usec) { uint64_t tick = usec * get_tbclk(); That likely overflows. usec *= get_tbclk(); That was an attempt to fix it by performing the multiply after the promotion of usec to 64-bit, but was applied to the wrong variable, which was never used. This patch fixes these issues. A user-visible symptom of the problem was the e.g. "dhcp zImage" using an ASIX USB Ethernet dongle would print: Waiting for Ethernet connection... unable to connect. ... with no delay before "unable to connect". There are likely other symptoms. Signed-off-by: Stephen Warren Acked-by: Rob Herring --- lib/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/time.c b/lib/time.c index 09bb05a..8085aa4 100644 --- a/lib/time.c +++ b/lib/time.c @@ -71,8 +71,8 @@ unsigned long __weak notrace timer_get_us(void) } static unsigned long long usec_to_tick(unsigned long usec) { - uint64_t tick = usec * get_tbclk(); - usec *= get_tbclk(); + uint64_t tick = usec; + tick *= get_tbclk(); do_div(tick, 1000000); return tick; } -- cgit v1.1 From 60d18d3fe9d1a5db663711063cd0d5c915af377a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 10 Nov 2013 10:26:47 -0700 Subject: Add crc8 routine Add an implementation of the CRC8 algorithm. This is required by the TPM emulation, but is probably useful to U-Boot in general. Signed-off-by: Simon Glass Signed-off-by: Simon Glass Reviewed-by: Simon Glass --- lib/Makefile | 1 + lib/crc8.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/crc8.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index e787f77..760340f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_BZIP2) += bzlib_randtable.o obj-$(CONFIG_BZIP2) += bzlib_huffman.o obj-$(CONFIG_USB_TTY) += circbuf.o obj-y += crc7.o +obj-y += crc8.o obj-y += crc16.o obj-$(CONFIG_OF_CONTROL) += fdtdec.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o diff --git a/lib/crc8.c b/lib/crc8.c new file mode 100644 index 0000000..8b68a29 --- /dev/null +++ b/lib/crc8.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2013 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "linux/crc8.h" + +unsigned int crc8(const unsigned char *vptr, int len) +{ + const unsigned char *data = vptr; + unsigned int crc = 0; + int i, j; + + for (j = len; j; j--, data++) { + crc ^= (*data << 8); + for (i = 8; i; i--) { + if (crc & 0x8000) + crc ^= (0x1070 << 3); + crc <<= 1; + } + } + + return (crc >> 8) & 0xff; +} -- cgit v1.1