If we violate the raw SPI communication protocol requirements of the Bus Pirate (namely, waiting for the completion of one command before sending the next one), we can reduce the number of round trips by a factor of 3. The FT2232 chip present in the Bus Pirate has a big enough buffer (at least 128 bytes IIRC) to avoid overflows in the tiny buffer of the Bus Pirate PIC.
Untested because I don't own the hardware.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-buspirate_speedup_protocolviolation/buspirate_spi.c =================================================================== --- flashrom-buspirate_speedup_protocolviolation/buspirate_spi.c (Revision 1048) +++ flashrom-buspirate_speedup_protocolviolation/buspirate_spi.c (Arbeitskopie) @@ -266,8 +266,8 @@ if (writecnt > 16 || readcnt > 16 || (readcnt + writecnt) > 16) return SPI_INVALID_LENGTH;
- /* +2 is pretty arbitrary. */ - buf = realloc(buf, writecnt + readcnt + 2); + /* 3 bytes extra for CS#, len, CS#. */ + buf = realloc(buf, writecnt + readcnt + 3); if (!buf) { msg_perr("Out of memory!\n"); exit(1); // -1 @@ -275,39 +275,41 @@
/* Assert CS# */ buf[i++] = 0x02; - ret = buspirate_sendrecv(buf, 1, 1); - if (ret) - return SPI_GENERIC_ERROR; - if (buf[0] != 0x01) { - msg_perr("Protocol error while lowering CS#!\n"); - return SPI_GENERIC_ERROR; - }
- i = 0; buf[i++] = 0x10 | (writecnt + readcnt - 1); memcpy(buf + i, writearr, writecnt); i += writecnt; memset(buf + i, 0, readcnt); - ret = buspirate_sendrecv(buf, i + readcnt, i + readcnt); - if (ret) + + i += readcnt; + /* De-assert CS# */ + buf[i++] = 0x03; + + ret = buspirate_sendrecv(buf, i, i); + + if (ret) { + msg_perr("Bus Pirate communication error!\n"); return SPI_GENERIC_ERROR; + } + if (buf[0] != 0x01) { + msg_perr("Protocol error while lowering CS#!\n"); + return SPI_GENERIC_ERROR; + } + + if (buf[1] != 0x01) { msg_perr("Protocol error while reading/writing SPI!\n"); return SPI_GENERIC_ERROR; } - memcpy(readarr, buf + i, readcnt);
- i = 0; - /* De-assert CS# */ - buf[i++] = 0x03; - ret = buspirate_sendrecv(buf, 1, 1); - if (ret) - return SPI_GENERIC_ERROR; - if (buf[0] != 0x01) { + if (buf[i - 1] != 0x01) { msg_perr("Protocol error while raising CS#!\n"); return SPI_GENERIC_ERROR; }
+ /* Skip CS#, length, writearr. */ + memcpy(readarr, buf + 2 + writecnt, readcnt); + return ret; }
On 16.06.2010 16:58, Carl-Daniel Hailfinger wrote:
If we violate the raw SPI communication protocol requirements of the Bus Pirate (namely, waiting for the completion of one command before sending the next one), we can reduce the number of round trips by a factor of 3. The FT2232 chip present in the Bus Pirate has a big enough buffer (at least 128 bytes IIRC) to avoid overflows in the tiny buffer of the Bus Pirate PIC.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Tested-by: Daniel Flinkmann DFlinkmann@gmx.de
Anyone up for an ack?
Regards, Carl-Daniel
I am not sure if I am the right person to ack it, but the patch worked fine.
Daniel
Am 29.07.2010 um 17:28 schrieb Carl-Daniel Hailfinger:
On 16.06.2010 16:58, Carl-Daniel Hailfinger wrote:
If we violate the raw SPI communication protocol requirements of the Bus Pirate (namely, waiting for the completion of one command before sending the next one), we can reduce the number of round trips by a factor of 3. The FT2232 chip present in the Bus Pirate has a big enough buffer (at least 128 bytes IIRC) to avoid overflows in the tiny buffer of the Bus Pirate PIC.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Tested-by: Daniel Flinkmann DFlinkmann@gmx.de
Anyone up for an ack?
Regards, Carl-Daniel
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
On 29.07.2010 17:51, Daniel Flinkmann wrote:
I am not sure if I am the right person to ack it, but the patch worked fine.
In that case you're the right person to ack it.
Am 29.07.2010 um 17:28 schrieb Carl-Daniel Hailfinger:
On 16.06.2010 16:58, Carl-Daniel Hailfinger wrote:
If we violate the raw SPI communication protocol requirements of the Bus Pirate (namely, waiting for the completion of one command before sending the next one), we can reduce the number of round trips by a factor of 3. The FT2232 chip present in the Bus Pirate has a big enough buffer (at least 128 bytes IIRC) to avoid overflows in the tiny buffer of the Bus Pirate PIC.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Tested-by: Daniel Flinkmann DFlinkmann@gmx.de
Regards, Carl-Daniel
Am 29.07.2010 um 17:28 schrieb Carl-Daniel Hailfinger:
On 16.06.2010 16:58, Carl-Daniel Hailfinger wrote:
If we violate the raw SPI communication protocol requirements of the Bus Pirate (namely, waiting for the completion of one command before sending the next one), we can reduce the number of round trips by a factor of 3. The FT2232 chip present in the Bus Pirate has a big enough buffer (at least 128 bytes IIRC) to avoid overflows in the tiny buffer of the Bus Pirate PIC.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Tested-by: Daniel Flinkmann DFlinkmann@gmx.de
Anyone up for an ack?
Regards, Carl-Daniel
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
Acked-by: Daniel Flinkmann dflinkmann@gmx.de
On 29.07.2010 17:58, Daniel Flinkmann wrote:
Am 29.07.2010 um 17:28 schrieb Carl-Daniel Hailfinger:
On 16.06.2010 16:58, Carl-Daniel Hailfinger wrote:
If we violate the raw SPI communication protocol requirements of the Bus Pirate (namely, waiting for the completion of one command before sending the next one), we can reduce the number of round trips by a factor of 3. The FT2232 chip present in the Bus Pirate has a big enough buffer (at least 128 bytes IIRC) to avoid overflows in the tiny buffer of the Bus Pirate PIC.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Tested-by: Daniel Flinkmann DFlinkmann@gmx.de
Acked-by: Daniel Flinkmann dflinkmann@gmx.de
Thanks, committed in r1120.
Regards, Carl-Daniel