From 768322d728e8e9228b8ce46dfbf0c8954b8650c4 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Mon, 11 Oct 2021 12:50:25 -0700 Subject: mec1322/timer: Unroll udelay This patch flattens udelay by unrolling __hw_clock_source_read. This increases the chance that we record LR of the instruction near which an infinite loop happened. BUG=b:218982018,b:200593658 BRANCH= TEST=buildall Change-Id: I8127e9a3308c161fd064e78048d82972bb57e464 Signed-off-by: Daisuke Nojiri (cherry picked from commit f0a9a2701fee604ec721b6a23173cec12cd8f4f0) Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3508423 --- chip/mec1322/hwtimer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/chip/mec1322/hwtimer.c b/chip/mec1322/hwtimer.c index be9ffac1ea..221633d3f4 100644 --- a/chip/mec1322/hwtimer.c +++ b/chip/mec1322/hwtimer.c @@ -107,3 +107,14 @@ int __hw_clock_source_init(uint32_t start_t) return MEC1322_IRQ_TIMER32_1; } + +/* + * Unrolled udelay. It preserves LR, which points to the root cause of WD crash. + */ +__override void udelay(unsigned us) +{ + unsigned t0 = 0xffffffff - MEC1322_TMR32_CNT(0); + + while (0xffffffff - MEC1322_TMR32_CNT(0) - t0 <= us) + ; +} -- cgit v1.2.1