summaryrefslogtreecommitdiff
path: root/chip/lm4/flash.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2012-08-20 07:24:06 +0100
committerGerrit <chrome-bot@google.com>2012-08-23 14:40:01 -0700
commit21c1bf96282e8ac6bf6ff43cb537cbdefd84fc65 (patch)
tree8de5249392113af1fc42594749df31688bbe309c /chip/lm4/flash.c
parenta8402a53ea89e69ef6463a5a8bc033c42c163926 (diff)
downloadchrome-ec-21c1bf96282e8ac6bf6ff43cb537cbdefd84fc65.tar.gz
flash: Only erase flash block that contain data
It wastes time to erase blocks that are already erased and it is faster on stm32 to check first. Add a check in flash_physical_erase() on all chips, using a common flash_is_erased() function. BUG=none BRANCH=snow,link TEST=manual Do software sync in U-Boot and see that it succeeds. This tests that we can still erase and then boot a written image. It typically saves a second on a full sync over i2c. SMDK5250 # cros_test swsync -f SF: Detected W25Q32 with page size 4 KiB, total 4 MiB Flashing RW EC image: erasing, writing, done Flashing RO EC image: erasing, writing, done Full software sync completed in 22.949s SMDK5250 # Also see that second erase is faster: SMDK5250 # time mkbp erase rw time: 0.952 seconds, 952 ticks SMDK5250 # time mkbp erase rw time: 0.054 seconds, 54 ticks SMDK5250 # Change-Id: I3699577217fdbb2f212d20d150d3ca15fdff03eb Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/30851 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/lm4/flash.c')
-rw-r--r--chip/lm4/flash.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/chip/lm4/flash.c b/chip/lm4/flash.c
index 8eab52ca9c..c9922b4ea4 100644
--- a/chip/lm4/flash.c
+++ b/chip/lm4/flash.c
@@ -227,11 +227,17 @@ int flash_physical_write(int offset, int size, const char *data)
int flash_physical_erase(int offset, int size)
{
LM4_FLASH_FCMISC = LM4_FLASH_FCRIS; /* Clear previous error status */
- LM4_FLASH_FMA = offset;
- for ( ; size > 0; size -= CONFIG_FLASH_ERASE_SIZE) {
+ for ( ; size > 0; size -= CONFIG_FLASH_ERASE_SIZE,
+ offset += CONFIG_FLASH_ERASE_SIZE) {
int t;
+ /* Do nothing if already erased */
+ if (flash_is_erased(offset, CONFIG_FLASH_ERASE_SIZE))
+ continue;
+
+ LM4_FLASH_FMA = offset;
+
#ifdef CONFIG_TASK_WATCHDOG
/* Reload the watchdog timer, so that erasing many flash pages
* doesn't cause a watchdog reset. May not need this now that
@@ -253,8 +259,6 @@ int flash_physical_erase(int offset, int size)
* protection error */
if (LM4_FLASH_FCRIS & 0x0a01)
return EC_ERROR_UNKNOWN;
-
- LM4_FLASH_FMA += CONFIG_FLASH_ERASE_SIZE;
}
return EC_SUCCESS;