[flashrom] [PATCH] Improve error messages, protect the user

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Tue Aug 11 17:25:38 CEST 2009


Disallow erase/write for known bad chips so people won't try without a
clear understanding. If we want them to test, we can tell them to
patch/edit flashchips.c.

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.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: flashrom-errormessages/flashrom.c
===================================================================
--- flashrom-errormessages/flashrom.c	(Revision 676)
+++ flashrom-errormessages/flashrom.c	(Arbeitskopie)
@@ -221,6 +221,7 @@
 {
 	size_t size = flash->total_size * 1024;
 	/* Flash registers live 4 MByte below the flash. */
+	/* FIXME: This is incorrect for nonstandard flashbase. */
 	flash->virtual_registers = (chipaddr)programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
 }
 
@@ -475,6 +476,15 @@
 	return 0;
 }
 
+void emergency_help_message()
+{
+	fprintf(stderr, "Your flash chip is in an unknown state.\n"
+		"Get help on IRC at irc.freenode.net channel #flashrom or\n"
+		"mail flashrom at flashrom.org\n"
+		"------------------------------------------------------------\n"
+		"DO NOT REBOOT OR POWEROFF!\n");
+}
+
 void usage(const char *name)
 {
 	printf("usage: %s [-VfLzhR] [-E|-r file|-w file|-v file] [-c chipname]\n"
@@ -743,6 +753,7 @@
 				printf("Run flashrom -L to view the hardware supported in this flashrom version.\n");
 				exit(1);
 			}
+			printf("Please note that forced reads most likely contain garbage.\n");
 			return read_flash(flashes[0], filename);
 		}
 		// FIXME: flash writes stay enabled!
@@ -808,14 +819,31 @@
 	buf = (uint8_t *) calloc(size, sizeof(char));
 
 	if (erase_it) {
-		if (erase_flash(flash))
+		if (flash->tested & TEST_BAD_ERASE) {
+			fprintf(stderr, "Erase is not working on this chip. "
+				"Aborting.\n");
 			return 1;
+		}
+		if (erase_flash(flash)) {
+			emergency_help_message();
+			return 1;
+		}
 	} else if (read_it) {
 		if (read_flash(flash, filename))
 			return 1;
 	} else {
 		struct stat image_stat;
 
+		if (flash->tested & TEST_BAD_ERASE) {
+			fprintf(stderr, "Erase is not working on this chip "
+				"and erase is needed for write. Aborting.\n");
+			return 1;
+		}
+		if (flash->tested & TEST_BAD_WRITE) {
+			fprintf(stderr, "Write is not working on this chip. "
+				"Aborting.\n");
+			return 1;
+		}
 		if ((image = fopen(filename, "r")) == NULL) {
 			perror(filename);
 			exit(1);
@@ -854,14 +882,18 @@
 		ret = flash->write(flash, buf);
 		if (ret) {
 			fprintf(stderr, "FAILED!\n");
+			emergency_help_message();
 			return 1;
 		} else {
 			printf("COMPLETE.\n");
 		}
 	}
 
-	if (verify_it)
+	if (verify_it) {
 		ret = verify_flash(flash, buf);
+		if (ret)
+			emergency_help_message();
+	}
 
 	programmer_shutdown();
 


-- 
http://www.hailfinger.org/





More information about the flashrom mailing list