[flashrom] [PATCH] Fix parallel-style programmer access from SPI

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Thu Mar 1 23:15:34 CET 2012


Third time's a charm.

Michael Karcher pointed out that I had inexplicably overlooked wbsio.

Fix parallel-style programmer access from ITE IT87/Winbond W83627 SPI

The ITE IT87 SPI driver uses a trick to speed up reading and writing:
If a flash chip is 512 kByte or less, the flash chip can be completely
mapped in memory and both read and write accesses are faster that way.
The current IT87 SPI code did use the parallel programmer interface for
memory mapped reads and writes, but that's the wrong abstraction. It has
been fixed to use mmio_read*/mmio_write* for that purpose.

The Winbond W83627 SPI driver uses the same trick in its read path for
all supported chip sizes. Fix it the same way.

Switch internal_chip_readn to use mmio_readn as proper abstraction.

Kudos to Michael Karcher for spotting the bugs.

Reported-by: Johan Svensson <flashrom.js at crypt.se>
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Acked-by: Michael Karcher <flashrom at mkarcher.dialup.fu-berlin.de>
Tested-by: Johan Svensson <flashrom.js at crypt.se>

Index: flashrom-fix_par_programmer_access_from_spi/hwaccess.c
===================================================================
--- flashrom-fix_par_programmer_access_from_spi/hwaccess.c	(Revision 1510)
+++ flashrom-fix_par_programmer_access_from_spi/hwaccess.c	(Arbeitskopie)
@@ -169,6 +169,12 @@
 	return *(volatile uint32_t *) addr;
 }
 
+void mmio_readn(void *addr, uint8_t *buf, size_t len)
+{
+	memcpy(buf, addr, len);
+	return;
+}
+
 void mmio_le_writeb(uint8_t val, void *addr)
 {
 	mmio_writeb(cpu_to_le8(val), addr);
Index: flashrom-fix_par_programmer_access_from_spi/it87spi.c
===================================================================
--- flashrom-fix_par_programmer_access_from_spi/it87spi.c	(Revision 1510)
+++ flashrom-fix_par_programmer_access_from_spi/it87spi.c	(Arbeitskopie)
@@ -330,7 +330,7 @@
 	OUTB(0x06, it8716f_flashport + 1);
 	OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport);
 	for (i = 0; i < flash->page_size; i++)
-		chip_writeb(flash, buf[i], bios + start + i);
+		mmio_writeb(buf[i], (void *)(bios + start + i));
 	OUTB(0, it8716f_flashport);
 	/* Wait until the Write-In-Progress bit is cleared.
 	 * This usually takes 1-10 ms, so wait in 1 ms steps.
@@ -356,7 +356,7 @@
 	if ((flash->total_size * 1024 > 512 * 1024)) {
 		spi_read_chunked(flash, buf, start, len, 3);
 	} else {
-		read_memmapped(flash, buf, start, len);
+		mmio_readn((void *)(flash->virtual_memory + start), buf, len);
 	}
 
 	return 0;
Index: flashrom-fix_par_programmer_access_from_spi/internal.c
===================================================================
--- flashrom-fix_par_programmer_access_from_spi/internal.c	(Revision 1510)
+++ flashrom-fix_par_programmer_access_from_spi/internal.c	(Arbeitskopie)
@@ -387,6 +387,6 @@
 static void internal_chip_readn(const struct flashctx *flash, uint8_t *buf,
 				const chipaddr addr, size_t len)
 {
-	memcpy(buf, (void *)addr, len);
+	mmio_readn((void *)addr, buf, len);
 	return;
 }
Index: flashrom-fix_par_programmer_access_from_spi/wbsio_spi.c
===================================================================
--- flashrom-fix_par_programmer_access_from_spi/wbsio_spi.c	(Revision 1510)
+++ flashrom-fix_par_programmer_access_from_spi/wbsio_spi.c	(Arbeitskopie)
@@ -202,7 +202,8 @@
 static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf,
 			  unsigned int start, unsigned int len)
 {
-	return read_memmapped(flash, buf, start, len);
+	mmio_readn((void *)(flash->virtual_memory + start), buf, len);
+	return 0;
 }
 
 #endif
Index: flashrom-fix_par_programmer_access_from_spi/programmer.h
===================================================================
--- flashrom-fix_par_programmer_access_from_spi/programmer.h	(Revision 1510)
+++ flashrom-fix_par_programmer_access_from_spi/programmer.h	(Arbeitskopie)
@@ -312,6 +312,7 @@
 uint8_t mmio_readb(void *addr);
 uint16_t mmio_readw(void *addr);
 uint32_t mmio_readl(void *addr);
+void mmio_readn(void *addr, uint8_t *buf, size_t len);
 void mmio_le_writeb(uint8_t val, void *addr);
 void mmio_le_writew(uint16_t val, void *addr);
 void mmio_le_writel(uint32_t val, void *addr);


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





More information about the flashrom mailing list