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>
This commit is contained in:
Simon Glass
2012-08-20 07:24:06 +01:00
committed by Gerrit
parent a8402a53ea
commit 21c1bf9628
5 changed files with 49 additions and 9 deletions

View File

@@ -31,6 +31,17 @@ static inline char *flash_physical_dataptr(int offset)
return (char *)(CONFIG_FLASH_BASE + offset);
}
/**
* Check if a region of flash is erased
*
* It is assumed that an erased region has all bits set to 1.
*
* @param offset Flash offset to check
* @param size Number of bytes to check (word-aligned)
* @return 1 if erased, 0 if not erased
*/
int flash_is_erased(uint32_t offset, int size);
/**
* Write to physical flash.
*