]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cfi: Make the flash erase and write operations abortable
authorJoe Hershberger <joe.hershberger@ni.com>
Fri, 17 Aug 2012 20:36:41 +0000 (15:36 -0500)
committerStefan Roese <sr@denx.de>
Mon, 3 Sep 2012 09:24:27 +0000 (11:24 +0200)
Check for ctrlc() in operations that take time and loop over the flash
addresses.

In netconsole, tstc() is expensive.  Only check once in a while to not
slow down the operation significantly.

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

index 0e9b2e3c741e2b534904acf06944b68a044f77c9..e55d366c65d4a3029ebcdd3ecafc4170e609c237 100644 (file)
@@ -443,7 +443,8 @@ int flash_sect_erase (ulong addr_first, ulong addr_last)
                                rcode = flash_erase (info, s_first[bank], s_last[bank]);
                        }
                }
-               printf ("Erased %d sectors\n", erased);
+               if (rcode == 0)
+                       printf("Erased %d sectors\n", erased);
        } else if (rcode == 0) {
                puts ("Error: start and/or end address"
                        " not on sector boundary\n");
index 781cb9c4a2e0edef319de5506ee4546214b4c5df..8244ba2ddde65b029cb5b5f8af9f8236129ddcb7 100644 (file)
@@ -221,6 +221,9 @@ void flash_perror (int err)
        case ERR_PROG_ERROR:
                puts ("General Flash Programming Error\n");
                break;
+       case ERR_ABORTED:
+               puts("Flash Programming Aborted\n");
+               break;
        default:
                printf ("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, err);
                break;
index 97a4fd7cfaa7b6c342925167fa77a209afab60b4..43140f36479cbee9b0b894c567c4a9588fe8b36f 100644 (file)
@@ -1077,6 +1077,11 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 
 
        for (sect = s_first; sect <= s_last; sect++) {
+               if (ctrlc()) {
+                       printf("\n");
+                       return 1;
+               }
+
                if (info->protect[sect] == 0) { /* not protected */
 #ifdef CONFIG_SYS_FLASH_CHECK_BLANK_BEFORE_ERASE
                        int k;
@@ -1379,6 +1384,9 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
                src += i;
                cnt -= i;
                FLASH_SHOW_PROGRESS(scale, dots, digit, i);
+               /* Only check every once in a while */
+               if ((cnt & 0xFFFF) < buffered_size && ctrlc())
+                       return ERR_ABORTED;
        }
 #else
        while (cnt >= info->portwidth) {
@@ -1391,6 +1399,9 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
                wp += info->portwidth;
                cnt -= info->portwidth;
                FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth);
+               /* Only check every once in a while */
+               if ((cnt & 0xFFFF) < info->portwidth && ctrlc())
+                       return ERR_ABORTED;
        }
 #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */
 
index e614d07dfa90187ca32835ff751755e5eb23db29..6d70bdd81d8318c9a44110a58a8a819c55da9b65 100644 (file)
@@ -141,6 +141,7 @@ extern flash_info_t *flash_get_info(ulong base);
 #define ERR_UNKNOWN_FLASH_VENDOR       32
 #define ERR_UNKNOWN_FLASH_TYPE         64
 #define ERR_PROG_ERROR                 128
+#define ERR_ABORTED                    256
 
 /*-----------------------------------------------------------------------
  * Protection Flags for flash_protect():