Nico Huber has submitted this change and it was merged. ( https://review.coreboot.org/26947 )
Change subject: bitbang_spi: Add half-duplex optimizations
......................................................................
bitbang_spi: Add half-duplex optimizations
Currently, the core of bitbang_spi is a full-duplex SPI loop but in
practice this code is only ever used half-duplex. Spliting this code
into two half duplex loops allows us to optimize performance by reducing
communications and/or CPU pipeline stalls.
The speed up varies depending on how much the overhead of
getting/setting pins dominates execution time. For a USB bit bang driver
running on a 7th generation Core i5, the time to probe drops from ~7.7
seconds to ~6.7 seconds when this patch is applied.
Change-Id: I33b9f363716f651146c09113bda5fffe53b16738
Signed-off-by: Daniel Thompson <daniel.thompson(a)linaro.org>
Reviewed-on: https://review.coreboot.org/26947
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
---
M bitbang_spi.c
1 file changed, 19 insertions(+), 5 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 2c7a3f1..4b39164 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -119,14 +119,16 @@
return 0;
}
-static uint8_t bitbang_spi_rw_byte(const struct bitbang_spi_master *master,
- uint8_t val)
+static uint8_t bitbang_spi_read_byte(const struct bitbang_spi_master *master)
{
uint8_t ret = 0;
int i;
for (i = 7; i >= 0; i--) {
- bitbang_spi_set_sck_set_mosi(master, 0, (val >> i) & 1);
+ if (i == 0)
+ bitbang_spi_set_sck_set_mosi(master, 0, 0);
+ else
+ bitbang_spi_set_sck(master, 0);
programmer_delay(master->half_period);
ret <<= 1;
ret |= bitbang_spi_set_sck_get_miso(master, 1);
@@ -135,6 +137,18 @@
return ret;
}
+static void bitbang_spi_write_byte(const struct bitbang_spi_master *master, uint8_t val)
+{
+ int i;
+
+ for (i = 7; i >= 0; i--) {
+ bitbang_spi_set_sck_set_mosi(master, 0, (val >> i) & 1);
+ programmer_delay(master->half_period);
+ bitbang_spi_set_sck(master, 1);
+ programmer_delay(master->half_period);
+ }
+}
+
static int bitbang_spi_send_command(struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
@@ -150,9 +164,9 @@
bitbang_spi_request_bus(master);
bitbang_spi_set_cs(master, 0);
for (i = 0; i < writecnt; i++)
- bitbang_spi_rw_byte(master, writearr[i]);
+ bitbang_spi_write_byte(master, writearr[i]);
for (i = 0; i < readcnt; i++)
- readarr[i] = bitbang_spi_rw_byte(master, 0);
+ readarr[i] = bitbang_spi_read_byte(master);
bitbang_spi_set_sck(master, 0);
programmer_delay(master->half_period);
--
To view, visit https://review.coreboot.org/26947
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I33b9f363716f651146c09113bda5fffe53b16738
Gerrit-Change-Number: 26947
Gerrit-PatchSet: 4
Gerrit-Owner: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Nico Huber has submitted this change and it was merged. ( https://review.coreboot.org/26946 )
Change subject: bitbang_spi: Add functions to optimize xfers
......................................................................
bitbang_spi: Add functions to optimize xfers
On systems where the overhead of getting/setting pins is much greater
than the half period (for example, USB bit banging) it significantly
boosts performance if we can bang more than one bit at the same time.
Add support for setting sck at the same time as mosi or miso activity.
The speed up varies depending on how much the overhead of
getting/setting pins dominates execution time. For a USB bit bang driver
running on a 7th generation Core i5, the time to probe drops from ~9.2
seconds to ~7.7 seconds when set_clk_set_mosi() is implemented.
Change-Id: Ic3430a9df34844cdfa82e109456be788eaa1789a
Signed-off-by: Daniel Thompson <daniel.thompson(a)linaro.org>
Reviewed-on: https://review.coreboot.org/26946
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi(a)google.com>
Reviewed-by: Idwer Vollering <vidwer(a)gmail.com>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
---
M bitbang_spi.c
M programmer.h
2 files changed, 27 insertions(+), 16 deletions(-)
Approvals:
build bot (Jenkins): Verified
Patrick Georgi: Looks good to me, but someone else must approve
Idwer Vollering: Looks good to me, but someone else must approve
Nico Huber: Looks good to me, approved
diff --git a/bitbang_spi.c b/bitbang_spi.c
index edbc3e9..2c7a3f1 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -32,16 +32,6 @@
master->set_sck(val);
}
-static void bitbang_spi_set_mosi(const struct bitbang_spi_master * const master, int val)
-{
- master->set_mosi(val);
-}
-
-static int bitbang_spi_get_miso(const struct bitbang_spi_master * const master)
-{
- return master->get_miso();
-}
-
static void bitbang_spi_request_bus(const struct bitbang_spi_master * const master)
{
if (master->request_bus)
@@ -54,6 +44,26 @@
master->release_bus();
}
+static void bitbang_spi_set_sck_set_mosi(const struct bitbang_spi_master * const master, int sck, int mosi)
+{
+ if (master->set_sck_set_mosi) {
+ master->set_sck_set_mosi(sck, mosi);
+ return;
+ }
+
+ master->set_sck(sck);
+ master->set_mosi(mosi);
+}
+
+static int bitbang_spi_set_sck_get_miso(const struct bitbang_spi_master * const master, int sck)
+{
+ if (master->set_sck_get_miso)
+ return master->set_sck_get_miso(sck);
+
+ master->set_sck(sck);
+ return master->get_miso();
+}
+
static int bitbang_spi_send_command(struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr,
@@ -101,8 +111,7 @@
/* Only mess with the bus if we're sure nobody else uses it. */
bitbang_spi_request_bus(master);
bitbang_spi_set_cs(master, 1);
- bitbang_spi_set_sck(master, 0);
- bitbang_spi_set_mosi(master, 0);
+ bitbang_spi_set_sck_set_mosi(master, 0, 0);
/* FIXME: Release SPI bus here and request it again for each command or
* don't release it now and only release it on programmer shutdown?
*/
@@ -117,13 +126,11 @@
int i;
for (i = 7; i >= 0; i--) {
- bitbang_spi_set_mosi(master, (val >> i) & 1);
+ bitbang_spi_set_sck_set_mosi(master, 0, (val >> i) & 1);
programmer_delay(master->half_period);
- bitbang_spi_set_sck(master, 1);
ret <<= 1;
- ret |= bitbang_spi_get_miso(master);
+ ret |= bitbang_spi_set_sck_get_miso(master, 1);
programmer_delay(master->half_period);
- bitbang_spi_set_sck(master, 0);
}
return ret;
}
@@ -147,6 +154,7 @@
for (i = 0; i < readcnt; i++)
readarr[i] = bitbang_spi_rw_byte(master, 0);
+ bitbang_spi_set_sck(master, 0);
programmer_delay(master->half_period);
bitbang_spi_set_cs(master, 1);
programmer_delay(master->half_period);
diff --git a/programmer.h b/programmer.h
index ff81036..7e530b6 100644
--- a/programmer.h
+++ b/programmer.h
@@ -184,6 +184,9 @@
int (*get_miso) (void);
void (*request_bus) (void);
void (*release_bus) (void);
+ /* optional functions to optimize xfers */
+ void (*set_sck_set_mosi) (int sck, int mosi);
+ int (*set_sck_get_miso) (int sck);
/* Length of half a clock period in usecs. */
unsigned int half_period;
};
--
To view, visit https://review.coreboot.org/26946
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic3430a9df34844cdfa82e109456be788eaa1789a
Gerrit-Change-Number: 26946
Gerrit-PatchSet: 4
Gerrit-Owner: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Idwer Vollering <vidwer(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/26948 )
Change subject: programmer: Add Developerbox/CP2104 bit bang driver
......................................................................
Patch Set 6: Code-Review+1
--
To view, visit https://review.coreboot.org/26948
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I2547a96c1a2259ad0d52cd4b6ef42261b37cccf3
Gerrit-Change-Number: 26948
Gerrit-PatchSet: 6
Gerrit-Owner: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Idwer Vollering <vidwer(a)gmail.com>
Gerrit-Comment-Date: Fri, 17 Aug 2018 11:18:24 +0000
Gerrit-HasComments: No
Gerrit-HasLabels: Yes
Nico Huber has posted comments on this change. ( https://review.coreboot.org/26948 )
Change subject: programmer: Add Developerbox/CP2104 bit bang driver
......................................................................
Patch Set 6: Code-Review+2
Added my signed-off-by for the relicensed USB device filter code.
--
To view, visit https://review.coreboot.org/26948
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I2547a96c1a2259ad0d52cd4b6ef42261b37cccf3
Gerrit-Change-Number: 26948
Gerrit-PatchSet: 6
Gerrit-Owner: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Idwer Vollering <vidwer(a)gmail.com>
Gerrit-Comment-Date: Thu, 16 Aug 2018 20:49:14 +0000
Gerrit-HasComments: No
Gerrit-HasLabels: Yes
Nico Huber has uploaded a new patch set (#6) to the change originally created by Daniel Thompson. ( https://review.coreboot.org/26948 )
Change subject: programmer: Add Developerbox/CP2104 bit bang driver
......................................................................
programmer: Add Developerbox/CP2104 bit bang driver
The 96Boards Developerbox (a.k.a. Synquacer E-series) provides a CP2102
debug UART with its GPIO pins hooked up to the SPI NOR FLASH. The
circuit is intended to provide emergency recovery functions without
requiring any additional tools (such as a JTAG or SPI programmer). This
was expected to be very slow (and it is) but CP2102 is much cheaper than
a full dual channel USB comms chip.
Read performance is roughly on par with a 2400 baud modem (between 60
and 70 minutes per megabyte if you prefer) and write performance is 50%
slower still. The full recovery process, with backup and verification of
4MB data written takes between 14 and 15 hours. Thus it is only really
practical as an emergency recovery tool, firmware developers will need
to use an alternative programmer.
Change-Id: I2547a96c1a2259ad0d52cd4b6ef42261b37cccf3
Signed-off-by: Daniel Thompson <daniel.thompson(a)linaro.org>
Signed-off-by: Nico Huber <nico.huber(a)secunet.com>
---
M Makefile
A developerbox_spi.c
M flashrom.c
M programmer.h
4 files changed, 278 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/48/26948/6
--
To view, visit https://review.coreboot.org/26948
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I2547a96c1a2259ad0d52cd4b6ef42261b37cccf3
Gerrit-Change-Number: 26948
Gerrit-PatchSet: 6
Gerrit-Owner: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Daniel Thompson <daniel.thompson(a)linaro.org>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Idwer Vollering <vidwer(a)gmail.com>
Gerrit-CC: Nico Huber <nico.h(a)gmx.de>
Nico Huber has posted comments on this change. ( https://review.coreboot.org/28087 )
Change subject: Add initial J-Link SPI programmer
......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/#/c/28087/1/jlink_spi.c
File jlink_spi.c:
https://review.coreboot.org/#/c/28087/1/jlink_spi.c@168
PS1, Line 168: .max_data_read = JTAG_MAX_TRANSFER_SIZE,
The correct interpretation of the comment above is that
we have to tell here how much payload we can take. Which
is `JTAG_MAX_TRANSFER_SIZE - 4` or `- 5` if we allow 4B
addresses. (The interface is just wrong and should change
in the future. The SPI drivers shouldn't predict the
protocol overhead. But for now we have to do the calcu-
lation here.)
Please add `- 5` to both `.max_data_(read|write)`, and
set `.features = SPI_MASTER_4BA,` (I don't see a reason
why it shouldn't work oob).
--
To view, visit https://review.coreboot.org/28087
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ie03a054a75457ec9e1cab36ea124bb53b10e8d7e
Gerrit-Change-Number: 28087
Gerrit-PatchSet: 1
Gerrit-Owner: Marc Schink <flashrom-dev(a)marcschink.de>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Comment-Date: Thu, 16 Aug 2018 20:34:38 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: No
Nico Huber has posted comments on this change. ( https://review.coreboot.org/23338 )
Change subject: digilent_spi: add a driver for the iCEblink40 development board
......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/#/c/23338/4/digilent_spi.c
File digilent_spi.c:
https://review.coreboot.org/#/c/23338/4/digilent_spi.c@276
PS4, Line 276: ret = spi_start_io(read_follows, writecnt);
: if (ret != 0)
> The overhead is already reduced by setting it to 252. Now, I agree, […]
Hmmm, might have overlooked something here. The "empirically
determined" 252 were tested with 3B addresses I guess? but we
advertise 4B address support. So this should probably be 251B
(256B - 4B address - 1B opcode).
(One nice day, this should be refactored throughout flashrom,
so the SPI drivers wouldn't have to care about the protocol
overhead.)
--
To view, visit https://review.coreboot.org/23338
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I7ffcd9a2db4395816f0e8b6ce6c3b0d8e930c9e6
Gerrit-Change-Number: 23338
Gerrit-PatchSet: 8
Gerrit-Owner: Lubomir Rintel <lkundrak(a)v3.sk>
Gerrit-Reviewer: Lubomir Rintel <lkundrak(a)v3.sk>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Comment-Date: Thu, 16 Aug 2018 20:26:38 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: No
Nico Huber has posted comments on this change. ( https://review.coreboot.org/28086 )
Change subject: helpers: Add reverse_byte() and reverse_bytes()
......................................................................
Patch Set 1: Code-Review+2
(1 comment)
https://review.coreboot.org/#/c/28086/1/flash.h
File flash.h:
https://review.coreboot.org/#/c/28086/1/flash.h@299
PS1, Line 299: void reverse_bytes(uint8_t *dst, const uint8_t *src, size_t length);
Memory is returning. I think my argument was that we're changing
the order of bits not bytes. Ofc, we can't name both functions
`reverse_bits`... my current choice would be:
uint8_t reverse_bits(uint8_t);
void reverse_bits_copy(uint8_t *, const uint8_t *, size_t);
But I won't fight it, if you want to keep the current names.
--
To view, visit https://review.coreboot.org/28086
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I9d2e1e2856c835d22eed3b3a34bc0379773dd831
Gerrit-Change-Number: 28086
Gerrit-PatchSet: 1
Gerrit-Owner: Marc Schink <flashrom-dev(a)marcschink.de>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Comment-Date: Wed, 15 Aug 2018 17:30:18 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: Yes