slow read M25P16

Bus Pirate support for the Flashrom project

Re: slow read M25P16

Postby dturpin » Sat Jun 09, 2012 4:15 am

biosflasher wrote:I found a Bus Pirate firmware bug which caused an extreme slowdown of flashrom operations.
Code: Select all
static unsigned char binSPIspeed[] = {0b00000, 0b11000, 0b11100, 0b11101, 0b00011, 0b01000, 0b10000, 0b11000};
//00=30,01=125,10=250,11=1000khz, 100=2mhz,101=2.667mhz,  110=4mhz, 111=8mhz; datasheet pg 142

Unless I'm looking at the wrong datasheet, the clock divisors for these values are:
0b00000 8:1 64:1 512:1
0b11000 2:1 64:1 128:1
0b11100 1:1 64:1 64:1
0b11101 1:1 16:1 16:1
0b00011 8:1 1:1 8:1
0b01000 6:1 64:1 384:1
0b10000 4:1 64:1 256:1
0b11000 2:1 64:1 128:1
This means people who selected values above 2 MHz got extremely slow rates instead: 24kHz instead of 2.667MHz, 62kHz instead of 4MHz, 125kHz instead of 8MHz. It also explains why many people complained that using speeds >2MHz slowed things down a lot.

Until there is a fixed firmware, use the following flashrom command line to get 2 MHz (best possible option until the Bus Pirate firmware bug is fixed):
Code: Select all
flashrom -p buspirate_spi:dev=/dev/ttyUSB0,spispeed=2M


Didn't I mention just that in a couple of submits above =) As I wrote I also tested to change that row with success
dturpin
Newbie
Newbie
 
Posts: 16
Joined: Tue Apr 03, 2012 2:51 am

Re: slow read M25P16

Postby biosflasher » Sat Jun 09, 2012 4:55 am

dturpin wrote:
biosflasher wrote:I found a Bus Pirate firmware bug which caused an extreme slowdown of flashrom operations.
Code: Select all
static unsigned char binSPIspeed[] = {0b00000, 0b11000, 0b11100, 0b11101, 0b00011, 0b01000, 0b10000, 0b11000};
//00=30,01=125,10=250,11=1000khz, 100=2mhz,101=2.667mhz,  110=4mhz, 111=8mhz; datasheet pg 142



Didn't I mention just that in a couple of submits above =)


Yes, you did. Ian's comments about BPv4 problems made me (falsely) think that the bug didn't exist in BPv3 until I looked at the sources and noticed that your analysis applied to BPv3 and BPv4.

dturpin wrote:As I wrote I also tested to change that row with success


Indeed. It's a bit unfortunate that the clock divider would be capable of 16 MHz, but the original SPI binmode protocol put 8 MHz as upper limit.
biosflasher
Full Member
Full Member
 
Posts: 118
Joined: Mon Nov 16, 2009 7:14 pm

Re: slow read M25P16

Postby ian » Tue Jun 12, 2012 3:58 am

how do I chose which project to open? I just opened the project by going to the firmware dir and buspirate.X, mplab displays this:


Ah, I understand now. The MPLAB X version was contributed by someone, I still work with the MPLAB 8 version in the main project directory (buspirate.mcp/bpv4.mcp). MPLABX version may be for 3 only (?).

How will the buspirate firmware know that it can exceed the speed? Does it get an ACK for each packet sent? or could one end up in a situation where some buffer is overflowing on host since it only allows 115200 out to the application?


The BP just processes packets as they come, and marks transmit packets as ready to go. The PC is in complete control of transfers. I'm not familiar with the host part, though I suspect that is accounted for in the virtual serial drivers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: slow read M25P16

Postby ian » Tue Jun 12, 2012 4:33 am

You are correct, that applies to v3 and v4, I thought it was a v4 difference only. The registers for the 64GA and 256GB are identical in the datasheet. The big is fixed in SVN, and here are v3 and v4 firmwares with the bug fix.

The high-speed UART mode mentioned by Sjaak is actually in the OpenOCD JTAG mode and not part of the regular binmode features.

The 16MHz SPI speed mode is not valid, the max SPI peripheral speed is 8MHz (10MHz slave). We could try to overclock it though :)
Attachments
2012-06-12_1105.png
bp-spifix.zip
(181.81 KiB) Downloaded 560 times
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: slow read M25P16

Postby biosflasher » Tue Jun 12, 2012 6:18 pm

Thanks for the quick fix!
With the new firmware, flashrom read speed went up and the 8 MHz mode now works as designed.

Old firmware, 2 MHz SPI, 32 Mbit (4 MByte) flash chip: Full chip read 6 min 40 s
Old firmware, broken 8 MHz (really 125 kHz) SPI, 32 Mbit (4 MByte) flash chip: Full chip read >>10 min
New firmware, 8 MHz SPI, 32 Mbit (4 MByte) flash chip: Full chip read 6 min 26 s

Even if we could increase SPI speed further, the speed improvement wouldn't be noticeable (2-3 seconds less if we used 16 MHz).

OTOH, using the OpenOCD JTAG high-speed UART mode would fix the BP-to-host bottleneck and might save us 200 seconds in the configuration I tested.
biosflasher
Full Member
Full Member
 
Posts: 118
Joined: Mon Nov 16, 2009 7:14 pm

Re: slow read M25P16

Postby ian » Wed Jun 13, 2012 2:26 am

pls send me your address via PM and I will send a BPv4 - then you can use the USB connection and double buffer :)
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: slow read M25P16

Postby dturpin » Thu Jun 14, 2012 12:56 pm

biosflasher wrote:Thanks for the quick fix!
With the new firmware, flashrom read speed went up and the 8 MHz mode now works as designed.

Old firmware, 2 MHz SPI, 32 Mbit (4 MByte) flash chip: Full chip read 6 min 40 s
Old firmware, broken 8 MHz (really 125 kHz) SPI, 32 Mbit (4 MByte) flash chip: Full chip read >>10 min
New firmware, 8 MHz SPI, 32 Mbit (4 MByte) flash chip: Full chip read 6 min 26 s

Even if we could increase SPI speed further, the speed improvement wouldn't be noticeable (2-3 seconds less if we used 16 MHz).

OTOH, using the OpenOCD JTAG high-speed UART mode would fix the BP-to-host bottleneck and might save us 200 seconds in the configuration I tested.

Cool, did you try my patch to use the "write then read"-command instead of Bulk SPI? That increased my speed significantly
dturpin
Newbie
Newbie
 
Posts: 16
Joined: Tue Apr 03, 2012 2:51 am

Re: slow read M25P16

Postby dturpin » Thu Jun 14, 2012 1:01 pm

ian wrote:Ah, I understand now. The MPLAB X version was contributed by someone, I still work with the MPLAB 8 version in the main project directory (buspirate.mcp/bpv4.mcp). MPLABX version may be for 3 only (?).

Ah I suspected that. Do you plan to move over to MPLAB X completely? I did get it to work with my tweaks above but it would of course be nicer if worked out of the box =)

ian wrote:The BP just processes packets as they come, and marks transmit packets as ready to go. The PC is in complete control of transfers. I'm not familiar with the host part, though I suspect that is accounted for in the virtual serial drivers.

Thanks, cleared it up for me. So its up to the driver really if it wants to be "true" to the configured speed.
dturpin
Newbie
Newbie
 
Posts: 16
Joined: Tue Apr 03, 2012 2:51 am

Re: slow read M25P16

Postby biosflasher » Thu Jun 14, 2012 1:56 pm

dturpin wrote:
biosflasher wrote:With the new firmware, flashrom read speed went up and the 8 MHz mode now works as designed.
New firmware, 8 MHz SPI, 32 Mbit (4 MByte) flash chip: Full chip read 6 min 26 s

Cool, did you try my patch to use the "write then read"-command instead of Bulk SPI? That increased my speed significantly

You created a flashrom patch? Sorry, didn't see that.

I'm using a variant of my "write then read" flashrom patch written some time ago, but that patch was not merged because some users reported corruption issues which we couldn't track down or solve.
Link to my old patch: http://patchwork.coreboot.org/patch/2033/. I updated the patch a few days ago and added some firmware dependent workarounds: http://patchwork.coreboot.org/patch/3653/
biosflasher
Full Member
Full Member
 
Posts: 118
Joined: Mon Nov 16, 2009 7:14 pm

Re: slow read M25P16

Postby dturpin » Thu Jun 14, 2012 2:02 pm

Ah cool, by the looks of it it was I that missed you're patch =) Mine was just a quick hack (posted earlier in this thread).
dturpin
Newbie
Newbie
 
Posts: 16
Joined: Tue Apr 03, 2012 2:51 am

Re: slow read M25P16

Postby biosflasher » Mon Jun 18, 2012 12:06 pm

Whoa! I changed the UART speed to exactly 2 MBaud, and now the read time for current firmware beta, 8 MHz SPI, 32 Mbit (4 MByte) flash chip is down to 42 sec (instead of 6 min 26 sec). That's a factor of 10 speedup.

The downside is that this speedup only applies to Linux hosts. I have absolutely no idea how to set the virtual COM port in Windows to 2 Mbaud.

This is the latest flashrom patch for the Bus Pirate speedup: http://patchwork.coreboot.org/patch/3663/ (applies against flashrom svn). That patch is very experimental, but it seems to work fine (at least in a quick read test with one chip on my box). You need a firmware which identifies as version 6.2, the one posted by Ian earlier in this thread is the one I tested against.
biosflasher
Full Member
Full Member
 
Posts: 118
Joined: Mon Nov 16, 2009 7:14 pm

Re: slow read M25P16

Postby ian » Wed Jun 20, 2012 1:37 am

The downside is that this speedup only applies to Linux hosts. I have absolutely no idea how to set the virtual COM port in Windows to 2 Mbaud.


I think you just open the serial port at 2,xxx,xxx (whatever the standard is), though I could be totally clueless. I have never tried it before :) Jawi would know, his Java client for the logic sniffer opens the port at 9,xxx,xxx.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: slow read M25P16

Postby ian » Wed Jun 20, 2012 1:46 am

Ah I suspected that. Do you plan to move over to MPLAB X completely? I did get it to work with my tweaks above but it would of course be nicer if worked out of the box =)


There is a big push to move over, but since bugs are still cropping up everywhere (markus found 2 in this thread alone: viewtopic.php?f=56&t=3944&view=unread#p41517 ) I'm not keen to support it on a day to day basis on a project as widespread as the Bus Pirate.

The USB serial actually usually goes MUCH faster than the set baud rate. It is only a question of if the PC throttles the data down to the lower serial speed when passing it to the application. That really depends on the operating system, they are all different.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: slow read M25P16

Postby csch » Sun Jul 29, 2012 3:19 pm

Hm, does binmode really have it? I am running my software at extended serial speeds up to 2mbit, but it uses speed changing in terminal mode ;)
On first glance through flashrom (which I wanted to scavenge for their SPI flash code since that's what I'm toying with) it didn't look like it was switchig serial speed at all.
csch
Newbie
Newbie
 
Posts: 8
Joined: Sun Jul 29, 2012 9:26 am

Re: slow read M25P16

Postby biosflasher » Mon Jul 30, 2012 12:10 pm

SPI binmode doesn't support fast serial speeds. I have a flashrom patch (for Bus Pirate hardware v3 only) which sets the serial speed in terminal mode, then switches to binmode.
biosflasher
Full Member
Full Member
 
Posts: 118
Joined: Mon Nov 16, 2009 7:14 pm

Previous

Return to Flashrom