]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
cfi: Check for blank before erase
authorJoe Hershberger <joe.hershberger@ni.com>
Fri, 17 Aug 2012 20:36:40 +0000 (15:36 -0500)
committerStefan Roese <sr@denx.de>
Mon, 3 Sep 2012 09:24:27 +0000 (11:24 +0200)
Added an optional check in the CFI driver to evaluate if the sector is
already blank before issuing an erase command.  Improves erase time by
over a factor of 10 if already blank.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Stefan Roese <sr@denx.de>
drivers/mtd/cfi_flash.c

index f0f301a46023e67c952b5dd7f65790f835fd28a8..97a4fd7cfaa7b6c342925167fa77a209afab60b4 100644 (file)
@@ -1078,6 +1078,32 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 
        for (sect = s_first; sect <= s_last; sect++) {
                if (info->protect[sect] == 0) { /* not protected */
+#ifdef CONFIG_SYS_FLASH_CHECK_BLANK_BEFORE_ERASE
+                       int k;
+                       int size;
+                       int erased;
+                       u32 *flash;
+
+                       /*
+                        * Check if whole sector is erased
+                        */
+                       size = flash_sector_size(info, sect);
+                       erased = 1;
+                       flash = (u32 *)info->start[sect];
+                       /* divide by 4 for longword access */
+                       size = size >> 2;
+                       for (k = 0; k < size; k++) {
+                               if (flash_read32(flash++) != 0xffffffff) {
+                                       erased = 0;
+                                       break;
+                               }
+                       }
+                       if (erased) {
+                               if (flash_verbose)
+                                       putc(',');
+                               continue;
+                       }
+#endif
                        switch (info->vendor) {
                        case CFI_CMDSET_INTEL_PROG_REGIONS:
                        case CFI_CMDSET_INTEL_STANDARD: