From 21c1bf96282e8ac6bf6ff43cb537cbdefd84fc65 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 20 Aug 2012 07:24:06 +0100 Subject: 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 Reviewed-on: https://gerrit.chromium.org/gerrit/30851 Reviewed-by: Randall Spangler --- include/flash.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/flash.h') diff --git a/include/flash.h b/include/flash.h index 2e31cf0f22..8bf0264c14 100644 --- a/include/flash.h +++ b/include/flash.h @@ -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. * -- cgit v1.2.1