Hey Ian,
thanks for thinking of me and of the needs flashrom has.
ian wrote:Some reported problems with flashrom and the latest firmware. I tested it but didn't have any problems.
Do you have a link to reports? I only heard rumors, but never saw any logs.
There is a known problem with having to reset the Bus Pirate after a flashrom run. I have diagnosed that problem and it's essentially a side effect of the "send 0x00 twenty times to enter bitbang mode". flashrom exits binary SPI mode and raw bitbang mode on regular shutdown until the Bus Pirate is in regular user terminal mode again, but flashrom can't do this if it is killed by the user. On the next flashrom run flashrom will send 0x00 twenty times again, but it will get boatloads of "BBIO1" responses instead of just one response. flashrom can deal with that as well by running a "flush serial line buffer" command, BUT flushing actually does not work reliably. Parts of the buffer are flushed by the OS, but since the Bus Pirate is slow and the FT232 is slow as well, the remaining response from the Bus Pirate might arrive after flushing. I tried flushing five times, and it was not sufficient. I tried flushing five times with a 1.5 ms delay between flushes and that fixed maybe 80% of the problems, but in the end I gave up and flushed 10 times with an 1.5 ms delay between flushes and with those changes I have been unable to break initialization.
I'm looking for testers of that patch at
http://patchwork.coreboot.org/patch/1673/ . It works for me, but I have no idea if the rumors about flashrom problems are related or not.
Note: Never trust a flush command to actually do what you want.
ian wrote:The new bulk mode is for PIC programming, but I want to make you a new SPI command for flashrom too.
How about this:
Two new commands. Long write and long read.
Long write:
Write Command|length H|length L|data0|data1|...|datan|
The long write command, with the length of data to buffer then write out SPI (up to 4096 bytes)
Write all the data at once, max speed. The Bus Pirate buffers it first, then writes it out SPI at max speed.
Bus Pirate responds 0x01 at the end of data transmit.
Long read:
Read Command|length H|length L|
Bus Pirate returns up to 0xffff bytes.
I think that will speed things up a ton :) It speeds up PIC programming from minutes for 18K to 1-2 seconds.
A few days ago I committed a patch to flashrom which resulted in a 3x speedup on the Bus Pirate by violating the protocol a bit. It essentially bundles three commands and sends them off before waiting for a response for the first command. Those three commands are: Lower CS#, Read/Write SPI, Raise CS#.
How can flashrom detect the availability of your proposed new mode? I want to make sure that this feature needs zero user interaction (autodetect is needed) and won't break old flashrom versions. Some people won't be able to upgrade their flashrom version, and others won't be able to upgrade their Bus Pirate firmware. We should take care of both groups.
Now on to the technical details:
For writes it is essential that the buffer is big enough to actually write in one go without stopping the clock in between. While most chips can handle a stopped clock just fine, other chips explicitly require that all clock line states (1 or 0) are not longer than 50 us (lowest allowed frequency is 10 kHz). Due to that, flashrom has to take the buffer size of the Bus Pirate into consideration.
The trick of bundling up commands has to continue working or the new feature will essentially make flashing slower than it is right now, and that would be really sad.
However, there is one additional 2x speedup on some writes we could get by being able to bundle six commands: Lower CS#, Read/Write SPI, Raise CS#, Lower CS#, Read/Write SPI, Raise CS#. Most SPI flash write commands are actually two SPI commands in direct succession, and flashrom is able to send them at once if the hardware supports that.
Your proposed SPI read/write commands look good at a first glance. Now if there is a way to make sure the delay between subsequent write and read commands is less than 50 us, this should work out nicely, and we get the advantage of reducing traffic over the serial line by half.
Oh, and while I'm outlining a wishlist there are two things which would result in a ~100x speedup for some commands:
A repeat-until-result-mask command which would mask+compare the SPI response for the previous command against some value and repeat until response&mask=value. Usage would be to send read-status-register to the chip and repeat that until the response from the chip has the work-in-progress bit cleared. Having the ability to limit the number of loops even if the condition is not met would be even better since flashrom doesn't want to be stuck on a dead chip without working diagnostics.
As an alternative (or useful extension), a delay-n-microseconds command for that mode would help as well. Many chips offer a choice between waiting for a fixed time or polling the status register to detect end-of-write.
Either solution would be faster than a full flashrom<->Bus Pirate roundtrip to check the status register.
There is another speed problem I'm having with the Bus Pirate, and I was unable to track down the underlying reason. Communication with the BP is roughly 9x slower than it should be. AFAICS it should be possible to use one USB frame to send a command to the BP, and use the next USB frame to read the response. That would give us a roundtrip time of 2 ms per command (1 ms per USB frame). However, the actual roundtrip time is closer to 18 ms which is really devastating for performance. I've seen reports which indicate the problem exists on Windows and Linux, and it apparently is independent of how much data we're reading or writing from/to the BP. Just to give you an idea of the magnitude of problems: MrHijet needed 10 hours to write 1 MB, and that is totally unacceptable if we could manage this in little more than an hour without my speedups, and maybe 20 minutes or less with all possible speedups for the old BP SPI interface.
Do you have any idea what could cause those massive roundtrip delays?