Skip to content

Commit 8ab49e7

Browse files
committed
Disallow erase/write for known bad chips so people won't try without a clear understanding
Allow override with --force. If write/erase failed, warn the user to get help and not shutdown/reboot the computer. Warn that the result of a forced read is often garbage. Too many users believed that a forced read meant that everything was fine. Wait 1 second between erase and verify. This fixes a few reports where verify directly after erase had unpleasant side effects like corrupting flash or at least getting incorrect verify results. Corresponding to flashrom svn r692. Signed-off-by: Carl-Daniel Hailfinger <[email protected]> Acked-by: Stefan Reinauer <[email protected]>
1 parent 3426ef6 commit 8ab49e7

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

flashrom.c

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ void map_flash_registers(struct flashchip *flash)
234234
{
235235
size_t size = flash->total_size * 1024;
236236
/* Flash registers live 4 MByte below the flash. */
237+
/* FIXME: This is incorrect for nonstandard flashbase. */
237238
flash->virtual_registers = (chipaddr)programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
238239
}
239240

@@ -488,6 +489,15 @@ int erase_flash(struct flashchip *flash)
488489
return 0;
489490
}
490491

492+
void emergency_help_message()
493+
{
494+
fprintf(stderr, "Your flash chip is in an unknown state.\n"
495+
"Get help on IRC at irc.freenode.net channel #flashrom or\n"
496+
497+
"------------------------------------------------------------\n"
498+
"DO NOT REBOOT OR POWEROFF!\n");
499+
}
500+
491501
void usage(const char *name)
492502
{
493503
const char *pname;
@@ -792,6 +802,7 @@ int main(int argc, char *argv[])
792802
printf("Run flashrom -L to view the hardware supported in this flashrom version.\n");
793803
exit(1);
794804
}
805+
printf("Please note that forced reads most likely contain garbage.\n");
795806
return read_flash(flashes[0], filename);
796807
}
797808
// FIXME: flash writes stay enabled!
@@ -857,14 +868,44 @@ int main(int argc, char *argv[])
857868
buf = (uint8_t *) calloc(size, sizeof(char));
858869

859870
if (erase_it) {
860-
if (erase_flash(flash))
871+
if (flash->tested & TEST_BAD_ERASE) {
872+
fprintf(stderr, "Erase is not working on this chip. ");
873+
if (!force) {
874+
fprintf(stderr, "Aborting.\n");
875+
return 1;
876+
} else {
877+
fprintf(stderr, "Continuing anyway.\n");
878+
}
879+
}
880+
if (erase_flash(flash)) {
881+
emergency_help_message();
861882
return 1;
883+
}
862884
} else if (read_it) {
863885
if (read_flash(flash, filename))
864886
return 1;
865887
} else {
866888
struct stat image_stat;
867889

890+
if (flash->tested & TEST_BAD_ERASE) {
891+
fprintf(stderr, "Erase is not working on this chip "
892+
"and erase is needed for write. ");
893+
if (!force) {
894+
fprintf(stderr, "Aborting.\n");
895+
return 1;
896+
} else {
897+
fprintf(stderr, "Continuing anyway.\n");
898+
}
899+
}
900+
if (flash->tested & TEST_BAD_WRITE) {
901+
fprintf(stderr, "Write is not working on this chip. ");
902+
if (!force) {
903+
fprintf(stderr, "Aborting.\n");
904+
return 1;
905+
} else {
906+
fprintf(stderr, "Continuing anyway.\n");
907+
}
908+
}
868909
if ((image = fopen(filename, "r")) == NULL) {
869910
perror(filename);
870911
exit(1);
@@ -903,14 +944,24 @@ int main(int argc, char *argv[])
903944
ret = flash->write(flash, buf);
904945
if (ret) {
905946
fprintf(stderr, "FAILED!\n");
947+
emergency_help_message();
906948
return 1;
907949
} else {
908950
printf("COMPLETE.\n");
909951
}
910952
}
911953

912-
if (verify_it)
954+
if (verify_it) {
955+
/* Work around chips which need some time to calm down. */
956+
if (write_it)
957+
programmer_delay(1000*1000);
913958
ret = verify_flash(flash, buf);
959+
/* If we tried to write, and now we don't properly verify, we
960+
* might have an emergency situation.
961+
*/
962+
if (ret && write_it)
963+
emergency_help_message();
964+
}
914965

915966
programmer_shutdown();
916967

0 commit comments

Comments
 (0)