From b90e2510001996ea9419fb482c9c7a97af21ec12 Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Fri, 29 Apr 2022 14:06:09 -0600 Subject: [PATCH] drivers/spi: Add better error reporting to spi_flash_cmd_poll_bit It's useful to know how many attempts were made at polling the status bit. BUG=b:228289365 TEST=Boot guybrush Signed-off-by: Raul E Rangel Change-Id: Ifcc79a339707fbaab33e128807d4c0b26aa90108 Reviewed-on: https://review.coreboot.org/c/coreboot/+/63959 Tested-by: build bot (Jenkins) Reviewed-by: Rob Barnes --- src/drivers/spi/spi_flash.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c index 0142fad442..9934f55e49 100644 --- a/src/drivers/spi/spi_flash.c +++ b/src/drivers/spi/spi_flash.c @@ -192,19 +192,28 @@ int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout, { const struct spi_slave *spi = &flash->spi; int ret; + int attempt = 0; u8 status; struct stopwatch sw; stopwatch_init_msecs_expire(&sw, timeout); do { + attempt++; + ret = do_spi_flash_cmd(spi, &cmd, 1, &status, 1); - if (ret) + if (ret) { + printk(BIOS_WARNING, + "SF: SPI command failed on attempt %d with rc %d\n", attempt, + ret); return -1; + } + if ((status & poll_bit) == 0) return 0; } while (!stopwatch_expired(&sw)); - printk(BIOS_WARNING, "SF: timeout at %ld msec\n", stopwatch_duration_msecs(&sw)); + printk(BIOS_WARNING, "SF: timeout at %ld msec after %d attempts\n", + stopwatch_duration_msecs(&sw), attempt); return -1; }