From b8879d81a2d342a6054cc92ed3c1a63ffce38bc0 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Sun, 27 Nov 2016 15:09:42 -0800 Subject: [PATCH] Add timeout to infinite loop. Change-Id: I7d005b4779154b4dfe8c9a26f4f0e351f426df9b --- src/flash/nor/fespi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/flash/nor/fespi.c b/src/flash/nor/fespi.c index e6fffd4ba..f8436b1f4 100644 --- a/src/flash/nor/fespi.c +++ b/src/flash/nor/fespi.c @@ -226,7 +226,19 @@ static int fespi_tx(struct flash_bank *bank, uint8_t in){ struct fespi_flash_bank *fespi_info = bank->driver_priv; uint32_t ctrl_base = fespi_info->ctrl_base; - while ((int32_t) FESPI_READ_REG(FESPI_REG_TXFIFO) < 0); + int64_t start = timeval_ms(); + + while (1) { + if ((int32_t) FESPI_READ_REG(FESPI_REG_TXFIFO) >= 0) { + break; + } + int64_t now = timeval_ms(); + if (now - start > 1000) { + LOG_ERROR("txfifo stayed negative."); + return ERROR_TARGET_TIMEOUT; + } + } + FESPI_WRITE_REG(FESPI_REG_TXFIFO, in); return ERROR_OK;