On Thu, 30 Jun 2011 22:26:25 +0200 Stefan Tauner <[email protected]> wrote:
> > appended is my current version. now. -- Kind regards/Mit freundlichen Grüßen, Stefan Tauner
>From 3c2c9a665bfba14799974eaa2a93b2aad4a1528a Mon Sep 17 00:00:00 2001 From: Stefan Tauner <[email protected]> Date: Thu, 30 Jun 2011 22:36:00 +0200 Subject: [PATCH] add count_usable_erasers which returns the number of well-defined erasers for a chip This can be used in various situations (including one in the upcoming SFDP patch) and removes one FIXME in current HEAD. Needed to add a declaration of check_block_eraser. Signed-off-by: Stefan Tauner <[email protected]> --- flashrom.c | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-) diff --git a/flashrom.c b/flashrom.c index 13d398e..10035c4 100644 --- a/flashrom.c +++ b/flashrom.c @@ -465,6 +465,8 @@ struct shutdown_func_data { */ static int may_register_shutdown = 0; +static int check_block_eraser(const struct flashchip *flash, int k, int log); + /* Register a function to be executed on programmer shutdown. * The advantage over atexit() is that you can supply a void pointer which will * be used as parameter to the registered function upon programmer shutdown. @@ -711,6 +713,19 @@ char *extract_programmer_param(const char *param_name) return extract_param(&programmer_param, param_name, ","); } +/* Returns the number of well-defined erasers for a chip. + * The log parameter controls output. */ +static unsigned int count_usable_erasers(const struct flashchip *flash, int log) +{ + unsigned int usable_erasefunctions = 0; + int k; + for (k = 0; k < NUM_ERASEFUNCTIONS; k++) { + if (!check_block_eraser(flash, k, 0)) + usable_erasefunctions++; + } + return usable_erasefunctions; +} + /* start is an offset to the base address of the flash chip */ int check_erased_range(struct flashchip *flash, int start, int len) { @@ -1466,7 +1481,7 @@ static int walk_eraseregions(struct flashchip *flash, int erasefunction, return 0; } -static int check_block_eraser(struct flashchip *flash, int k, int log) +static int check_block_eraser(const struct flashchip *flash, int k, int log) { struct block_eraser eraser = flash->block_erasers[k]; @@ -1495,11 +1510,8 @@ int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t int k, ret = 0; uint8_t *curcontents; unsigned long size = flash->total_size * 1024; - int usable_erasefunctions = 0; + unsigned int usable_erasefunctions = count_usable_erasers(flash, 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 " @@ -1818,13 +1830,13 @@ int chip_safety_check(struct flashchip *flash, int force, int read_it, int write } if (erase_it || write_it) { /* Write needs erase. */ - if (flash->tested & TEST_BAD_ERASE) { + if (flash->tested & TEST_BAD_ERASE || + !count_usable_erasers(flash, 0)) { msg_cerr("Erase is not working on this chip. "); if (!force) return 1; msg_cerr("Continuing anyway.\n"); } - /* FIXME: Check if at least one erase function exists. */ } if (write_it) { if (flash->tested & TEST_BAD_WRITE) { -- 1.7.1
_______________________________________________ flashrom mailing list [email protected] http://www.flashrom.org/mailman/listinfo/flashrom
