aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
Diffstat (limited to 'external')
-rw-r--r--external/pflash/pflash.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index d6b2b8e..381df24 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -325,16 +325,20 @@ static int erase_range(struct flash_details *flash,
*/
progress_init(size);
if (start & erase_mask) {
- /* Align to next erase block */
- rc = blocklevel_smart_erase(flash->bl, start,
- flash->erase_granule - (start & erase_mask));
+ /*
+ * Align to next erase block, or just do the entire
+ * thing if we fit within one erase block
+ */
+ uint32_t first_size = MIN(size, (flash->erase_granule - (start & erase_mask)));
+
+ rc = blocklevel_smart_erase(flash->bl, start, first_size);
if (rc) {
fprintf(stderr, "Failed to blocklevel_smart_erase(): %d\n", rc);
return 1;
}
- size -= flash->erase_granule - (start & erase_mask);
- done = flash->erase_granule - (start & erase_mask);
- start += flash->erase_granule - (start & erase_mask);
+ size -= first_size;
+ done = first_size;
+ start += first_size;
}
progress_tick(done);
while (size & ~(erase_mask)) {