Hi,<div>I'm using Flashrom with an FTDI FT4232H to read a 1MB SPI ROM (w25q80), but am encountering difficulties. I believe we may be missing some steps in ft2232_spi_init(), however I don't have much experience with libftdi or usb debugging so I hope someone on the list does :-)</div>

<div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>When the programmer is plugged into a "full-speed" USB port slow, things seem to work well. However, when plugged into a "high-speed" port, bytes simply disappear. There does not seem to be a pattern with regard to where the problems start. Sometimes it will fail very early and Flashrom will not be able to detect the chip. Sometimes we'll get lucky and we can read the full chip. It can fail anywhere in between.</div>

<div><br></div><div>The only pattern I've seen is that usb bulk reads return less than the requested number of bytes before it fails entirely. For example, if we request 256 bytes, then it might return 256-N data bytes. libftdi will request the remaining bytes, and libusb will provide the remaining N data bytes. On the next 256-byte request, libusb will not return any data bytes (only the 2-byte USB header).</div>

<div><br></div><div>I added a bunch of debug prints to libftdi and libusb to get a better idea of what's happening deeper in the stack. Here is a sample of what we see (with added comments) when it fails:</div></div>
<div>
<font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div>Invocation: <span class="Apple-style-span" style="font-family: 'courier new', monospace; ">flashrom -p ft2232_spi:type=4232H,port=A -r /tmp/foo.bin</span></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><span class="Apple-style-span" style="font-family: 'courier new', monospace; "><br>

</span></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace">Successful 256-byte read:</font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">writecnt: 4, writearr: 03 02 c3 00     <--- SPI command. 03 indicates read, 02 c3 00 is the address.</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">getting buffer from ftdi...</font></div><div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 258</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">"offset" from ftdi_read_data(): 256</font></div><div><font class="Apple-style-span" face="'courier new', monospace">get_buf returned with 0</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">A troubled 256-byte read follows:</font></div><div>
<span class="Apple-style-span" style="font-family: 'courier new', monospace; ">writecnt: 4, writearr: 03 02 c4 00 </span></div>
<div><font class="Apple-style-span" face="'courier new', monospace">getting buffer from ftdi...</font></div><div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 45</font><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">                  <--- (45-2) + (142-2) + (75-2) = 256</span></div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 142</font></div><div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 75</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">"offset" from ftdi_read_data(): 256</font></div><div><font class="Apple-style-span" face="'courier new', monospace">get_buf returned with 0</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">And now it simply fails to read anything:</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">writecnt: 4, writearr: 03 02 c5 00 </font></div><div><font class="Apple-style-span" face="'courier new', monospace">getting buffer from ftdi...</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 211                 </font><span class="Apple-style-span" style="font-family: 'courier new', monospace; "><--- returns 209 data bytes</span></div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 2                   </font><span class="Apple-style-span" style="font-family: 'courier new', monospace; "><--- fails to read any more data bytes</span></div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">"offset" from ftdi_read_data(): 209</font></div><div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 2</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">get_buf: no data was available</font></div><div><font class="Apple-style-span" face="'courier new', monospace">"offset" from ftdi_read_data(): 0</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">usb_bulk_read ret: 2</font></div></div><div><br></div><div>libftdi's ftdi_read_data() will loop indefinitely here until the remaining data bytes arrive, which never happens.</div>

<div><br></div><div>Any ideas on what could be causing this are appreciated!</div><div><br></div><div>-- <br>David Hendricks (dhendrix)<br>Systems Software Engineer, Google Inc.<br>
</div>