spi_flash: Reload watchdog before writing a flash page

When EC receives many flash write requests from host and
PDCMD, CHARGE and USB_CHG_P0 tasks are all ready to run, the
HOOK task may not get scheduled in time to pet the watchdog
resulting in an EC reset.

BUG=chrome-os-partner:51438
BRANCH=None
TEST=Manual on lars, determine two EC versions that have enough
differences so that replacing one image with the other will
require all or most of the flash pages to be updated. Alternate
between flashing the two images with flashrom using a script.
Atleast 1000 iterations should pass.

Change-Id: I8b5c8b680a2935b945f3740e371dee2d218ec4c5
Signed-off-by: Shamile Khan <shamile.khan@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/334457
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit a537d1ac44c40e7f6e1131e8cc852b030ccdba52)
Reviewed-on: https://chromium-review.googlesource.com/334903
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
This commit is contained in:
Shamile Khan
2016-03-23 16:02:59 -07:00
committed by chrome-bot
parent a76eb92cc2
commit ef561a293f

View File

@@ -272,6 +272,7 @@ int spi_flash_write(unsigned int offset, unsigned int bytes,
return EC_ERROR_INVAL;
while (bytes > 0) {
watchdog_reload();
/* Write length can not go beyond the end of the flash page */
write_size = MIN(bytes, SPI_FLASH_MAX_WRITE_SIZE -
(offset & (SPI_FLASH_MAX_WRITE_SIZE - 1)));
@@ -540,8 +541,6 @@ static int command_spi_flashwrite(int argc, char **argv)
ccprintf("Writing %d bytes to 0x%x...\n", bytes, offset);
while (bytes > 0) {
watchdog_reload();
/* First write multiples of 256, then (bytes % 256) last */
write_len = ((bytes % SPI_FLASH_MAX_WRITE_SIZE) == bytes) ?
bytes : SPI_FLASH_MAX_WRITE_SIZE;