diff options
author | Diana Z <dzigterman@chromium.org> | 2022-12-20 13:40:19 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-12-20 23:40:56 +0000 |
commit | 69b31a6532b6c2d83a82eb58b5dd2f1465a5abd5 (patch) | |
tree | c49ce868b53654d599cfbbc8dc842da991b8c864 | |
parent | 98e00bb45940f1cf31216a20c7441364d43fd8fb (diff) | |
download | chrome-ec-69b31a6532b6c2d83a82eb58b5dd2f1465a5abd5.tar.gz |
Zephyr: Ensure NPCX flash write and erase reload watchdog
Writing to the flash during EC FW update may take some time, and the AP
may be sending these commands frequently. Ensure we've reloaded the
watchdog on writes to prevent a watchdog reset in the middle of FW
update.
Similarly, ensure we reload the watchdog during flash erase as well. Do
this once per sector.
LOW_COVERAGE_REASON=cros_flash currently has no coverage
BRANCH=None
BUG=b:261724677
TEST=on skyrim, run "chromeos-firmwareupdate --force" from the OS and
ensure it completes successfully
Change-Id: Iab5e02929880464e84e6636c00640efc5ce2a668
Signed-off-by: Diana Z <dzigterman@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4118799
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/drivers/cros_flash/cros_flash_npcx.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/zephyr/drivers/cros_flash/cros_flash_npcx.c b/zephyr/drivers/cros_flash/cros_flash_npcx.c index e49067ad1a..6a0a87f7c1 100644 --- a/zephyr/drivers/cros_flash/cros_flash_npcx.c +++ b/zephyr/drivers/cros_flash/cros_flash_npcx.c @@ -8,6 +8,7 @@ #include "../drivers/flash/spi_nor.h" #include "flash.h" #include "spi_flash_reg.h" +#include "watchdog.h" #include "write_protect.h" #include <zephyr/drivers/flash.h> @@ -443,6 +444,14 @@ static int cros_flash_npcx_write(const struct device *dev, int offset, int size, return -EINVAL; } + /* + * If the AP sends a sequence of write commands, we may not have time to + * reload the watchdog normally. Force a reload here to avoid the + * watchdog triggering in the middle of flashing. + */ + if (IS_ENABLED(CONFIG_WATCHDOG)) + watchdog_reload(); + /* Lock physical flash operations */ crec_flash_lock_mapped_storage(1); @@ -480,7 +489,22 @@ static int cros_flash_npcx_erase(const struct device *dev, int offset, int size) /* Lock physical flash operations */ crec_flash_lock_mapped_storage(1); - ret = flash_erase(data->flash_dev, offset, size); + for (; size > 0; size -= CONFIG_FLASH_ERASE_SIZE) { + /* + * Reload the watchdog timer, so that erasing many flash pages + * doesn't cause a watchdog reset + */ + if (IS_ENABLED(CONFIG_WATCHDOG)) + watchdog_reload(); + + /* Start erase */ + ret = flash_erase(data->flash_dev, offset, + CONFIG_FLASH_ERASE_SIZE); + if (ret) + break; + + offset += CONFIG_FLASH_ERASE_SIZE; + } /* Unlock physical flash operations */ crec_flash_lock_mapped_storage(0); |