Patchwork ichspi: fix missing set_addr and crossing of 256 boundary

login
register
about
Submitter Vladimir 'φ-coder/phcoder' Serbinenko
Date 2014-01-05 09:09:37
Message ID <52C92151.1070105@gmail.com>
Download mbox | patch
Permalink /patch/4105/
State Superseded
Headers show

Comments

Accoring to PCH documentation crossing 256-byte boundary is invalid and
causes wraparound. Please apply attached patch

Patch

Index: ichspi.c
===================================================================
--- ichspi.c	(revision 1764)
+++ ichspi.c	(working copy)
@@ -1272,6 +1272,7 @@ 
 	}
 
 	msg_pdbg("Erasing %d bytes starting at 0x%06x.\n", len, addr);
+	ich_hwseq_set_addr(addr);
 
 	/* make sure FDONE, FCERR, AEL are cleared by writing 1 to them */
 	REGWRITE16(ICH9_REG_HSFS, REGREAD16(ICH9_REG_HSFS));
@@ -1308,6 +1309,9 @@ 
 
 	while (len > 0) {
 		block_len = min(len, flash->pgm->opaque.max_data_read);
+		if (block_len > (~addr & 0xff))
+			block_len = (~addr & 0xff) + 1;
+
 		ich_hwseq_set_addr(addr);
 		hsfc = REGREAD16(ICH9_REG_HSFC);
 		hsfc &= ~HSFC_FCYCLE; /* set read operation */
@@ -1347,6 +1351,8 @@ 
 	while (len > 0) {
 		ich_hwseq_set_addr(addr);
 		block_len = min(len, flash->pgm->opaque.max_data_write);
+		if (block_len > (~addr & 0xff))
+			block_len = (~addr & 0xff) + 1;
 		ich_fill_data(buf, block_len, ICH9_REG_FDATA0);
 		hsfc = REGREAD16(ICH9_REG_HSFC);
 		hsfc &= ~HSFC_FCYCLE; /* clear operation */