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!
Hi,
Am 26.04.2011 00:43 schrieb David Hendricks:
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).
This is a known problem which may happen with older (>6 months) libftdi and/or older kernels (>6 months) and/or older libusb. The libftdi mailing list probably has more information. If you can reproduce the issue with a recent kernel (2.6.36 or newer) and recent libusb and libftdi from git, please tell the libftdi mailing list. IIRC some flashrom patch (sent in the last 6 months or so) tried to make sure that such issues are worked around in flashrom by requiring recent libftdi and by setting a parameter which reduces the likelihood of that event. Sorry, I don't have more details handy right now.
Regards, Carl-Daniel
On Mon, Apr 25, 2011 at 5:53 PM, Carl-Daniel Hailfinger < c-d.hailfinger.devel.2006@gmx.net> wrote:
Hi,
Am 26.04.2011 00:43 schrieb David Hendricks:
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).
This is a known problem which may happen with older (>6 months) libftdi and/or older kernels (>6 months) and/or older libusb. The libftdi mailing list probably has more information. If you can reproduce the issue with a recent kernel (2.6.36 or newer) and recent libusb and libftdi from git, please tell the libftdi mailing list. IIRC some flashrom patch (sent in the last 6 months or so) tried to make sure that such issues are worked around in flashrom by requiring recent libftdi and by setting a parameter which reduces the likelihood of that event. Sorry, I don't have more details handy right now.
Quick follow up -- I got a chance to try flashrom out with the FT4232H out on machine with a 2.6.38 kernel and it worked great, EHCI high speed and all :-)
Thanks for the pointer!