Commit de15a06aad1f221255366ac07238c80fed146da1
Committed by
Stefan Roese
1 parent
6822a647b9
Exists in
master
and in
54 other branches
cfi: Make the flash erase and write operations abortable
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>
Showing 4 changed files with 17 additions and 1 deletions Side-by-side Diff
common/cmd_flash.c
... | ... | @@ -443,7 +443,8 @@ |
443 | 443 | rcode = flash_erase (info, s_first[bank], s_last[bank]); |
444 | 444 | } |
445 | 445 | } |
446 | - printf ("Erased %d sectors\n", erased); | |
446 | + if (rcode == 0) | |
447 | + printf("Erased %d sectors\n", erased); | |
447 | 448 | } else if (rcode == 0) { |
448 | 449 | puts ("Error: start and/or end address" |
449 | 450 | " not on sector boundary\n"); |
common/flash.c
... | ... | @@ -221,6 +221,9 @@ |
221 | 221 | case ERR_PROG_ERROR: |
222 | 222 | puts ("General Flash Programming Error\n"); |
223 | 223 | break; |
224 | + case ERR_ABORTED: | |
225 | + puts("Flash Programming Aborted\n"); | |
226 | + break; | |
224 | 227 | default: |
225 | 228 | printf ("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, err); |
226 | 229 | break; |
drivers/mtd/cfi_flash.c
... | ... | @@ -1077,6 +1077,11 @@ |
1077 | 1077 | |
1078 | 1078 | |
1079 | 1079 | for (sect = s_first; sect <= s_last; sect++) { |
1080 | + if (ctrlc()) { | |
1081 | + printf("\n"); | |
1082 | + return 1; | |
1083 | + } | |
1084 | + | |
1080 | 1085 | if (info->protect[sect] == 0) { /* not protected */ |
1081 | 1086 | #ifdef CONFIG_SYS_FLASH_CHECK_BLANK_BEFORE_ERASE |
1082 | 1087 | int k; |
... | ... | @@ -1379,6 +1384,9 @@ |
1379 | 1384 | src += i; |
1380 | 1385 | cnt -= i; |
1381 | 1386 | FLASH_SHOW_PROGRESS(scale, dots, digit, i); |
1387 | + /* Only check every once in a while */ | |
1388 | + if ((cnt & 0xFFFF) < buffered_size && ctrlc()) | |
1389 | + return ERR_ABORTED; | |
1382 | 1390 | } |
1383 | 1391 | #else |
1384 | 1392 | while (cnt >= info->portwidth) { |
... | ... | @@ -1391,6 +1399,9 @@ |
1391 | 1399 | wp += info->portwidth; |
1392 | 1400 | cnt -= info->portwidth; |
1393 | 1401 | FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth); |
1402 | + /* Only check every once in a while */ | |
1403 | + if ((cnt & 0xFFFF) < info->portwidth && ctrlc()) | |
1404 | + return ERR_ABORTED; | |
1394 | 1405 | } |
1395 | 1406 | #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */ |
1396 | 1407 |
include/flash.h
... | ... | @@ -141,6 +141,7 @@ |
141 | 141 | #define ERR_UNKNOWN_FLASH_VENDOR 32 |
142 | 142 | #define ERR_UNKNOWN_FLASH_TYPE 64 |
143 | 143 | #define ERR_PROG_ERROR 128 |
144 | +#define ERR_ABORTED 256 | |
144 | 145 | |
145 | 146 | /*----------------------------------------------------------------------- |
146 | 147 | * Protection Flags for flash_protect(): |