Patchwork Improve error messages, protect the user

login
register
about
Submitter Carl-Daniel Hailfinger
Date 2009-08-11 15:25:38
Message ID <4A818D72.3090505@gmx.net>
Download mbox | patch
Permalink /patch/105/
State Superseded
Headers show

Comments

Carl-Daniel Hailfinger - 2009-08-11 15:25:38
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@gmx.net>
Stefan Reinauer - 2009-08-12 09:39:51
On 8/11/09 5:25 PM, Carl-Daniel Hailfinger wrote:

> +		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;
> +		}
>   

I would agree to this as long as there's a --force option

I think the IRC note should go to the documentation, not the code.

Patch

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@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();