diff options
Diffstat (limited to 'flashrom.c')
-rw-r--r-- | flashrom.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/flashrom.c b/flashrom.c index 5bf9645c9..12a51ad00 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) { @@ -1467,7 +1482,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]; @@ -1496,18 +1511,9 @@ 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 " - "chip.\n"); - return 1; - } - curcontents = (uint8_t *) malloc(size); /* Copy oldcontents to curcontents to avoid clobbering oldcontents. */ memcpy(curcontents, oldcontents, size); @@ -1825,7 +1831,11 @@ int chip_safety_check(struct flashchip *flash, int force, int read_it, int write return 1; msg_cerr("Continuing anyway.\n"); } - /* FIXME: Check if at least one erase function exists. */ + if(count_usable_erasers(flash, 0) == 0) { + msg_cerr("flashrom has no erase function for this " + "flash chip.\n"); + return 1; + } } if (write_it) { if (flash->tested & TEST_BAD_WRITE) { |