Don't assume flash is accessible via MMIO for chips with no read function

Flashrom assumes that the flash chip contents are available via mmap if
no read function is defined.

This special case is handled in lots of places all over the code.

Remove the special case and use the read_memmapped function. Not only
does this allow us to fix a read bug in flashrom I recently uncovered on
ICH SPI, it also allows us to add support for Paraflasher to flashrom.

Corresponding to flashrom svn r473.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/flash.h b/flash.h
index b8f4ca7..f5dea55 100644
--- a/flash.h
+++ b/flash.h
@@ -539,6 +539,7 @@
 extern int verbose;
 #define printf_debug(x...) { if (verbose) printf(x); }
 void map_flash_registers(struct flashchip *flash);
+int read_memmapped(struct flashchip *flash, uint8_t *buf);
 
 /* layout.c */
 int show_id(uint8_t *bios, int size, int force);
diff --git a/flashchips.c b/flashchips.c
index c3d2635..8ec0845 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -48,6 +48,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_en29f002a,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -61,6 +62,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_en29f002a,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -74,6 +76,7 @@
 		.probe		= probe_29f040b,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -87,6 +90,7 @@
 		.probe		= probe_29f040b,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -100,6 +104,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -113,6 +118,7 @@
 		.probe		= probe_29f040b,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -126,6 +132,7 @@
 		.probe		= probe_29f040b,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -139,6 +146,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -377,6 +385,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -390,6 +399,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -529,6 +539,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -542,6 +553,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -569,6 +581,7 @@
 		.probe		= probe_29f002,
 		.erase		= erase_29f002,
 		.write		= write_29f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -582,6 +595,7 @@
 		.probe		= probe_29f002,
 		.erase		= erase_29f002,
 		.write		= write_29f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -595,6 +609,7 @@
 		.probe		= probe_29f040b,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -608,6 +623,7 @@
 		.probe		= probe_49fl00x,
 		.erase		= erase_49fl00x,
 		.write		= write_49fl00x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -621,6 +637,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -634,6 +651,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_en29f002a,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -647,6 +665,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_en29f002a,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -660,6 +679,7 @@
 		.probe		= probe_jedec,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -673,6 +693,7 @@
 		.probe		= probe_jedec,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -686,6 +707,7 @@
 		.probe		= probe_m29f400bt,
 		.erase		= erase_m29f400bt,
 		.write		= write_coreboot_m29f400bt,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -699,6 +721,7 @@
 		.probe		= probe_m29f400bt,
 		.erase		= erase_m29f400bt,
 		.write		= write_coreboot_m29f400bt,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -712,6 +735,7 @@
 		.probe		= probe_82802ab,
 		.erase		= erase_82802ab,
 		.write		= write_82802ab,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -725,6 +749,7 @@
 		.probe		= probe_82802ab,
 		.erase		= erase_82802ab,
 		.write		= write_82802ab,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -892,6 +917,7 @@
 		.probe		= probe_29f002,
 		.erase		= erase_29f002,
 		.write		= write_29f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -905,6 +931,7 @@
 		.probe		= probe_29f002,
 		.erase		= erase_29f002,
 		.write		= write_29f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -918,6 +945,7 @@
 		.probe		= probe_29f002,
 		.erase		= erase_29f002,
 		.write		= write_29f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1085,6 +1113,7 @@
 		.probe		= probe_49fl00x,
 		.erase		= erase_49fl00x,
 		.write		= write_49fl00x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1098,6 +1127,7 @@
 		.probe		= probe_49fl00x,
 		.erase		= erase_49fl00x,
 		.write		= write_49fl00x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1111,6 +1141,7 @@
 		.probe		= probe_lhf00l04,
 		.erase		= erase_lhf00l04,
 		.write		= write_lhf00l04,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1222,6 +1253,7 @@
 		.probe		= probe_28sf040,
 		.erase		= erase_28sf040,
 		.write		= write_28sf040,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1235,6 +1267,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1248,6 +1281,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1261,6 +1295,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1274,6 +1309,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1287,6 +1323,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1300,6 +1337,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1313,6 +1351,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1326,6 +1365,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1339,6 +1379,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1352,6 +1393,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1365,6 +1407,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1378,6 +1421,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1391,6 +1435,7 @@
 		.probe		= probe_sst_fwhub,
 		.erase		= erase_sst_fwhub,
 		.write		= write_sst_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1404,6 +1449,7 @@
 		.probe		= probe_sst_fwhub,
 		.erase		= erase_sst_fwhub,
 		.write		= write_sst_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1417,6 +1463,7 @@
 		.probe		= probe_sst_fwhub,
 		.erase		= erase_sst_fwhub,
 		.write		= write_sst_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1430,6 +1477,7 @@
 		.probe		= probe_49lfxxxc,
 		.erase		= erase_49lfxxxc,
 		.write		= write_49lfxxxc,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1443,6 +1491,7 @@
 		.probe		= probe_sst_fwhub,
 		.erase		= erase_sst_fwhub,
 		.write		= write_sst_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1456,6 +1505,7 @@
 		.probe		= probe_49lfxxxc,
 		.erase		= erase_49lfxxxc,
 		.write		= write_49lfxxxc,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1469,6 +1519,7 @@
 		.probe		= probe_49lfxxxc,
 		.erase		= erase_49lfxxxc,
 		.write		= write_49lfxxxc,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1482,6 +1533,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_49lf040,
 		.write		= write_49lf040,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1495,6 +1547,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_49lf040,
 		.write		= write_49lf040,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1508,6 +1561,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_49lf040,
 		.write		= write_49lf040,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1521,6 +1575,7 @@
 		.probe		= probe_sst_fwhub,
 		.erase		= erase_sst_fwhub,
 		.write		= write_sst_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1534,6 +1589,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_49lf040,
 		.write		= write_49lf040,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1547,6 +1603,7 @@
 		.probe		= probe_49lfxxxc,
 		.erase		= erase_49lfxxxc,
 		.write		= write_49lfxxxc,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1700,6 +1757,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_m29f002,
 		.write		= write_m29f002b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1713,6 +1771,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_m29f002,
 		.write		= write_m29f002t,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1726,6 +1785,7 @@
 		.probe		= probe_29f040b,
 		.erase		= erase_29f040b,
 		.write		= write_29f040b,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1739,6 +1799,7 @@
 		.probe		= probe_m29f400bt,
 		.erase		= erase_m29f400bt,
 		.write		= write_coreboot_m29f400bt,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1752,6 +1813,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1765,6 +1827,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1778,6 +1841,7 @@
 		.probe		= probe_stm50flw0x0x,
 		.erase		= erase_stm50flw0x0x,
 		.write		= write_stm50flw0x0x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1791,6 +1855,7 @@
 		.probe		= probe_stm50flw0x0x,
 		.erase		= erase_stm50flw0x0x,
 		.write		= write_stm50flw0x0x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1804,6 +1869,7 @@
 		.probe		= probe_stm50flw0x0x,
 		.erase		= erase_stm50flw0x0x,
 		.write		= write_stm50flw0x0x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1817,6 +1883,7 @@
 		.probe		= probe_stm50flw0x0x,
 		.erase		= erase_stm50flw0x0x,
 		.write		= write_stm50flw0x0x,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1830,6 +1897,7 @@
 		.probe		= probe_49lfxxxc,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1843,6 +1911,7 @@
 		.probe		= probe_82802ab,
 		.erase		= erase_82802ab,
 		.write		= write_82802ab,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1856,6 +1925,7 @@
 		.probe		= probe_82802ab,
 		.erase		= erase_82802ab,
 		.write		= write_82802ab,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1869,6 +1939,7 @@
 		.probe		= probe_82802ab,
 		.erase		= erase_82802ab,
 		.write		= write_82802ab,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1882,6 +1953,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1895,6 +1967,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1908,6 +1981,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1921,6 +1995,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -1934,6 +2009,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2003,6 +2079,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2016,6 +2093,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2029,6 +2107,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2042,6 +2121,7 @@
 		.probe		= probe_w29ee011,
 		.erase		= erase_chip_jedec,
 		.write		= write_jedec,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2055,6 +2135,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2068,6 +2149,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2081,6 +2163,7 @@
 		.probe		= probe_w39v040c,
 		.erase		= erase_w39v040c,
 		.write		= write_w39v040c,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2094,6 +2177,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2107,6 +2191,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_39sf020,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2120,6 +2205,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2133,6 +2219,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2146,6 +2233,7 @@
 		.probe		= probe_jedec,
 		.erase		= erase_chip_jedec,
 		.write		= write_49f002,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2159,6 +2247,7 @@
 		.probe		= probe_winbond_fwhub,
 		.erase		= erase_winbond_fwhub,
 		.write		= write_winbond_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2172,6 +2261,7 @@
 		.probe		= probe_winbond_fwhub,
 		.erase		= erase_winbond_fwhub,
 		.write		= write_winbond_fwhub,
+		.read		= read_memmapped,
 	},
 
 	{
@@ -2185,6 +2275,7 @@
 		.probe		= probe_spi_rdid,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= NULL,
 	},
 
 	{
@@ -2198,6 +2289,7 @@
 		.probe		= probe_spi_rdid,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= NULL,
 	},
 
 	{
@@ -2211,6 +2303,7 @@
 		.probe		= probe_spi_rdid,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= NULL,
 	},
 
 	{
@@ -2224,6 +2317,7 @@
 		.probe		= probe_spi_rdid,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= NULL,
 	},
 
 	{
@@ -2237,6 +2331,7 @@
 		.probe		= probe_spi_rdid,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= NULL,
 	},
 
 	{
@@ -2250,6 +2345,7 @@
 		.probe		= probe_spi_rdid,
 		.erase		= NULL,
 		.write		= NULL,
+		.read		= NULL,
 	},
 
 	{ NULL 	}
diff --git a/flashrom.c b/flashrom.c
index 2a5f1b3..68ef8f0 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2000 Silicon Integrated System Corporation
  * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com>
  * Copyright (C) 2005-2008 coresystems GmbH 
+ * Copyright (C) 2008,2009 Carl-Daniel Hailfinger
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -81,6 +82,18 @@
 	flash->virtual_registers = physmap("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
 }
 
+int read_memmapped(struct flashchip *flash, uint8_t *buf)
+{
+	int i;
+
+	/* We could do a memcpy as optimization if the flash is onboard */
+	//memcpy(buf, (const char *)flash->virtual_memory, flash->total_size * 1024);
+	for (i = 0; i < flash->total_size * 1024; i++)
+		buf[i] = chip_readb(flash->virtual_memory + i);
+		
+	return 0;
+}
+
 struct flashchip *probe_flash(struct flashchip *first_flash, int force)
 {
 	volatile uint8_t *bios;
@@ -145,9 +158,11 @@
 	int idx;
 	int total_size = flash->total_size * 1024;
 	uint8_t *buf2 = (uint8_t *) calloc(total_size, sizeof(char));
-	if (flash->read == NULL)
-		memcpy(buf2, (const char *)flash->virtual_memory, total_size);
-	else
+	if (!flash->read) {
+		printf("FAILED!\n");
+		fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+		return 1;
+	} else
 		flash->read(flash, buf2);
 
 	printf("Verifying flash... ");
@@ -191,9 +206,11 @@
 		exit(1);
 	}
 	printf("Reading flash... ");
-	if (flash->read == NULL)
-		memcpy(buf, (const char *)flash->virtual_memory, size);
-	else
+	if (!flash->read) {
+		printf("FAILED!\n");
+		fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+		return 1;
+	} else
 		flash->read(flash, buf);
 
 	if (exclude_end_position - exclude_start_position > 0)
@@ -219,11 +236,13 @@
 		fprintf(stderr, "ERROR: flashrom has no erase function for this flash chip.\n");
 		return 1;
 	}
-	flash->erase(flash);
-	if (NULL == flash->read)
-		memcpy(buf, (const char *)flash->virtual_memory, size);
-	else
+	if (!flash->read) {
+		printf("FAILED!\n");
+		fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+		return 1;
+	} else
 		flash->read(flash, buf);
+
 	for (erasedbytes = 0; erasedbytes < size; erasedbytes++)
 		if (0xff != buf[erasedbytes]) {
 			printf("FAILED!\n");
@@ -537,9 +556,11 @@
 				exit(1);
 			}
 			printf("Force reading flash... ");
-			if (!flashes[0]->read)
-				memcpy(buf, (const char *)flashes[0]->virtual_memory, size);
-			else
+			if (!flashes[0]->read) {
+				printf("FAILED!\n");
+				fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+				return 1;
+			} else
 				flashes[0]->read(flashes[0], buf);
 
 			if (exclude_end_position - exclude_start_position > 0)
@@ -648,6 +669,9 @@
 	 */
 
 	// ////////////////////////////////////////////////////////////
+	/* FIXME: This memcpy will not work for SPI nor external flashers.
+	 * Convert to chip_readb.
+	 */
 	if (exclude_end_position - exclude_start_position > 0)
 		memcpy(buf + exclude_start_position,
 		       (const char *)flash->virtual_memory +