Carl,<br>I downloaded a clean copy from SVN and patched it.  I pulled 4 reads without verbose and 4 with, they are attached.  The reads came back different each time just as before, but I did not get any error messages so this must be a libftdi issue.  Let me know if there's more I can do.<br>
Jeremy<br><br><div class="gmail_quote">On Mon, Nov 9, 2009 at 10:07 PM, Carl-Daniel Hailfinger <span dir="ltr"><<a href="mailto:c-d.hailfinger.devel.2006@gmx.net">c-d.hailfinger.devel.2006@gmx.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Pretty much everybody who used the FT2232 SPI driver in flashrom had<br>
problems with incorrect reads from time to time.<br>
One reason was that the hardware is pretty timing sensitive even for reads.<br>
<br>
The other reason was that the code silently ignored errors. This patch<br>
doesn't add any error recovery, but it will emit error messages if<br>
FT2232 communication goes wrong. That allows us to track down errors<br>
without investing hours in driver debugging.<br>
<br>
Jeremy, I'd be very interested in the results of an unmodified flashrom<br>
with only this patch applied (read is sufficient). In theory, you should<br>
either get a working read or loads of error messages about<br>
send_buf/read_buf. If you get no error messages and the image read is<br>
still wrong, libftdi doesn't tell us about the problem. Oh, and please<br>
try in verbose and normal mode. Maybe there's a difference.<br>
<br>
This patch will show up at<br>
<a href="http://patchwork.coreboot.org/project/flashrom/list/" target="_blank">http://patchwork.coreboot.org/project/flashrom/list/</a> in a few minutes.<br>
<br>
Signed-off-by: Carl-Daniel Hailfinger <<a href="mailto:c-d.hailfinger.devel.2006@gmx.net">c-d.hailfinger.devel.2006@gmx.net</a>><br>
<br>
Index: flashrom-ft2232_errorcheck/ft2232_spi.c<br>
===================================================================<br>
--- flashrom-ft2232_errorcheck/ft2232_spi.c     (Revision 756)<br>
+++ flashrom-ft2232_errorcheck/ft2232_spi.c     (Arbeitskopie)<br>
@@ -198,7 +198,8 @@<br>
 {<br>
        struct ftdi_context *ftdic = &ftdic_context;<br>
        static unsigned char *buf = NULL;<br>
-       int i = 0, ret = 0;<br>
+       /* failed is special. We use bitwise ops, but it is essentially bool. */<br>
+       int i = 0, ret = 0, failed = 0;<br>
<br>
        if (writecnt > 65536 || readcnt > 65536)<br>
                return SPI_INVALID_LENGTH;<br>
@@ -237,6 +238,11 @@<br>
                buf[i++] = (readcnt - 1) & 0xff;<br>
                buf[i++] = ((readcnt - 1) >> 8) & 0xff;<br>
                ret = send_buf(ftdic, buf, i);<br>
+               failed = ret;<br>
+               /* We can't abort here, we still have to deassert CS#. */<br>
+               if (ret)<br>
+                       fprintf(stderr, "send_buf failed before read: %i\n",<br>
+                               ret);<br>
                i = 0;<br>
                if (ret == 0) {<br>
                        /*<br>
@@ -245,6 +251,10 @@<br>
                         * command. We may be scheduled out etc.<br>
                         */<br>
                        ret = get_buf(ftdic, readarr, readcnt);<br>
+                       failed |= ret;<br>
+                       /* We can't abort here either. */<br>
+                       if (ret)<br>
+                               fprintf(stderr, "get_buf failed: %i\n", ret);<br>
                }<br>
        }<br>
<br>
@@ -252,10 +262,12 @@<br>
        buf[i++] = SET_BITS_LOW;<br>
        buf[i++] = CS_BIT;<br>
        buf[i++] = 0x0b;<br>
-       if (send_buf(ftdic, buf, i))<br>
-               return -1;<br>
+       ret = send_buf(ftdic, buf, i);<br>
+       failed |= ret;<br>
+       if (ret)<br>
+               fprintf(stderr, "send_buf failed at end: %i\n", ret);<br>
<br>
-       return ret;<br>
+       return failed ? -1 : 0;<br>
 }<br>
<br>
 int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)<br>
<font color="#888888"><br>
<br>
--<br>
Developer quote of the week:<br>
"We are juggling too many chainsaws and flaming arrows and tigers."<br>
<br>
</font></blockquote></div><br>