Hi,
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 :-)

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.

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).

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:

Invocation: flashrom -p ft2232_spi:type=4232H,port=A -r /tmp/foo.bin

Successful 256-byte read:
writecnt: 4, writearr: 03 02 c3 00     <--- SPI command. 03 indicates read, 02 c3 00 is the address.
getting buffer from ftdi...
usb_bulk_read ret: 258
"offset" from ftdi_read_data(): 256
get_buf returned with 0

A troubled 256-byte read follows:
writecnt: 4, writearr: 03 02 c4 00 
getting buffer from ftdi...
usb_bulk_read ret: 45                  <--- (45-2) + (142-2) + (75-2) = 256
usb_bulk_read ret: 142
usb_bulk_read ret: 75
"offset" from ftdi_read_data(): 256
get_buf returned with 0

And now it simply fails to read anything:
writecnt: 4, writearr: 03 02 c5 00 
getting buffer from ftdi...
usb_bulk_read ret: 211                 <--- returns 209 data bytes
usb_bulk_read ret: 2                   <--- fails to read any more data bytes
"offset" from ftdi_read_data(): 209
usb_bulk_read ret: 2
get_buf: no data was available
"offset" from ftdi_read_data(): 0
usb_bulk_read ret: 2

libftdi's ftdi_read_data() will loop indefinitely here until the remaining data bytes arrive, which never happens.

Any ideas on what could be causing this are appreciated!

--
David Hendricks (dhendrix)
Systems Software Engineer, Google Inc.