diff options
author | Tim Lin <tim2.lin@ite.corp-partner.google.com> | 2021-08-03 13:49:59 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-05 04:37:37 +0000 |
commit | c9a082a25252f0afd10eb98b45fdd291f40f4026 (patch) | |
tree | 38c2605cede428271287a35145abf6b836d0b26d /zephyr/drivers/cros_flash | |
parent | 1e6fa3706b77db7139853b12a3977b03aea31bef (diff) | |
download | chrome-ec-c9a082a25252f0afd10eb98b45fdd291f40f4026.tar.gz |
zephyr/drivers: flash: add watchdog reload in flash erasing
When a large size of data is erased, the watchdog needs to be
reloaded, otherwise it will cause the watchdog timeout.
BUG=b:195328245
BRANCH=none
TEST=console command:
flasherase 0x80000 0x80000
watchdog will not timeout to cause reboot.
Change-Id: Ic483101b481b58c2870f18b3745cee511504a809
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3068488
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'zephyr/drivers/cros_flash')
-rw-r--r-- | zephyr/drivers/cros_flash/cros_flash_it8xxx2.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/zephyr/drivers/cros_flash/cros_flash_it8xxx2.c b/zephyr/drivers/cros_flash/cros_flash_it8xxx2.c index 5b7c04a24a..9c3d8f9db1 100644 --- a/zephyr/drivers/cros_flash/cros_flash_it8xxx2.c +++ b/zephyr/drivers/cros_flash/cros_flash_it8xxx2.c @@ -14,6 +14,7 @@ #include "flash.h" #include "host_command.h" #include "system.h" +#include "watchdog.h" LOG_MODULE_REGISTER(cros_flash, LOG_LEVEL_ERR); @@ -184,12 +185,40 @@ static int cros_flash_it8xxx2_erase(const struct device *dev, int offset, int size) { struct cros_flash_it8xxx2_data *const data = DRV_DATA(dev); + int ret = 0; if (data->all_protected) { return -EACCES; } + /* + * Before the flash erasing, the interrupts should be disabled. In + * the flash erasing loop, the SHI interrupt should be enabled to + * handle AP's command, so irq_lock() is not used here. + */ + if (IS_ENABLED(CONFIG_ITE_IT8XXX2_INTC)) { + ite_intc_save_and_disable_interrupts(); + } + /* Always use sector erase command */ + for (; size > 0; size -= CONFIG_FLASH_ERASE_SIZE) { + ret = flash_erase(flash_controller, offset, + CONFIG_FLASH_ERASE_SIZE); + if (ret) + break; + + offset += CONFIG_FLASH_ERASE_SIZE; + /* + * If requested erase size is too large at one time on KGD + * flash, we need to reload watchdog to prevent the reset. + */ + if (IS_ENABLED(CONFIG_PLATFORM_EC_WATCHDOG) && (size > 0x10000)) + watchdog_reload(); + } + /* Restore interrupts */ + if (IS_ENABLED(CONFIG_ITE_IT8XXX2_INTC)) { + ite_intc_restore_interrupts(); + } - return flash_erase(flash_controller, offset, size); + return ret; } static int cros_flash_it8xxx2_get_protect(const struct device *dev, int bank) |