File 0001-Bus-Pirate-UART-speedup.patch of Package flashrom
From 944bdbfcb9daf6e48c8c51915aaed759d5b68f70 Mon Sep 17 00:00:00 2001
From: Bernie Innocenti <bernie@codewiz.org>
Date: Mon, 18 Aug 2014 02:40:28 +0000
Subject: Bus Pirate UART speedup
I'm reposting this patch sent by Stefan Tauner in April,
after rebasing it onto flashrom's svn trunk.
Compared to the original, there's just one change: the original patch
did set the host uart speed back to 115200 (which is a no-op).
So I changed the baudrate to 2000000 (2Mbit), making the code agree
with the description.
I tested the patched flashrom with a Buspirate v3 running the 6.2beta
firmware. While I didn't make any accurate measurements, I'd
guesstimate a 10x speedup with my 8MB SPI flash. WOAH!
---
buspirate_spi.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/buspirate_spi.c b/buspirate_spi.c
index b6554ac..5d9c32f 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -178,7 +178,10 @@ static int buspirate_spi_shutdown(void *data)
}
/* Reset Bus Pirate (return to user terminal) */
bp_commbuf[0] = 0x0f;
- ret = buspirate_sendrecv(bp_commbuf, 1, 0);
+ if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
+ goto out_shutdown;
+ if ((ret = serialport_config(sp_fd, 115200)))
+ goto out_shutdown;
out_shutdown:
/* Shut down serial port communication */
@@ -370,6 +373,45 @@ int buspirate_spi_init(void)
spi_master_buspirate.command = buspirate_spi_send_command_v1;
}
+ /* Increase PIC/FT232 UART speed to 2 Mbaud (instead of 115200 baud) in firmware 5.5 and newer.
+ * Although this is already possible in firmware 5.2, fast UART in combination with the old SPI
+ * command set causes hangs for bigger transactions. This is caused by a UART buffer overrun
+ * in the PIC, and all firmware versions up to (hopefully not including) 6.2 are affected.
+ */
+ if (BP_FWVERSION(fw_version_major, fw_version_minor) >= BP_FWVERSION(5, 5)) {
+ // FIXME: Do this only for USB-based Bus Pirates... unless you're sure the UART can handle more.
+ int cmdlen;
+ /* Request setting the UART baud rate. */
+ cmdlen = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "b\n");
+ if ((ret = buspirate_sendrecv(bp_commbuf, cmdlen, 0)))
+ return ret;
+ if ((ret = buspirate_wait_for_string(bp_commbuf, ">")))
+ return ret;
+ /* Request setting the UART clock divisor manually. */
+ cmdlen = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "10\n");
+ if ((ret = buspirate_sendrecv(bp_commbuf, cmdlen, 0)))
+ return ret;
+ if ((ret = buspirate_wait_for_string(bp_commbuf, ">")))
+ return ret;
+ /* Set the UART clock divisor. New clock is 4000000/(divisor+1). */
+ cmdlen = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "%i\n", 1);
+ if ((ret = buspirate_sendrecv(bp_commbuf, cmdlen, 0)))
+ return ret;
+ sleep(1);
+ if (serialport_config(sp_fd, 2000000) != 0)
+ return 1;
+ bp_commbuf[0] = ' ';
+ if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
+ return ret;
+ if ((ret = buspirate_wait_for_string(bp_commbuf, "HiZ>")))
+ return ret;
+ msg_pdbg("Using fast 2 Mbaud for Bus Pirate <-> host communication.\n");
+ } else {
+ msg_pinfo("Bus Pirate firmware 5.4 and older does not support fast Bus Pirate <-> host "
+ "communication. Limiting UART speed to 115200 Baud.\n");
+ msg_pinfo("It is recommended to upgrade to firmware 6.2 or newer.\n");
+ }
+
/* Workaround for broken speed settings in firmware 6.1 and older. */
if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(6, 2))
if (spispeed > 0x4) {
--
2.1.2