summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2011-07-01 00:19:12 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2011-07-01 00:19:12 +0000
commit5368dca4363d35d4a67537fc03e1f5d417b87ce5 (patch)
tree726e6f6d0b1bff1252f29bea5d4456e64fead816 /flashrom.c
parent00155498a86e2c77ee6c08d274fa7954f38a56f6 (diff)
downloadflashrom-5368dca4363d35d4a67537fc03e1f5d417b87ce5.tar.gz
flashrom-5368dca4363d35d4a67537fc03e1f5d417b87ce5.tar.bz2
flashrom-5368dca4363d35d4a67537fc03e1f5d417b87ce5.zip
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>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c34
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) {