diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-10-08 18:52:29 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-10-08 18:52:29 +0000 |
commit | f52f784bb300ec0acbd6c6bd9e6c3e5b435c4a90 (patch) | |
tree | 957964a468245432abbd23cd06839898b64105ce /flashrom.c | |
parent | 92c8b0cec2ed06db9c24c4d93cf38a596edf23ab (diff) | |
download | ast2050-flashrom-f52f784bb300ec0acbd6c6bd9e6c3e5b435c4a90.zip ast2050-flashrom-f52f784bb300ec0acbd6c6bd9e6c3e5b435c4a90.tar.gz |
Move implicit erase out of chip drivers
Flashrom had an implicit erase-on-write for most flash chip and
programmer drivers, but it was not entirely consistent.
Some drivers had their own hand-rolled partial update functionality
which made handling partial updates from generic code impossible.
Move implicit erase out of chip drivers, and kill some dead erase
functions at the same time. A full chip erase is now performed in the
generic code for all flash chips on write, and after that the whole chip
is written.
Corresponding to flashrom svn r1206.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r-- | flashrom.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -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"); |