flashrom.c: Drop retry logic for failed erase/write
Now that we check first if an erase function should work with the
given programmer, we can drop the retry logic. This also simplifies
surrounding return codes a little.
Change-Id: I6db645dd3496f7c7f97c51aa5e8e088119012261
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72547
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/flashrom.c b/flashrom.c
index 2b5c571..cb84bdd 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -978,37 +978,24 @@
info->region_end = entry->end;
size_t j;
- int error = 1; /* retry as long as it's 1 */
for (j = 0; j < NUM_ERASEFUNCTIONS; ++j) {
if (j != 0)
msg_cinfo("Looking for another erase function.\n");
msg_cdbg("Trying erase function %zi... ", j);
- if (check_block_eraser(flashctx, j, 1))
- continue;
-
- error = walk_eraseblocks(flashctx, info, j, per_blockfn);
- if (error != 1)
+ if (!check_block_eraser(flashctx, j, 1))
break;
-
- if (info->curcontents) {
- msg_cinfo("Reading current flash chip contents... ");
- if (read_by_layout(flashctx, info->curcontents)) {
- /* Now we are truly screwed. Read failed as well. */
- msg_cerr("Can't read anymore! Aborting.\n");
- /* We have no idea about the flash chip contents, so
- retrying with another erase function is pointless. */
- error = 2;
- break;
- }
- msg_cinfo("done. ");
- }
}
- if (error == 1)
- msg_cinfo("No usable erase functions left.\n");
- if (error) {
+
+ if (j == NUM_ERASEFUNCTIONS) {
+ msg_cinfo("No usable erase function found.\n");
+ return 1;
+ }
+
+ if (walk_eraseblocks(flashctx, info, j, per_blockfn)) {
msg_cerr("FAILED!\n");
return 1;
}
+
}
if (all_skipped)
msg_cinfo("\nWarning: Chip content is identical to the requested image.\n");
@@ -1023,7 +1010,7 @@
const bool region_unaligned = info->region_start > info->erase_start ||
info->erase_end > info->region_end;
uint8_t *backup_contents = NULL, *erased_contents = NULL;
- int ret = 2;
+ int ret = 1;
/*
* If the region is not erase-block aligned, merge current flash con-
@@ -1034,7 +1021,6 @@
erased_contents = malloc(erase_len);
if (!backup_contents || !erased_contents) {
msg_cerr("Out of memory!\n");
- ret = 1;
goto _free_ret;
}
memset(backup_contents, ERASED_VALUE(flashctx), erase_len);
@@ -1062,7 +1048,6 @@
}
}
- ret = 1;
all_skipped = false;
msg_cdbg("E");