summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/flashrom.c b/flashrom.c
index e5e334c..2cf8075 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1509,6 +1509,7 @@ int main(int argc, char *argv[])
/* This function signature is horrible. We need to design a better interface,
* but right now it allows us to split off the CLI code.
+ * Besides that, the function itself is a textbook example of abysmal code flow.
*/
int doit(struct flashchip *flash, int force, char *filename, int read_it, int write_it, int erase_it, int verify_it)
{
@@ -1563,12 +1564,7 @@ int doit(struct flashchip *flash, int force, char *filename, int read_it, int wr
programmer_shutdown();
return 1;
}
- } else {
- struct stat image_stat;
-
- if (flash->unlock)
- flash->unlock(flash);
-
+ } else if (write_it) {
if (flash->tested & TEST_BAD_ERASE) {
msg_cerr("Erase is not working on this chip "
"and erase is needed for write. ");
@@ -1590,6 +1586,18 @@ int doit(struct flashchip *flash, int force, char *filename, int read_it, int wr
msg_cerr("Continuing anyway.\n");
}
}
+ if (!flash->write) {
+ msg_cerr("Error: flashrom has no write function for this flash chip.\n");
+ programmer_shutdown();
+ return 1;
+ }
+ if (flash->unlock)
+ flash->unlock(flash);
+
+ }
+ if (write_it || verify_it) {
+ struct stat image_stat;
+
if ((image = fopen(filename, "rb")) == NULL) {
perror(filename);
programmer_shutdown();
@@ -1625,12 +1633,12 @@ int doit(struct flashchip *flash, int force, char *filename, int read_it, int wr
// ////////////////////////////////////////////////////////////
if (write_it) {
- msg_cinfo("Writing flash chip... ");
- if (!flash->write) {
- msg_cerr("Error: flashrom has no write function for this flash chip.\n");
+ if (erase_flash(flash)) {
+ emergency_help_message();
programmer_shutdown();
return 1;
}
+ msg_cinfo("Writing flash chip... ");
ret = flash->write(flash, buf);
if (ret) {
msg_cerr("FAILED!\n");
OpenPOWER on IntegriCloud