Commit dce73ae6 authored by Carl-Daniel Hailfinger's avatar Carl-Daniel Hailfinger
Browse files

Clean up erase function checking


Update a few comments and messages to improve readability.

Corresponding to flashrom svn r1244.
Signed-off-by: default avatarCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: default avatarMichael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
parent da53adad
......@@ -1455,39 +1455,58 @@ static int walk_eraseregions(struct flashchip *flash, int erasefunction,
return 0;
}
static int check_block_eraser(struct flashchip *flash, int k, int log)
{
struct block_eraser eraser = flash->block_erasers[k];
if (!eraser.block_erase && !eraser.eraseblocks[0].count) {
if (log)
msg_cdbg("not defined. ");
return 1;
}
if (!eraser.block_erase && eraser.eraseblocks[0].count) {
if (log)
msg_cdbg("eraseblock layout is known, but matching "
"block erase function is not implemented. ");
return 1;
}
if (eraser.block_erase && !eraser.eraseblocks[0].count) {
if (log)
msg_cdbg("block erase function found, but "
"eraseblock layout is not defined. ");
return 1;
}
return 0;
}
int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t *newcontents)
{
int k, ret = 0, found = 0;
int k, ret = 0;
uint8_t *curcontents;
unsigned long size = flash->total_size * 1024;
int usable_erasefunctions = 0;
for (k = 0; k < NUM_ERASEFUNCTIONS; k++)
if (!check_block_eraser(flash, k, 0))
usable_erasefunctions++;
msg_cinfo("Erasing and writing flash chip... ");
if (!usable_erasefunctions) {
msg_cerr("ERROR: flashrom has no erase function for this flash "
"chip.\n");
return 1;
}
curcontents = (uint8_t *) malloc(size);
/* Copy oldcontents to curcontents to avoid clobbering oldcontents. */
memcpy(curcontents, oldcontents, size);
msg_cinfo("Erasing and writing flash chip... ");
for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
struct block_eraser eraser = flash->block_erasers[k];
msg_cdbg("Looking at blockwise erase function %i... ", k);
if (!eraser.block_erase && !eraser.eraseblocks[0].count) {
msg_cdbg("not defined. "
"Looking for another erase function.\n");
continue;
}
if (!eraser.block_erase && eraser.eraseblocks[0].count) {
msg_cdbg("eraseblock layout is known, but no "
"matching block erase function found. "
"Looking for another erase function.\n");
if (check_block_eraser(flash, k, 1) && usable_erasefunctions) {
msg_cdbg("Looking for another erase function.\n");
continue;
}
if (eraser.block_erase && !eraser.eraseblocks[0].count) {
msg_cdbg("block erase function found, but "
"eraseblock layout is unknown. "
"Looking for another erase function.\n");
continue;
}
found = 1;
usable_erasefunctions--;
msg_cdbg("trying... ");
ret = walk_eraseregions(flash, k, &erase_and_write_block_helper, curcontents, newcontents);
msg_cdbg("\n");
......@@ -1500,6 +1519,8 @@ int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t
* The only difference is whether the reason for other unusable
* functions is printed or not. If in doubt, verbosity wins.
*/
if (!usable_erasefunctions)
continue;
if (flash->read(flash, curcontents, 0, size)) {
/* Now we are truly screwed. Read failed as well. */
msg_cerr("Can't read anymore!\n");
......@@ -1511,10 +1532,6 @@ int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t
}
/* Free the scratchpad. */
free(curcontents);
if (!found) {
msg_cerr("ERROR: flashrom has no erase function for this flash chip.\n");
return 1;
}
if (ret) {
msg_cerr("FAILED!\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment