mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Add count_usable_erasers which returns the number of well-defined erasers for a chip
It solves one FIXME and consequentially allows to remove a later check right now, and is used in the upcoming SFDP patch. Adds a forward declaration of check_block_eraser. Corresponding to flashrom svn r1358. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
00155498a8
commit
5368dca436
34
flashrom.c
34
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user