Introduce proper error checking for SPI programming

Corresponding to flashrom svn r739.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
diff --git a/sb600spi.c b/sb600spi.c
index 5965b3b..87f1cc1 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -48,9 +48,9 @@
 /* FIXME: SB600 can write 5 bytes per transaction. */
 int sb600_spi_write_1(struct flashchip *flash, uint8_t *buf)
 {
-	int rc = 0, i;
+	int i;
 	int total_size = flash->total_size * 1024;
-	int result;
+	int result = 0;
 
 	spi_disable_blockprotect();
 	/* Erase first */
@@ -63,10 +63,10 @@
 
 	printf("Programming flash");
 	for (i = 0; i < total_size; i++, buf++) {
-		result = spi_byte_program(i, *buf);
+		result = spi_nbyte_program(i, buf, 1);
 		if (result) {
-			// spi_byte_program reported the error for us already
-			printf_debug("... continuing anyway.\n");
+			fprintf(stderr, "Write error!\n");
+			return result;
 		}
 
 		/* wait program complete. */
@@ -76,7 +76,7 @@
 			;
 	}
 	printf(" done.\n");
-	return rc;
+	return result;
 }
 
 static void reset_internal_fifo_pointer(void)
diff --git a/spi.c b/spi.c
index 8b3f6d9..cfb6966 100644
--- a/spi.c
+++ b/spi.c
@@ -970,7 +970,7 @@
 int spi_chip_write_1(struct flashchip *flash, uint8_t *buf)
 {
 	int total_size = 1024 * flash->total_size;
-	int i;
+	int i, result = 0;
 
 	spi_disable_blockprotect();
 	/* Erase first */
@@ -981,7 +981,9 @@
 	}
 	printf("done.\n");
 	for (i = 0; i < total_size; i++) {
-		spi_byte_program(i, buf[i]);
+		result = spi_byte_program(i, buf[i]);
+		if (result)
+			return 1;
 		while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
 			programmer_delay(10);
 	}