Khem Raj has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43770 )
Change subject: Makefile: Check for last line only from preprocessed output
......................................................................
Makefile: Check for last line only from preprocessed output
This started to fail with glibc 2.32 since glibc added additional
attributes to functions in signal.h therefore existing regexp started to
fail as it is not able to handle these functions e.g.
extern int siginterrupt (int __sig, int __interrupt) __attribute__ ((__nothrow__ , __leaf__))
__attribute__ ((__deprecated__ ("Use sigaction with SA_RESTART instead")));
grep -v '^\#' | grep '"' | cut -f 2 -d'"'
bit outside of fd_set selected
Use sigaction with SA_RESTART instead
arm
So changing it to
tail -1 | grep '"' | cut -f 2 -d'"'
arm
Produces the expected result, this was hidden until now
Signed-off-by: Khem Raj <raj.khem(a)gmail.com>
Change-Id: I123a046e142d54632f12d54e2aa09b0928c02b91
---
M Makefile
1 file changed, 3 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/70/43770/1
diff --git a/Makefile b/Makefile
index 803529f..3795681 100644
--- a/Makefile
+++ b/Makefile
@@ -106,7 +106,7 @@
# IMPORTANT: The following line must be placed before TARGET_OS is ever used
# (of course), but should come after any lines setting CC because the line
# below uses CC itself.
-override TARGET_OS := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E os.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
+override TARGET_OS := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E os.h 2>/dev/null | tail -1 | grep '"' | cut -f 2 -d'"'))
ifeq ($(TARGET_OS), Darwin)
override CPPFLAGS += -I/opt/local/include -I/usr/local/include
@@ -460,8 +460,8 @@
# IMPORTANT: The following line must be placed before ARCH is ever used
# (of course), but should come after any lines setting CC because the line
# below uses CC itself.
-override ARCH := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E archtest.c 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
-override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null | grep -v '^\#'))
+override ARCH := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E archtest.c 2>/dev/null | tail -1 | grep '"' | cut -f 2 -d'"'))
+override ENDIAN := $(strip $(call debug_shell,$(CC) $(CPPFLAGS) -E endiantest.c 2>/dev/null | tail -1))
# Disable the internal programmer on unsupported architectures (everything but x86 and mipsel)
ifneq ($(ARCH)-little, $(filter $(ARCH),x86 mips)-$(ENDIAN))
--
To view, visit https://review.coreboot.org/c/flashrom/+/43770
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I123a046e142d54632f12d54e2aa09b0928c02b91
Gerrit-Change-Number: 43770
Gerrit-PatchSet: 1
Gerrit-Owner: Khem Raj
Gerrit-MessageType: newchange
Ryan O'Leary has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/37776 )
Change subject: Add -- to make clean
......................................................................
Add -- to make clean
Somehow, I ended up with a file name "-c.d". I probably made it by
mistake. This change lets "make clean" be a bit more resilient to files
such as these.
Change-Id: I2517ffac975f3df75f706350a07f189a98a11b7c
Signed-off-by: Ryan O'Leary <ryanoleary(a)google.com>
---
M Makefile
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/76/37776/1
diff --git a/Makefile b/Makefile
index 518d41b..fa66910 100644
--- a/Makefile
+++ b/Makefile
@@ -1129,7 +1129,7 @@
# This includes all frontends and libflashrom.
# We don't use EXEC_SUFFIX here because we want to clean everything.
clean:
- rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE)
+ rm -f -- $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE)
@+$(MAKE) -C util/ich_descriptors_tool/ clean
distclean: clean
--
To view, visit https://review.coreboot.org/c/flashrom/+/37776
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I2517ffac975f3df75f706350a07f189a98a11b7c
Gerrit-Change-Number: 37776
Gerrit-PatchSet: 1
Gerrit-Owner: Ryan O'Leary <ryanoleary(a)google.com>
Gerrit-MessageType: newchange
Hello Patrick Rudolph,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/34629
to review the following change.
Change subject: dediprog: Fix SF600 4BA mode
......................................................................
dediprog: Fix SF600 4BA mode
Flash chips greater than 16MiB require 4BA mode support.
Current master doesn't support such mode as the SF600 uses
PROTOCOL_V3.
Fix protocol version check to support 4BA on PROTOCOL_V3, too.
Tested on SF600 V:7.2.45
Able to read and write "IS25WP256" (32768 kB, SPI).
Change-Id: I2d3089693fbd2f8f7717a8f71be242be131ce707
Signed-off-by: Patrick Rudolph <patrick.rudolph(a)9elements.com>
---
M dediprog.c
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/29/34629/1
diff --git a/dediprog.c b/dediprog.c
index 3566109..add478d 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1160,7 +1160,7 @@
if (dediprog_devicetype == DEV_SF100 && protocol() == PROTOCOL_V1)
spi_master_dediprog.features &= ~SPI_MASTER_NO_4BA_MODES;
- if (protocol() == PROTOCOL_V2)
+ if (protocol() >= PROTOCOL_V2)
spi_master_dediprog.features |= SPI_MASTER_4BA;
if (register_spi_master(&spi_master_dediprog) || dediprog_set_leds(LED_NONE))
--
To view, visit https://review.coreboot.org/c/flashrom/+/34629
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I2d3089693fbd2f8f7717a8f71be242be131ce707
Gerrit-Change-Number: 34629
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <siro(a)das-labor.org>
Gerrit-Reviewer: Patrick Rudolph <patrick.rudolph(a)9elements.com>
Gerrit-MessageType: newchange
Sean Anderson has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43608 )
Change subject: buspirate: Add option for setting the aux pin
......................................................................
buspirate: Add option for setting the aux pin
This adds a parameter to drive the aux pin low (or high if you
explicitly want the previous behavior). Some boards need to have a reset
pin driven low before the firmware can be safely flashed. With the Bus
Pirate, this is most easily done with the auxiliary pin.
Change-Id: Ieeecfdf1afc06dadda9b8f99547cd74854ca6775
Signed-off-by: Sean Anderson <seanga2(a)gmail.com>
---
M buspirate_spi.c
M flashrom.8.tmpl
2 files changed, 33 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/08/43608/1
diff --git a/buspirate_spi.c b/buspirate_spi.c
index fdfc0e4..1ccb107 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -228,6 +228,7 @@
int serialspeed_index = -1;
int ret = 0;
int pullup = 0;
+ int aux = 1;
dev = extract_programmer_param("dev");
if (dev && !strlen(dev)) {
@@ -277,6 +278,17 @@
}
free(tmp);
+ tmp = extract_programmer_param("aux");
+ if (tmp) {
+ if (strcasecmp("high", tmp) == 0)
+ ; /* Default */
+ else if (strcasecmp("low", tmp) == 0)
+ aux = 0;
+ else
+ msg_perr("Invalid AUX state, driving high by default.\n");
+ }
+ free(tmp);
+
/* Default buffer size is 19: 16 bytes data, 3 bytes control. */
#define DEFAULT_BUFSIZE (16 + 3)
bp_commbuf = malloc(DEFAULT_BUFSIZE);
@@ -520,11 +532,18 @@
}
/* Initial setup (SPI peripherals config): Enable power, CS high, AUX */
- bp_commbuf[0] = 0x40 | 0x0b;
+ bp_commbuf[0] = 0x40 | 0x09;
if (pullup == 1) {
bp_commbuf[0] |= (1 << 2);
msg_pdbg("Enabling pull-up resistors.\n");
}
+ if (aux) {
+ bp_commbuf[0] |= (1 << 1);
+ msg_pdbg("Driving AUX high.\n");
+ } else {
+ msg_pdbg("Driving AUX low.\n");
+ }
+
ret = buspirate_sendrecv(bp_commbuf, 1, 1);
if (ret)
return 1;
diff --git a/flashrom.8.tmpl b/flashrom.8.tmpl
index db50d59..caf860c 100644
--- a/flashrom.8.tmpl
+++ b/flashrom.8.tmpl
@@ -902,6 +902,19 @@
.URLB "http://dangerousprototypes.com/docs/Practical_guide_to_Bus_Pirate_pull-up_r…" \
"in a guide by dangerousprototypes" .
Only the external supply voltage (Vpu) is supported as of this writing.
+.sp
+An optional aux parameter specifies the state of the Bus Pirate auxiliary pin.
+This may be used to drive the auxiliary pin high or low before a transfer.
+Syntax is
+.sp
+.B " flashrom -p buspirate_spi:aux=state"
+.sp
+where
+.B state
+can be
+.BR high " or " low .
+The default
+.BR state " is " high .
.SS
.BR "pickit2_spi " programmer
.IP
--
To view, visit https://review.coreboot.org/c/flashrom/+/43608
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ieeecfdf1afc06dadda9b8f99547cd74854ca6775
Gerrit-Change-Number: 43608
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Anderson <seanga2(a)gmail.com>
Gerrit-MessageType: newchange
Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/37777 )
Change subject: chipset_enable.c: Enable Tiger Lake U support
......................................................................
chipset_enable.c: Enable Tiger Lake U support
Did a basic local test with --flash-name and -r bios and
ran strings to see if the bios contained reasonable data.
BUG=b:146089922
Change-Id: I2c13e0173c9b5e17d2ae197f4a4ab9aa2825c1b3
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
---
M chipset_enable.c
1 file changed, 1 insertion(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/77/37777/1
diff --git a/chipset_enable.c b/chipset_enable.c
index b55852c..d5a2f03 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -1996,6 +1996,7 @@
{0x8086, 0x9d56, B_S, NT, "Intel", "Kaby Lake Y Premium", enable_flash_pch100},
{0x8086, 0x9d58, B_S, NT, "Intel", "Kaby Lake U Premium", enable_flash_pch100},
{0x8086, 0x9d84, B_S, DEP, "Intel", "Cannon Lake U Premium", enable_flash_pch300},
+ {0x8086, 0xa082, B_FS, NT, "Intel", "Tiger Lake U", enable_flash_pch300},
{0x8086, 0xa141, B_S, NT, "Intel", "Sunrise Point Desktop Sample", enable_flash_pch100},
{0x8086, 0xa142, B_S, NT, "Intel", "Sunrise Point Unknown Sample", enable_flash_pch100},
{0x8086, 0xa143, B_S, NT, "Intel", "H110", enable_flash_pch100},
--
To view, visit https://review.coreboot.org/c/flashrom/+/37777
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I2c13e0173c9b5e17d2ae197f4a4ab9aa2825c1b3
Gerrit-Change-Number: 37777
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: newchange
Miklós Márton has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/34641 )
Change subject: usbdev: fix accepting shorter serial numbers than the real one.
......................................................................
usbdev: fix accepting shorter serial numbers than the real one.
Change-Id: Ife8c4e0a957c4345e27ec9ae9e1480ca80fe505c
---
M usbdev.c
1 file changed, 2 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/41/34641/1
diff --git a/usbdev.c b/usbdev.c
index 764ac04..7e41235 100644
--- a/usbdev.c
+++ b/usbdev.c
@@ -104,7 +104,8 @@
msg_pdbg("Serial number is %s\n", myserial);
/* Filter out any serial number that does not commence with serialno */
- return 0 != strncmp(serialno, (char *)myserial, strlen(serialno));
+ return strlen((char *)myserial) == strlen(serialno)
+ && 0 != strncmp(serialno, (char *)myserial, strlen(serialno));
}
struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
--
To view, visit https://review.coreboot.org/c/flashrom/+/34641
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ife8c4e0a957c4345e27ec9ae9e1480ca80fe505c
Gerrit-Change-Number: 34641
Gerrit-PatchSet: 1
Gerrit-Owner: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-MessageType: newchange
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43052 )
Change subject: util/ich_descriptors_tool: Use GNU-style printf in MinGW
......................................................................
util/ich_descriptors_tool: Use GNU-style printf in MinGW
This allows MinGW targets to use certain printf formatting
identifiers such as "%v" by adding -D__USE_MINGW_ANSI_STDIO=1 to
the CFLAGS. This is also done in flashrom's top-level Makefile.
Reported on https://github.com/flashrom/flashrom/issues/149
Change-Id: I644be8b5b607cc77b4be2121c443f0d41d8da687
Signed-off-by: David Hendricks <david.hendricks(a)gmail.com>
---
M util/ich_descriptors_tool/Makefile
1 file changed, 4 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/52/43052/1
diff --git a/util/ich_descriptors_tool/Makefile b/util/ich_descriptors_tool/Makefile
index c32e30b..8962431 100644
--- a/util/ich_descriptors_tool/Makefile
+++ b/util/ich_descriptors_tool/Makefile
@@ -41,6 +41,10 @@
CFLAGS += -Wno-format
endif
+ifeq ($(TARGET_OS), MinGW)
+CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
+endif
+
ifeq ($(WARNERROR), yes)
CFLAGS += -Werror
endif
--
To view, visit https://review.coreboot.org/c/flashrom/+/43052
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I644be8b5b607cc77b4be2121c443f0d41d8da687
Gerrit-Change-Number: 43052
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
Simon Buhrow has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/40748 )
Change subject: ft2232_spi.c - Pack read cmd and nCS in one ftdi_write_data() call
......................................................................
ft2232_spi.c - Pack read cmd and nCS in one ftdi_write_data() call
Every ftdi_write_data() call is quite time consuming as the ftdi-chip takes 2-3ms to respond.
As the comment already says: Minimize USB transfers by packing as many commands as possible together.
As I cannot see any reason to put read cmd and deassertion of nCS into seperated ftdi calls,
I packed them together to save programming time.
Signed-off-by: Simon Buhrow <simon.buhrow(a)posteo.de>
Change-Id: I3f76da3dd0124a0deec7f937dbc4b7dc488c8004
---
M ft2232_spi.c
1 file changed, 38 insertions(+), 40 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/48/40748/1
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 9f4c7f0..b2f5e40 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -398,7 +398,10 @@
msg_perr("Unable to set latency timer (%s).\n", ftdi_get_error_string(ftdic));
}
- if (ftdi_write_data_set_chunksize(ftdic, 270)) {
+ if (ftdi_write_data_set_chunksize(ftdic, 280)) {
+ /* 280 Byte = (9 Byte CMD + 1 Byte WREN) + (9 Byte CMD + 1 Byte op) + 4 Byte Addr
+ * + 256 Byte PageWrite-data
+ with op: PageProgram or Erase; CMD: FTDI-Chip commands*/
msg_perr("Unable to set chunk size (%s).\n", ftdi_get_error_string(ftdic));
}
@@ -467,31 +470,26 @@
struct ftdi_context *ftdic = &ftdic_context;
static unsigned char *buf = NULL;
/* failed is special. We use bitwise ops, but it is essentially bool. */
- int i = 0, ret = 0, failed = 0;
- size_t bufsize;
- static size_t oldbufsize = 0;
+ static int i = 0;
+ int ret = 0, failed = 0;
if (writecnt > 65536 || readcnt > 65536)
return SPI_INVALID_LENGTH;
- /* buf is not used for the response from the chip. */
- bufsize = max(writecnt + 9, 260 + 9);
- /* Never shrink. realloc() calls are expensive. */
- if (!buf || bufsize > oldbufsize) {
- buf = realloc(buf, bufsize);
+ if (!buf) {
+ /* set buf size to hardware buffer size of ftdi*/
+ buf = realloc(buf, 4096);
if (!buf) {
msg_perr("Out of memory!\n");
/* TODO: What to do with buf? */
return SPI_GENERIC_ERROR;
}
- oldbufsize = bufsize;
}
/*
* Minimize USB transfers by packing as many commands as possible
- * together. If we're not expecting to read, we can assert CS#, write,
- * and deassert CS# all in one shot. If reading, we do three separate
- * operations.
+ * together. We can assert CS#, write, (read,)
+ * and deassert CS# all in one shot.
*/
msg_pspew("Assert CS#\n");
buf[i++] = SET_BITS_LOW;
@@ -506,44 +504,44 @@
i += writecnt;
}
- /*
- * Optionally terminate this batch of commands with a
- * read command, then do the fetch of the results.
- */
+ /* A optionally read command */
if (readcnt) {
buf[i++] = MPSSE_DO_READ;
buf[i++] = (readcnt - 1) & 0xff;
buf[i++] = ((readcnt - 1) >> 8) & 0xff;
- ret = send_buf(ftdic, buf, i);
- failed = ret;
- /* We can't abort here, we still have to deassert CS#. */
- if (ret)
- msg_perr("send_buf failed before read: %i\n", ret);
- i = 0;
- if (ret == 0) {
- /*
- * FIXME: This is unreliable. There's no guarantee that
- * we read the response directly after sending the read
- * command. We may be scheduled out etc.
- */
- ret = get_buf(ftdic, readarr, readcnt);
- failed |= ret;
- /* We can't abort here either. */
- if (ret)
- msg_perr("get_buf failed: %i\n", ret);
- }
}
msg_pspew("De-assert CS#\n");
buf[i++] = SET_BITS_LOW;
buf[i++] = cs_bits;
buf[i++] = pindir;
- ret = send_buf(ftdic, buf, i);
- failed |= ret;
- if (ret)
- msg_perr("send_buf failed at end: %i\n", ret);
- return failed ? -1 : 0;
+ if (writearr[0] == JEDEC_WREN) {
+ /* Return to get second op (Program or Erase) without resetting buf nor i*/
+ return 0;
+ } else {
+ ret = send_buf(ftdic, buf, i);
+ failed |= ret;
+ if (ret)
+ msg_perr("send_buf failed: %i\n", ret);
+ i = 0;
+
+ if (readcnt) {
+ if (ret == 0) {
+ /*
+ * FIXME: This is unreliable. There's no guarantee that
+ * we read the response directly after sending the read
+ * command. We may be scheduled out etc.
+ */
+ ret = get_buf(ftdic, readarr, readcnt);
+ failed |= ret;
+ /* We can't abort here either. */
+ if (ret)
+ msg_perr("get_buf failed: %i\n", ret);
+ }
+ }
+ return failed ? -1 : 0;
+ }
}
#endif
--
To view, visit https://review.coreboot.org/c/flashrom/+/40748
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3f76da3dd0124a0deec7f937dbc4b7dc488c8004
Gerrit-Change-Number: 40748
Gerrit-PatchSet: 1
Gerrit-Owner: Simon Buhrow
Gerrit-MessageType: newchange
Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/38209 )
Change subject: raiden_debug: Upstream ChromiumOS servo debug board prog
......................................................................
raiden_debug: Upstream ChromiumOS servo debug board prog
Initial check-in of the Raiden debugger programmer.
Squash in,
usb_device: needed for raiden_debug prog
BUG=b:143389556
BRANCH=none
TEST=builds
Change-Id: Ifad273a708acea4de797a0808be58960635a8864
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
---
M Makefile
M flashrom.c
M meson.build
M meson_options.txt
M programmer.h
A raiden_debug_spi.c
A usb_device.c
A usb_device.h
8 files changed, 977 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/09/38209/1
diff --git a/Makefile b/Makefile
index 7242b09..e8ca7a8 100644
--- a/Makefile
+++ b/Makefile
@@ -226,6 +226,11 @@
else
override CONFIG_RAYER_SPI = no
endif
+ifeq ($(CONFIG_RAIDEN), yes)
+UNSUPPORTED_FEATURES += CONFIG_RAIDEN=yes
+else
+override CONFIG_RAIDEN = no
+endif
ifeq ($(CONFIG_NIC3COM), yes)
UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
else
@@ -607,6 +612,9 @@
# RayeR SPIPGM hardware support
CONFIG_RAYER_SPI ?= yes
+# ChromiumOS servo DUT debug board hardware support
+CONFIG_RAIDEN ?= yes
+
# PonyProg2000 SPI hardware support
CONFIG_PONY_SPI ?= yes
@@ -817,6 +825,11 @@
NEED_RAW_ACCESS += CONFIG_RAYER_SPI
endif
+ifeq ($(CONFIG_RAIDEN), yes)
+FEATURE_CFLAGS += -D'CONFIG_RAIDEN=1'
+PROGRAMMER_OBJS += raiden_debug_spi.o usb_device.o
+endif
+
ifeq ($(CONFIG_PONY_SPI), yes)
FEATURE_CFLAGS += -D'CONFIG_PONY_SPI=1'
PROGRAMMER_OBJS += pony_spi.o
diff --git a/flashrom.c b/flashrom.c
index e540027..e541b68 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -133,6 +133,18 @@
},
#endif
+#if CONFIG_RAIDEN == 1
+ {
+ .name = "raiden_debug",
+ .type = USB,
+ .devs.note = "All programmer devices speaking the raiden protocol\n",
+ .init = raiden_debug_spi_init,
+ .map_flash_region = fallback_map,
+ .unmap_flash_region = fallback_unmap,
+ .delay = internal_delay,
+ },
+#endif
+
#if CONFIG_DRKAISER == 1
{
.name = "drkaiser",
diff --git a/meson.build b/meson.build
index 375089c..88b14cf 100644
--- a/meson.build
+++ b/meson.build
@@ -42,6 +42,7 @@
config_dummy = get_option('config_dummy')
config_ft2232_spi = get_option('config_ft2232_spi')
config_gfxnvidia = get_option('config_gfxnvidia')
+config_raiden = get_option('config_raiden')
config_internal = get_option('config_internal')
config_it8212 = get_option('config_it8212')
config_linux_mtd = get_option('config_linux_mtd')
@@ -104,6 +105,7 @@
config_atavia = false
config_drkaiser = false
config_gfxnvidia = false
+ config_raiden = false
config_internal = false
config_it8212 = false
config_nic3com = false
@@ -170,6 +172,11 @@
srcs += 'gfxnvidia.c'
cargs += '-DCONFIG_GFXNVIDIA=1'
endif
+if config_raiden
+ srcs += 'raiden_debug_spi.c'
+ srcs += 'usb_device.c'
+ cargs += '-DCONFIG_RAIDEN=1'
+endif
if config_internal
srcs += 'board_enable.c'
srcs += 'cbtable.c'
diff --git a/meson_options.txt b/meson_options.txt
index b7633d0..4334814 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -13,6 +13,7 @@
option('config_dummy', type : 'boolean', value : true, description : 'dummy tracing')
option('config_ft2232_spi', type : 'boolean', value : true, description : 'FT2232 SPI dongles')
option('config_gfxnvidia', type : 'boolean', value : true, description : 'NVIDIA graphics cards')
+option('config_raiden', type : 'boolean', value : true, description : 'ChromiumOS Servo DUT debug board')
option('config_internal', type : 'boolean', value : true, description : 'internal/onboard')
option('config_internal_dmi', type : 'boolean', value : true, description : 'Use internal DMI parser')
option('config_it8212', type : 'boolean', value : true, description : 'ITE IT8212F PATA')
diff --git a/programmer.h b/programmer.h
index 3cf53b9..08500c6 100644
--- a/programmer.h
+++ b/programmer.h
@@ -43,6 +43,9 @@
#if CONFIG_GFXNVIDIA == 1
PROGRAMMER_GFXNVIDIA,
#endif
+#if CONFIG_RAIDEN == 1
+ PROGRAMMER_RAIDEN,
+#endif
#if CONFIG_DRKAISER == 1
PROGRAMMER_DRKAISER,
#endif
@@ -401,6 +404,11 @@
extern const struct dev_entry gfx_nvidia[];
#endif
+/* raiden_debug_spi.c */
+#if CONFIG_RAIDEN == 1
+int raiden_debug_spi_init(void);
+#endif
+
/* drkaiser.c */
#if CONFIG_DRKAISER == 1
int drkaiser_init(void);
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
new file mode 100644
index 0000000..9af0f7d
--- /dev/null
+++ b/raiden_debug_spi.c
@@ -0,0 +1,369 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+/*
+ * This SPI flash programming interface is designed to talk to a Chromium OS
+ * device over a Raiden USB connection. The USB connection is routed to a
+ * microcontroller running an image compiled from:
+ *
+ * https://chromium.googlesource.com/chromiumos/platform/ec
+ *
+ * The protocol for the USB-SPI bridge is documented in the following file in
+ * that respository:
+ *
+ * chip/stm32/usb_spi.c
+ */
+
+#include "programmer.h"
+#include "spi.h"
+#include "usb_device.h"
+
+#include <libusb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define GOOGLE_VID 0x18D1
+#define GOOGLE_RAIDEN_SPI_SUBCLASS 0x51
+#define GOOGLE_RAIDEN_SPI_PROTOCOL 0x01
+
+enum raiden_debug_spi_request {
+ RAIDEN_DEBUG_SPI_REQ_ENABLE = 0x0000,
+ RAIDEN_DEBUG_SPI_REQ_DISABLE = 0x0001,
+ RAIDEN_DEBUG_SPI_REQ_ENABLE_AP = 0x0002,
+ RAIDEN_DEBUG_SPI_REQ_ENABLE_EC = 0x0003,
+};
+
+#define PACKET_HEADER_SIZE 2
+#define MAX_PACKET_SIZE 64
+
+/*
+ * This timeout is so large because the Raiden SPI timeout is 800ms.
+ */
+#define TRANSFER_TIMEOUT_MS 1000
+
+struct usb_device *device = NULL;
+uint8_t in_endpoint = 0;
+uint8_t out_endpoint = 0;
+
+static int send_command(struct flashctx *flash,
+ unsigned int write_count,
+ unsigned int read_count,
+ const unsigned char *write_buffer,
+ unsigned char *read_buffer)
+{
+ uint8_t buffer[MAX_PACKET_SIZE];
+ int transferred;
+
+ if (write_count > MAX_PACKET_SIZE - PACKET_HEADER_SIZE) {
+ msg_perr("Raiden: invalid write_count of %d\n", write_count);
+ return SPI_INVALID_LENGTH;
+ }
+
+ if (read_count > MAX_PACKET_SIZE - PACKET_HEADER_SIZE) {
+ msg_perr("Raiden: invalid read_count of %d\n", read_count);
+ return SPI_INVALID_LENGTH;
+ }
+
+ buffer[0] = write_count;
+ buffer[1] = read_count;
+
+ memcpy(buffer + PACKET_HEADER_SIZE, write_buffer, write_count);
+
+ CHECK(LIBUSB(libusb_bulk_transfer(device->handle,
+ out_endpoint,
+ buffer,
+ write_count + PACKET_HEADER_SIZE,
+ &transferred,
+ TRANSFER_TIMEOUT_MS)),
+ "Raiden: OUT transfer failed\n"
+ " write_count = %d\n"
+ " read_count = %d\n",
+ write_count,
+ read_count);
+
+ if ((unsigned) transferred != write_count + PACKET_HEADER_SIZE) {
+ msg_perr("Raiden: Write failure (wrote %d, expected %d)\n",
+ transferred, write_count + PACKET_HEADER_SIZE);
+ return 0x10001;
+ }
+
+ CHECK(LIBUSB(libusb_bulk_transfer(device->handle,
+ in_endpoint,
+ buffer,
+ read_count + PACKET_HEADER_SIZE,
+ &transferred,
+ TRANSFER_TIMEOUT_MS)),
+ "Raiden: IN transfer failed\n"
+ " write_count = %d\n"
+ " read_count = %d\n",
+ write_count,
+ read_count);
+
+ if ((unsigned) transferred != read_count + PACKET_HEADER_SIZE) {
+ msg_perr("Raiden: Read failure (read %d, expected %d)\n",
+ transferred, read_count + PACKET_HEADER_SIZE);
+ return 0x10002;
+ }
+
+ memcpy(read_buffer, buffer + PACKET_HEADER_SIZE, read_count);
+
+ return buffer[0] | (buffer[1] << 8);
+}
+
+/*
+ * Unfortunately there doesn't seem to be a way to specify the maximum number
+ * of bytes that your SPI device can read/write, these values are the maximum
+ * data chunk size that flashrom will package up with an additional five bytes
+ * of command for the flash device, resulting in a 62 byte packet, that we then
+ * add two bytes to in either direction, making our way up to the 64 byte
+ * maximum USB packet size for the device.
+ *
+ * The largest command that flashrom generates is the byte program command, so
+ * we use that command header maximum size here.
+ */
+#define MAX_DATA_SIZE (MAX_PACKET_SIZE - \
+ PACKET_HEADER_SIZE - \
+ JEDEC_BYTE_PROGRAM_OUTSIZE)
+
+static const struct spi_master spi_master_raiden_debug = {
+ .features = SPI_MASTER_4BA,
+ .max_data_read = MAX_DATA_SIZE,
+ .max_data_write = MAX_DATA_SIZE,
+ .command = send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+};
+
+static int match_endpoint(struct libusb_endpoint_descriptor const *descriptor,
+ enum libusb_endpoint_direction direction)
+{
+ return (((descriptor->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) ==
+ direction) &&
+ ((descriptor->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) ==
+ LIBUSB_TRANSFER_TYPE_BULK));
+}
+
+static int find_endpoints(struct usb_device *dev, uint8_t *in_ep, uint8_t *out_ep)
+{
+ int i;
+ int in_count = 0;
+ int out_count = 0;
+
+ for (i = 0; i < dev->interface_descriptor->bNumEndpoints; i++) {
+ struct libusb_endpoint_descriptor const *endpoint =
+ &dev->interface_descriptor->endpoint[i];
+
+ if (match_endpoint(endpoint, LIBUSB_ENDPOINT_IN)) {
+ in_count++;
+ *in_ep = endpoint->bEndpointAddress;
+ } else if (match_endpoint(endpoint, LIBUSB_ENDPOINT_OUT)) {
+ out_count++;
+ *out_ep = endpoint->bEndpointAddress;
+ }
+ }
+
+ if (in_count != 1 || out_count != 1) {
+ msg_perr("Raiden: Failed to find one IN and one OUT endpoint\n"
+ " found %d IN and %d OUT endpoints\n",
+ in_count,
+ out_count);
+ return 1;
+ }
+
+ msg_pdbg("Raiden: Found IN endpoint = 0x%02x\n", *in_ep);
+ msg_pdbg("Raiden: Found OUT endpoint = 0x%02x\n", *out_ep);
+
+ return 0;
+}
+
+static int shutdown(void * data)
+{
+ CHECK(LIBUSB(libusb_control_transfer(
+ device->handle,
+ LIBUSB_ENDPOINT_OUT |
+ LIBUSB_REQUEST_TYPE_VENDOR |
+ LIBUSB_RECIPIENT_INTERFACE,
+ RAIDEN_DEBUG_SPI_REQ_DISABLE,
+ 0,
+ device->interface_descriptor->bInterfaceNumber,
+ NULL,
+ 0,
+ TRANSFER_TIMEOUT_MS)),
+ "Raiden: Failed to disable SPI bridge\n");
+
+ usb_device_free(device);
+
+ device = NULL;
+ libusb_exit(NULL);
+
+ return 0;
+}
+
+static int get_target()
+{
+ int request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE;
+
+ char *target_str = extract_programmer_param("target");
+ if (target_str) {
+ if (!strcasecmp(target_str, "ap"))
+ request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE_AP;
+ else if (!strcasecmp(target_str, "ec"))
+ request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE_EC;
+ else {
+ msg_perr("Invalid target: %s\n", target_str);
+ request_enable = -1;
+ }
+ }
+ free(target_str);
+
+ return request_enable;
+}
+
+static void free_dev_list(struct usb_device **dev_lst)
+{
+ struct usb_device *dev = *dev_lst;
+ /* free devices we don't care about */
+ dev = dev->next;
+ while (dev)
+ dev = usb_device_free(dev);
+}
+
+int raiden_debug_spi_init(void)
+{
+ struct usb_match match;
+ char *serial = extract_programmer_param("serial");
+ struct usb_device *current;
+ int found = 0;
+
+ int request_enable = get_target();
+ if (request_enable < 0)
+ return 1;
+
+ usb_match_init(&match);
+
+ usb_match_value_default(&match.vid, GOOGLE_VID);
+ usb_match_value_default(&match.class, LIBUSB_CLASS_VENDOR_SPEC);
+ usb_match_value_default(&match.subclass, GOOGLE_RAIDEN_SPI_SUBCLASS);
+ usb_match_value_default(&match.protocol, GOOGLE_RAIDEN_SPI_PROTOCOL);
+
+ CHECK(LIBUSB(libusb_init(NULL)), "Raiden: libusb_init failed\n");
+
+ CHECK(usb_device_find(&match, ¤t),
+ "Raiden: Failed to find devices\n");
+
+ while (current) {
+ device = current;
+
+ if (find_endpoints(device, &in_endpoint, &out_endpoint)) {
+ msg_pdbg("Raiden: Failed to find valid endpoints on device");
+ usb_device_show(" ", current);
+ goto loop_end;
+ }
+
+ if (usb_device_claim(device)) {
+ msg_pdbg("Raiden: Failed to claim USB device");
+ usb_device_show(" ", current);
+ goto loop_end;
+ }
+
+ if (!serial) {
+ found = 1;
+ goto loop_end;
+ } else {
+ unsigned char dev_serial[32];
+ struct libusb_device_descriptor descriptor;
+ int rc;
+
+ memset(dev_serial, 0, sizeof(dev_serial));
+
+ if (libusb_get_device_descriptor(device->device, &descriptor)) {
+ msg_pdbg("USB: Failed to get device descriptor.\n");
+ goto loop_end;
+ }
+
+ rc = libusb_get_string_descriptor_ascii(device->handle,
+ descriptor.iSerialNumber,
+ dev_serial,
+ sizeof(dev_serial));
+ if (rc < 0) {
+ LIBUSB(rc);
+ } else {
+ if (strcmp(serial, (char *)dev_serial)) {
+ msg_pdbg("Raiden: Serial number %s did not match device", serial);
+ usb_device_show(" ", current);
+ } else {
+ msg_pinfo("Raiden: Serial number %s matched device", serial);
+ usb_device_show(" ", current);
+ found = 1;
+ }
+ }
+ }
+
+loop_end:
+ if (found)
+ break;
+ else
+ current = usb_device_free(current);
+ }
+
+ if (!device || !found) {
+ msg_perr("Raiden: No usable device found.\n");
+ return 1;
+ }
+
+ free_dev_list(¤t);
+
+ CHECK(LIBUSB(libusb_control_transfer(
+ device->handle,
+ LIBUSB_ENDPOINT_OUT |
+ LIBUSB_REQUEST_TYPE_VENDOR |
+ LIBUSB_RECIPIENT_INTERFACE,
+ request_enable,
+ 0,
+ device->interface_descriptor->bInterfaceNumber,
+ NULL,
+ 0,
+ TRANSFER_TIMEOUT_MS)),
+ "Raiden: Failed to enable SPI bridge\n");
+
+ register_spi_master(&spi_master_raiden_debug);
+ register_shutdown(shutdown, NULL);
+
+ return 0;
+}
diff --git a/usb_device.c b/usb_device.c
new file mode 100644
index 0000000..0909694
--- /dev/null
+++ b/usb_device.c
@@ -0,0 +1,366 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+#include "programmer.h"
+#include "spi.h"
+#include "usb_device.h"
+
+#include <assert.h>
+#include <libusb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Possibly extract a programmer parameter and use it to initialize the given
+ * match value structure.
+ */
+static void usb_match_value_init(struct usb_match_value *match,
+ char const *parameter)
+{
+ char *string = extract_programmer_param(parameter);
+
+ match->name = parameter;
+
+ if (string) {
+ match->set = 1;
+ match->value = strtol(string, NULL, 0);
+ } else {
+ match->set = 0;
+ }
+
+ free(string);
+}
+
+#define USB_MATCH_VALUE_INIT(NAME) \
+ usb_match_value_init(&match->NAME, #NAME)
+
+void usb_match_init(struct usb_match *match)
+{
+ USB_MATCH_VALUE_INIT(vid);
+ USB_MATCH_VALUE_INIT(pid);
+ USB_MATCH_VALUE_INIT(bus);
+ USB_MATCH_VALUE_INIT(address);
+ USB_MATCH_VALUE_INIT(config);
+ USB_MATCH_VALUE_INIT(interface);
+ USB_MATCH_VALUE_INIT(altsetting);
+ USB_MATCH_VALUE_INIT(class);
+ USB_MATCH_VALUE_INIT(subclass);
+ USB_MATCH_VALUE_INIT(protocol);
+}
+
+void usb_match_value_default(struct usb_match_value *value,
+ long int default_value)
+{
+ if (value->set)
+ return;
+
+ value->set = 1;
+ value->value = default_value;
+}
+
+/*
+ * Match the value against a possible user supplied parameter.
+ *
+ * Return:
+ * 0: The user supplied the given parameter and it did not match the value.
+ * 1: Either the user didn't supply the parameter, or they did and it
+ * matches the given value.
+ */
+static int check_match(struct usb_match_value const *match_value, int value)
+{
+ int reject = match_value->set && (match_value->value != value);
+
+ if (reject)
+ msg_pdbg("USB: Rejecting device because %s = %d != %d\n",
+ match_value->name,
+ value,
+ match_value->value);
+
+ return !reject;
+}
+
+/*
+ * Allocate a copy of device and add it to the head of the devices list.
+ */
+static void add_device(struct usb_device *device,
+ struct usb_device **devices)
+{
+ struct usb_device *copy = malloc(sizeof(struct usb_device));
+
+ assert(copy != NULL);
+
+ *copy = *device;
+
+ copy->next = *devices;
+ *devices = copy;
+
+ libusb_ref_device(copy->device);
+}
+
+/*
+ * Look through the interfaces of the current device config for a match. Stop
+ * looking after the first valid match is found.
+ *
+ * Return:
+ * 0: No matching interface was found.
+ * 1: A complete match was found and added to the devices list.
+ */
+static int find_interface(struct usb_match const *match,
+ struct usb_device *current,
+ struct usb_device **devices)
+{
+ int i, j;
+
+ for (i = 0; i < current->config_descriptor->bNumInterfaces; ++i) {
+ struct libusb_interface const *interface;
+
+ interface = ¤t->config_descriptor->interface[i];
+
+ for (j = 0; j < interface->num_altsetting; ++j) {
+ struct libusb_interface_descriptor const *descriptor;
+
+ descriptor = &interface->altsetting[j];
+
+ if (check_match(&match->interface,
+ descriptor->bInterfaceNumber) &&
+ check_match(&match->altsetting,
+ descriptor->bAlternateSetting) &&
+ check_match(&match->class,
+ descriptor->bInterfaceClass) &&
+ check_match(&match->subclass,
+ descriptor->bInterfaceSubClass) &&
+ check_match(&match->protocol,
+ descriptor->bInterfaceProtocol)) {
+ current->interface_descriptor = descriptor;
+ add_device(current, devices);
+ msg_pdbg("USB: Found matching device\n");
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Look through the configs of the current device for a match. Stop looking
+ * after the first valid match is found.
+ *
+ * Return:
+ * 0: All configurations successfully checked, one may have been added to
+ * the list.
+ * non-zero: There was a failure while checking for a match.
+ */
+static int find_config(struct usb_match const *match,
+ struct usb_device *current,
+ struct libusb_device_descriptor const *device_descriptor,
+ struct usb_device **devices)
+{
+ int i;
+
+ for (i = 0; i < device_descriptor->bNumConfigurations; ++i) {
+ CHECK(LIBUSB(libusb_get_config_descriptor(
+ current->device,
+ i,
+ ¤t->config_descriptor)),
+ "USB: Failed to get config descriptor");
+
+ if (check_match(&match->config,
+ current->config_descriptor->
+ bConfigurationValue) &&
+ find_interface(match, current, devices))
+ break;
+
+ libusb_free_config_descriptor(current->config_descriptor);
+ }
+
+ return 0;
+}
+
+int usb_device_find(struct usb_match const *match, struct usb_device **devices)
+{
+ libusb_device **list;
+ size_t count;
+ size_t i;
+
+ *devices = NULL;
+
+ CHECK(LIBUSB(count = libusb_get_device_list(NULL, &list)),
+ "USB: Failed to get device list");
+
+ for (i = 0; i < count; ++i) {
+ struct libusb_device_descriptor descriptor;
+ struct usb_device current = {
+ .device = list[i],
+ .handle = NULL,
+ .next = NULL,
+ };
+
+ uint8_t bus = libusb_get_bus_number(list[i]);
+ uint8_t address = libusb_get_device_address(list[i]);
+
+ msg_pdbg("USB: Inspecting device (Bus %d, Address %d)\n",
+ bus,
+ address);
+
+ CHECK(LIBUSB(libusb_get_device_descriptor(list[i],
+ &descriptor)),
+ "USB: Failed to get device descriptor");
+
+ if (check_match(&match->vid, descriptor.idVendor) &&
+ check_match(&match->pid, descriptor.idProduct) &&
+ check_match(&match->bus, bus) &&
+ check_match(&match->address, address))
+ CHECK(find_config(match,
+ ¤t,
+ &descriptor,
+ devices),
+ "USB: Failed to find config");
+ }
+
+ libusb_free_device_list(list, 1);
+
+ return (*devices == NULL);
+}
+
+/*
+ * If the underlying libusb device is not open, open it.
+ *
+ * Return:
+ * 0: The device was already open or was successfully opened.
+ * non-zero: There was a failure while opening the device.
+ */
+static int usb_device_open(struct usb_device *device)
+{
+ if (device->handle == NULL)
+ CHECK(LIBUSB(libusb_open(device->device, &device->handle)),
+ "USB: Failed to open device\n");
+
+ return 0;
+}
+
+int usb_device_show(char const *prefix, struct usb_device *device)
+{
+ struct libusb_device_descriptor descriptor;
+ unsigned char product[256];
+
+ CHECK(usb_device_open(device), "USB: Failed to open device\n");
+
+ CHECK(LIBUSB(libusb_get_device_descriptor(device->device, &descriptor)),
+ "USB: Failed to get device descriptor\n");
+
+ CHECK(LIBUSB(libusb_get_string_descriptor_ascii(
+ device->handle,
+ descriptor.iProduct,
+ product,
+ sizeof(product))),
+ "USB: Failed to get device product string\n");
+
+ product[255] = '\0';
+
+ msg_perr("%sbus=0x%02x,address=0x%02x | %s\n",
+ prefix,
+ libusb_get_bus_number(device->device),
+ libusb_get_device_address(device->device),
+ product);
+
+ return 0;
+}
+
+int usb_device_claim(struct usb_device *device)
+{
+ int current_config;
+
+ CHECK(usb_device_open(device), "USB: Failed to open device\n");
+
+ CHECK(LIBUSB(libusb_get_configuration(device->handle,
+ ¤t_config)),
+ "USB: Failed to get current device configuration\n");
+
+ if (current_config != device->config_descriptor->bConfigurationValue)
+ CHECK(LIBUSB(libusb_set_configuration(
+ device->handle,
+ device->
+ config_descriptor->
+ bConfigurationValue)),
+ "USB: Failed to set new configuration from %d to %d\n",
+ current_config,
+ device->config_descriptor->bConfigurationValue);
+
+ CHECK(LIBUSB(libusb_set_auto_detach_kernel_driver(device->handle, 1)),
+ "USB: Failed to enable auto kernel driver detach\n");
+
+ CHECK(LIBUSB(libusb_claim_interface(device->handle,
+ device->
+ interface_descriptor->
+ bInterfaceNumber)),
+ "USB: Could not claim device interface %d\n",
+ device->interface_descriptor->bInterfaceNumber);
+
+ if (device->interface_descriptor->bAlternateSetting != 0)
+ CHECK(LIBUSB(libusb_set_interface_alt_setting(
+ device->handle,
+ device->
+ interface_descriptor->
+ bInterfaceNumber,
+ device->
+ interface_descriptor->
+ bAlternateSetting)),
+ "USB: Failed to set alternate setting %d\n",
+ device->interface_descriptor->bAlternateSetting);
+
+ return 0;
+}
+
+struct usb_device *usb_device_free(struct usb_device *device)
+{
+ struct usb_device *next = device->next;
+
+ if (device->handle != NULL)
+ libusb_close(device->handle);
+
+ /*
+ * This unref balances the ref added in the add_device function.
+ */
+ libusb_unref_device(device->device);
+ libusb_free_config_descriptor(device->config_descriptor);
+
+ free(device);
+
+ return next;
+}
diff --git a/usb_device.h b/usb_device.h
new file mode 100644
index 0000000..46d2458
--- /dev/null
+++ b/usb_device.h
@@ -0,0 +1,201 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+/*
+ * USB device matching framework
+ *
+ * This can be used to match a USB device by a number of different parameters.
+ * The parameters can be passed on the command line and defaults can be set
+ * by the programmer.
+ */
+
+#include <libusb.h>
+#include <stdint.h>
+
+/*
+ * Check Macro
+ *
+ * The check macro simplifies common return error code checking logic. If the
+ * expression does not evaluate to zero then the string error is printed and
+ * the expressions result is imediately returned, else the result is available
+ * as the value of the CHECK expression statement.
+ */
+
+#define CHECK(expression, string...) \
+ ({ \
+ int error__ = (expression); \
+ \
+ if (error__ != 0) { \
+ msg_perr(string); \
+ return error__; \
+ } \
+ \
+ error__; \
+ })
+
+/*
+ * The LIBUSB macro converts a libusb failure code into an error code that
+ * flashrom recognizes. It also displays additional libusb specific
+ * information about the failure.
+ */
+#define LIBUSB(expression) \
+ ({ \
+ int libusb_error__ = (expression); \
+ \
+ if (libusb_error__ < 0) { \
+ msg_perr("libusb error: %s:%d %s\n", \
+ __FILE__, \
+ __LINE__, \
+ libusb_error_name(libusb_error__)); \
+ libusb_error__ = 0x20000 | -libusb_error__; \
+ } else { \
+ libusb_error__ = 0; \
+ } \
+ \
+ libusb_error__; \
+ })
+
+/*
+ * A USB match and associated value struct are used to encode the information
+ * about a device against which we wish to match. If the value of a
+ * usb_match_value has been set then a device must match that value. The name
+ * of the usb_match_value is used to fetch the programmer parameter from the
+ * flashrom command line and is the same as the name of the corresponding
+ * field in usb_match.
+ */
+struct usb_match_value {
+ char const *name;
+ int value;
+ int set;
+};
+
+struct usb_match {
+ struct usb_match_value bus;
+ struct usb_match_value address;
+ struct usb_match_value vid;
+ struct usb_match_value pid;
+ struct usb_match_value serial;
+ struct usb_match_value config;
+ struct usb_match_value interface;
+ struct usb_match_value altsetting;
+ struct usb_match_value class;
+ struct usb_match_value subclass;
+ struct usb_match_value protocol;
+};
+
+/*
+ * Initialize a usb_match structure so that each value's name matches the
+ * values name in the usb_match structure (so bus.name == "bus"...), and
+ * look for each value in the flashrom command line via
+ * extract_programmer_param. If the value is found convert it to an integer
+ * using strtol, accepting hex, decimal and octal encoding.
+ */
+void usb_match_init(struct usb_match *match);
+
+/*
+ * Add a default value to a usb_match_value. This must be done after calling
+ * usb_match_init. If usb_match_init already set the value of a usb_match_value
+ * we do nothing, otherwise set the value to default_value. This ensures that
+ * parameters passed on the command line override defaults.
+ */
+void usb_match_value_default(struct usb_match_value *match,
+ long int default_value);
+
+/*
+ * The usb_device structure is an entry in a linked list of devices that were
+ * matched by usb_device_find.
+ */
+struct usb_device {
+ struct libusb_device *device;
+ struct libusb_config_descriptor *config_descriptor;
+ struct libusb_interface_descriptor const *interface_descriptor;
+
+ /*
+ * Initially NULL, the libusb_device_handle is only valid once the
+ * usb_device has been successfully passed to usb_device_show or
+ * usb_device_claim.
+ */
+ struct libusb_device_handle *handle;
+
+ /*
+ * Link to next device, or NULL
+ */
+ struct usb_device *next;
+};
+
+/*
+ * Find and return a list of all compatible devices. Each device is added to
+ * the list with its first valid configuration and interface. If an alternate
+ * configuration (config, interface, altsetting...) is desired the specifics
+ * can be supplied as programmer parameters.
+ *
+ * Return:
+ * 0: At least one matching device was found.
+ * 1: No matching devices were found.
+ */
+int usb_device_find(struct usb_match const *match, struct usb_device **devices);
+
+/*
+ * Display the devices bus and address as well as its product string. The
+ * underlying libusb device is opened if it is not already open.
+ *
+ * Return:
+ * 0: The device information was displayed.
+ * non-zero: There was a failure while displaying the device information.
+ */
+int usb_device_show(char const *prefix, struct usb_device *device);
+
+/*
+ * Open the underlying libusb device, set its config, claim the interface and
+ * select the correct alternate interface.
+ *
+ * Return:
+ * 0: The device was successfully claimed.
+ * non-zero: There was a failure while trying to claim the device.
+ */
+int usb_device_claim(struct usb_device *device);
+
+/*
+ * Free a usb_device structure.
+ *
+ * This ensures that the libusb device is closed and that all allocated
+ * handles and descriptors are freed.
+ *
+ * Return:
+ * The next device in the device list.
+ */
+struct usb_device *usb_device_free(struct usb_device *device);
--
To view, visit https://review.coreboot.org/c/flashrom/+/38209
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ifad273a708acea4de797a0808be58960635a8864
Gerrit-Change-Number: 38209
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: newchange
Alan Green has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/35479 )
Change subject: flashchips.c: Take GD25LQ40 from downstream
......................................................................
flashchips.c: Take GD25LQ40 from downstream
Take definition of GD25LQ40 from ChromiumOS repository. This chip was
added in `commit 59543cd1` by dnschneid(a)chromium.org on 2016-04-27. The
commit message notes that some testing had been done, even thought the
.tested attribute was left as UNTESTED.
Signed-off-by: Alan Green <avg(a)google.com>
Change-Id: I978745b38536cda807adf07af4e4d093d0d93ad1
---
M flashchips.c
1 file changed, 2 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/79/35479/1
diff --git a/flashchips.c b/flashchips.c
index 5c797fd..ac07fa8 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -6009,7 +6009,7 @@
.total_size = 512,
.page_size = 256,
/* OTP: 1024B total, 256B reserved; read 0x48; write 0x42, erase 0x44 */
- .feature_bits = FEATURE_WRSR_WREN | FEATURE_OTP,
+ .feature_bits = FEATURE_WRSR_WREN,
.tested = TEST_UNTESTED,
.probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
@@ -6032,8 +6032,7 @@
.block_erase = spi_block_erase_c7,
}
},
- .printlock = spi_prettyprint_status_register_bp4_srwd,
- .unlock = spi_disable_blockprotect_bp4_srwd, /* TODO: 2nd status reg (read with 0x35) */
+ .unlock = spi_disable_blockprotect,
.write = spi_chip_write_256,
.read = spi_chip_read, /* Fast read (0x0B) and multi I/O supported */
.voltage = {1695, 1950},
--
To view, visit https://review.coreboot.org/c/flashrom/+/35479
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I978745b38536cda807adf07af4e4d093d0d93ad1
Gerrit-Change-Number: 35479
Gerrit-PatchSet: 1
Gerrit-Owner: Alan Green <avg(a)google.com>
Gerrit-MessageType: newchange
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/30521
Change subject: dediprog: Use 4BA page program without 0x12
......................................................................
dediprog: Use 4BA page program without 0x12
It's not clear exactly what the difference is between
WRITE_MODE_4B_ADDR_256B_PAGE_PGM with and without _0x12 from the SF600
command spec, but the former seems to work more reliably.
Tested using an SF600 (FW v7.2.21), IS25LP256D, W25Q256JV, and
MX25L25735.
Change-Id: I3cb37ec8838f5bb02948ed52b4a2906fa033cf83
Signed-off-by: David Hendricks <david.hendricks(a)gmail.com>
---
M dediprog.c
1 file changed, 2 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/30521/1
diff --git a/dediprog.c b/dediprog.c
index 2a190d2..303f1d5 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -398,7 +398,8 @@
}
} else if (dedi_spi_cmd == WRITE_MODE_PAGE_PGM) {
if (flash->chip->feature_bits & FEATURE_4BA_WRITE) {
- data_packet[3] = WRITE_MODE_4B_ADDR_256B_PAGE_PGM_0x12;
+// data_packet[3] = WRITE_MODE_4B_ADDR_256B_PAGE_PGM_0x12;
+ data_packet[3] = WRITE_MODE_4B_ADDR_256B_PAGE_PGM;
data_packet[4] = JEDEC_BYTE_PROGRAM_4BA;
use_4ba = true;
} else if (flash->in_4ba_mode) {
--
To view, visit https://review.coreboot.org/c/flashrom/+/30521
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3cb37ec8838f5bb02948ed52b4a2906fa033cf83
Gerrit-Change-Number: 30521
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
Hrvoje Čavrak has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/39841 )
Change subject: udelay.c: Enable providing delay calibration value through CLI
......................................................................
udelay.c: Enable providing delay calibration value through CLI
This commit implements --delay option to retrieve and provide the calibration
loop delay through the command line. The delay calibration procedure can take
up to few seconds, which adds up when executed a number of times consecutively.
Therefore, this provides a means to execute it only once, and then re-use the
calibrated value on subsequent runs. Also, it implements a sanity check,
expecting the value to land within 10% of the theoretical delay expectance,
otherwise it ignores the provided value and runs the calibration procedure
instead.
modified: cli_classic.c
modified: flashrom.8.tmpl
modified: programmer.h
modified: udelay.c
Change-Id: Iea2a7f62300663bc0a32ed4abced57c8c55c90c8
Signed-off-by: Hrvoje Cavrak <hrvoje(a)hrvoje.org>
---
M cli_classic.c
M flashrom.8.tmpl
M programmer.h
M udelay.c
4 files changed, 51 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/41/39841/1
diff --git a/cli_classic.c b/cli_classic.c
index 73cc417..f0842d4 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -63,6 +63,8 @@
" -o | --output <logfile> log output to <logfile>\n"
" --flash-contents <ref-file> assume flash contents to be <ref-file>\n"
" -L | --list-supported print supported devices\n"
+ " -d | --loop-delay <value> set loop delay calibration manually\n"
+ " --loop-delay get show loop delay calibration\n"
#if CONFIG_PRINT_WIKI == 1
" -z | --list-supported-wiki print supported devices in wiki syntax\n"
#endif
@@ -118,6 +120,7 @@
int flash_name = 0, flash_size = 0;
int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
+ unsigned long provided_delay = 0;
struct flashrom_layout *layout = NULL;
enum programmer prog = PROGRAMMER_INVALID;
enum {
@@ -130,7 +133,7 @@
};
int ret = 0;
- static const char optstring[] = "r:Rw:v:nNVEfc:l:i:p:Lzho:";
+ static const char optstring[] = "r:Rw:v:nNVEfc:l:i:p:Lzho:d:";
static const struct option long_options[] = {
{"read", 1, NULL, 'r'},
{"write", 1, NULL, 'w'},
@@ -156,6 +159,7 @@
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'R'},
{"output", 1, NULL, 'o'},
+ {"delay", 1, NULL, 'd'},
{NULL, 0, NULL, 0},
};
@@ -362,6 +366,14 @@
}
#endif /* STANDALONE */
break;
+ case 'd':
+ provided_delay = strtoul(strdup(optarg), NULL, 0);
+ if (!provided_delay) {
+ /* Make it easy for scripts to parse this by omitting anything else */
+ msg_pinfo("%lu\n", get_calibration_value());
+ exit(0);
+ }
+ break;
default:
cli_classic_abort_usage(NULL);
break;
@@ -454,7 +466,10 @@
}
/* FIXME: Delay calibration should happen in programmer code. */
- myusec_calibrate_delay();
+ if (provided_delay)
+ set_external_calibration(provided_delay);
+ else
+ myusec_calibrate_delay();
if (programmer_init(prog, pparam)) {
msg_perr("Error: Programmer initialization failed.\n");
diff --git a/flashrom.8.tmpl b/flashrom.8.tmpl
index fde98c0..c14f2de 100644
--- a/flashrom.8.tmpl
+++ b/flashrom.8.tmpl
@@ -50,7 +50,7 @@
[\fB\-E\fR|\fB\-r\fR <file>|\fB\-w\fR <file>|\fB\-v\fR <file>]
[(\fB\-l\fR <file>|\fB\-\-ifd|\fB \-\-fmap\fR|\fB\-\-fmap-file\fR <file>) [\fB\-i\fR <image>]]
[\fB\-n\fR] [\fB\-N\fR] [\fB\-f\fR])]
- [\fB\-V\fR[\fBV\fR[\fBV\fR]]] [\fB-o\fR <logfile>]
+ [\fB\-V\fR[\fBV\fR[\fBV\fR]]] [\fB-o\fR <logfile>] [\fB-d\fR get | <value>]
.SH DESCRIPTION
.B flashrom
is a utility for detecting, reading, writing, verifying and erasing flash
@@ -364,6 +364,18 @@
.TP
.B "\-R, \-\-version"
Show version information and exit.
+.TP
+.B "\-d, \-\-loop\-delay"
+Retrieve the loop calibration delay value or provide one externally. Calibrate
+delay procedure can take a few seconds and for repeated execution on a large
+number of hosts it can provide a significant overhead. Therefore, this argument
+makes it possible to provide the calibration delay through the command line
+option.
+
+To retrieve the value, run
+.BR "flashrom \-\-loop\-delay get " "and to provide it during programming, add "
+.BR "\-\-loop\-delay <value> " "to your command."
+
.SH PROGRAMMER-SPECIFIC INFORMATION
Some programmer drivers accept further parameters to set programmer-specific
parameters. These parameters are separated from the programmer name by a
diff --git a/programmer.h b/programmer.h
index 08500c6..a659a18 100644
--- a/programmer.h
+++ b/programmer.h
@@ -277,6 +277,8 @@
void myusec_calibrate_delay(void);
void internal_sleep(unsigned int usecs);
void internal_delay(unsigned int usecs);
+unsigned long get_calibration_value(void);
+void set_external_calibration(unsigned long external_micro);
#if CONFIG_INTERNAL == 1
/* board_enable.c */
diff --git a/udelay.c b/udelay.c
index 6c0efc4..90c4c9e 100644
--- a/udelay.c
+++ b/udelay.c
@@ -221,6 +221,25 @@
msg_pinfo("OK.\n");
}
+void set_external_calibration(unsigned long external_micro)
+{
+ micro = external_micro;
+ unsigned long elapsed = measure_delay(100000);
+ /* Do a sanity check if the provided parameter makes loops fall within 10% of
+ * the desired value. Otherwise, ignore provided value and recalibrate.
+ */
+ if (elapsed > 90000 && elapsed < 110000)
+ msg_pinfo("Provided delay is acceptable!\n");
+ else
+ myusec_calibrate_delay();
+}
+
+unsigned long get_calibration_value(void)
+{
+ myusec_calibrate_delay();
+ return micro;
+}
+
/* Not very precise sleep. */
void internal_sleep(unsigned int usecs)
{
--
To view, visit https://review.coreboot.org/c/flashrom/+/39841
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Iea2a7f62300663bc0a32ed4abced57c8c55c90c8
Gerrit-Change-Number: 39841
Gerrit-PatchSet: 1
Gerrit-Owner: Hrvoje Čavrak <github(a)hrvoje.org>
Gerrit-MessageType: newchange
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43602 )
Change subject: git-hooks: Add check-style for pre-commit hook
......................................................................
git-hooks: Add check-style for pre-commit hook
This imports check-style and some related lint tools from coreboot
for the pre-commit hook:
- Add check-style rule to Makefile
- Replace the current pre-commit hook with the one from coreboot,
omitting lint-stable for the time being.
- Import checkpatch.pl, along with certain dependencies (spelling.txt
and const_structs.checkpatch) and .checkpatch.conf.
- Add .clang-format from CB:38673.
Change-Id: Ieb77aa1aa2911e081c69c93929a2f1c4430cd2b9
Signed-off-by: David Hendricks <david.hendricks(a)gmail.com>
---
A .checkpatch.conf
A .clang-format
M Makefile
M util/git-hooks/pre-commit
A util/lint/check-style
A util/lint/checkpatch.pl
A util/lint/const_structs.checkpatch
A util/lint/lint-007-checkpatch
A util/lint/spelling.txt
9 files changed, 16,655 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/02/43602/1
--
To view, visit https://review.coreboot.org/c/flashrom/+/43602
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ieb77aa1aa2911e081c69c93929a2f1c4430cd2b9
Gerrit-Change-Number: 43602
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
Richard Hughes has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/42230 )
Change subject: meson: Do not compile with -DSTANDALONE
......................................................................
meson: Do not compile with -DSTANDALONE
This enables the -o option which is used to collect logs for debugging.
Change-Id: If6c12c682ba72cd519e30f1f8c96552322ff75e3
Signed-off-by: Richard Hughes <richard(a)hughsie.com>
---
M meson.build
1 file changed, 0 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/30/42230/1
diff --git a/meson.build b/meson.build
index 5d8e630..4b00339 100644
--- a/meson.build
+++ b/meson.build
@@ -415,7 +415,6 @@
],
c_args : [
cargs,
- '-DSTANDALONE',
'-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
'-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
],
--
To view, visit https://review.coreboot.org/c/flashrom/+/42230
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If6c12c682ba72cd519e30f1f8c96552322ff75e3
Gerrit-Change-Number: 42230
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Hughes <richard(a)hughsie.com>
Gerrit-MessageType: newchange
Nikolai Artemiev has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/42796 )
Change subject: ft2232_spi.c: align with Chrome OS flashrom
......................................................................
ft2232_spi.c: align with Chrome OS flashrom
Brings over various changes:
- Limit servo channel selection to valid range
- Use DIS_DIV_5 constant
- Update some comments
- Wrap long lines
Signed-off-by: Nikolai Artemiev <nartemiev(a)google.com>
Change-Id: I24c20e9b5d7e661d0180699bbd0d1447f6bf816f
---
M ft2232_spi.c
1 file changed, 20 insertions(+), 10 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/96/42796/1
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 87e6057..083e58f 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -110,7 +110,8 @@
{
int i;
for (i = 0; devs_ft2232spi[i].vendor_name != NULL; i++) {
- if ((devs_ft2232spi[i].device_id == ft2232_type) && (devs_ft2232spi[i].vendor_id == ft2232_vid))
+ if ((devs_ft2232spi[i].device_id == ft2232_type)
+ && (devs_ft2232spi[i].vendor_id == ft2232_vid))
return devs_ft2232spi[i].device_name;
}
return "unknown device";
@@ -120,7 +121,8 @@
{
int i;
for (i = 0; devs_ft2232spi[i].vendor_name != NULL; i++) {
- if ((devs_ft2232spi[i].device_id == ft2232_type) && (devs_ft2232spi[i].vendor_id == ft2232_vid))
+ if ((devs_ft2232spi[i].device_id == ft2232_type)
+ && (devs_ft2232spi[i].vendor_id == ft2232_vid))
return devs_ft2232spi[i].vendor_name;
}
return "unknown vendor";
@@ -132,7 +134,8 @@
int r;
r = ftdi_write_data(ftdic, (unsigned char *) buf, size);
if (r < 0) {
- msg_perr("ftdi_write_data: %d, %s\n", r, ftdi_get_error_string(ftdic));
+ msg_perr("ftdi_write_data: %d, %s\n", r,
+ ftdi_get_error_string(ftdic));
return 1;
}
return 0;
@@ -146,7 +149,8 @@
while (size > 0) {
r = ftdi_read_data(ftdic, (unsigned char *) buf, size);
if (r < 0) {
- msg_perr("ftdi_read_data: %d, %s\n", r, ftdi_get_error_string(ftdic));
+ msg_perr("ftdi_read_data: %d, %s\n", r,
+ ftdi_get_error_string(ftdic));
return 1;
}
buf += r;
@@ -183,8 +187,8 @@
enum ftdi_interface ft2232_interface = INTERFACE_A;
/*
* The 'H' chips can run with an internal clock of either 12 MHz or 60 MHz,
- * but the non-H chips can only run at 12 MHz. We enable the divide-by-5
- * prescaler on the former to run on the same speed.
+ * but the non-H chips can only run at 12 MHz. We disable the divide-by-5
+ * prescaler on 'H' chips so they run at 60MHz.
*/
uint8_t clock_5x = 1;
/* In addition to the prescaler mentioned above there is also another
@@ -193,7 +197,8 @@
* div = (1 + x) * 2 <-> x = div / 2 - 1
* Hence the expressible divisors are all even numbers between 2 and
* 2^17 (=131072) resulting in SCK frequencies of 6 MHz down to about
- * 92 Hz for 12 MHz inputs.
+ * 92 Hz for 12 MHz inputs and 30 MHz down to about 458 Hz for 60 MHz
+ * inputs.
*/
uint32_t divisor = DEFAULT_DIVISOR;
int f;
@@ -268,14 +273,17 @@
} else if (!strcasecmp(arg, "google-servo")) {
ft2232_vid = GOOGLE_VID;
ft2232_type = GOOGLE_SERVO_PID;
+ channel_count = 2;
} else if (!strcasecmp(arg, "google-servo-v2")) {
ft2232_vid = GOOGLE_VID;
ft2232_type = GOOGLE_SERVO_V2_PID1;
+ channel_count = 2;
/* Default divisor is too fast, and chip ID fails */
divisor = 6;
} else if (!strcasecmp(arg, "google-servo-v2-legacy")) {
ft2232_vid = GOOGLE_VID;
ft2232_type = GOOGLE_SERVO_V2_PID0;
+ channel_count = 2;
} else if (!strcasecmp(arg, "flyswatter")) {
ft2232_type = FTDI_FT2232H_PID;
channel_count = 2;
@@ -381,7 +389,8 @@
free(arg);
if (f < 0 && f != -5) {
- msg_perr("Unable to open FTDI device: %d (%s).\n", f, ftdi_get_error_string(ftdic));
+ msg_perr("Unable to open FTDI device: %d (%s)\n", f,
+ ftdi_get_error_string(ftdic));
return -4;
}
@@ -408,7 +417,7 @@
if (clock_5x) {
msg_pdbg("Disable divide-by-5 front stage\n");
- buf[0] = 0x8a; /* Disable divide-by-5. DIS_DIV_5 in newer libftdi */
+ buf[0] = DIS_DIV_5;
if (send_buf(ftdic, buf, 1)) {
ret = -5;
goto ftdi_err;
@@ -453,7 +462,8 @@
ftdi_err:
if ((f = ftdi_usb_close(ftdic)) < 0) {
- msg_perr("Unable to close FTDI device: %d (%s)\n", f, ftdi_get_error_string(ftdic));
+ msg_perr("Unable to close FTDI device: %d (%s)\n", f,
+ ftdi_get_error_string(ftdic));
}
return ret;
}
--
To view, visit https://review.coreboot.org/c/flashrom/+/42796
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I24c20e9b5d7e661d0180699bbd0d1447f6bf816f
Gerrit-Change-Number: 42796
Gerrit-PatchSet: 1
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-MessageType: newchange
Miklós Márton has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43900 )
Change subject: [stlinkv3_spi]Added missing line ends, and added a note about the first version of the updater which contains the necessary V3 bridge feature.
......................................................................
[stlinkv3_spi]Added missing line ends, and added a note about the
first version of the updater which contains the necessary V3 bridge
feature.
Change-Id: Ib45efa37b192489bdfe26f1f0fd1d81035a08c70
Signed-off-by: Miklós Márton <martonmiklosqdev(a)gmail.com>
---
M stlinkv3_spi.c
1 file changed, 5 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/00/43900/1
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index ae865be..c75f7db 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -253,21 +253,22 @@
enum fw_version_check_result fw_check_result;
if (stlinkv3_check_version(&fw_check_result)) {
- msg_perr("Failed to query FW version");
+ msg_perr("Failed to query FW version\n");
return -1;
}
if (fw_check_result != FW_VERSION_OK) {
msg_pinfo("Your STLink V3 has too old version of the bridge interface\n"
- "Please update the firmware with the STSW-LINK007 which can be downloaded from here:\n"
- "https://www.st.com/en/development-tools/stsw-link007.html");
+ "Please update the firmware with version 2.33.25 or newer of the STSW-LINK007\n"
+ "which can be downloaded from here:\n"
+ "https://www.st.com/en/development-tools/stsw-link007.html\n");
return -1;
}
if (stlinkv3_spi_calc_prescaler(reqested_freq_in_kHz,
&prescaler,
&SCK_freq_in_kHz)) {
- msg_perr("Failed to calculate SPI clock prescaler");
+ msg_perr("Failed to calculate SPI clock prescaler\n");
return -1;
}
msg_pinfo("SCK frequency set to %d kHz\n", SCK_freq_in_kHz);
--
To view, visit https://review.coreboot.org/c/flashrom/+/43900
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ib45efa37b192489bdfe26f1f0fd1d81035a08c70
Gerrit-Change-Number: 43900
Gerrit-PatchSet: 1
Gerrit-Owner: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-MessageType: newchange
Simon Buhrow has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/40477 )
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
Patch Set 14:
Just a try to show what effect the change has:
To do one PageProgram the Flash needs the following cmds/information (PROG=PageProgramCmd):
Flash-Cmds: JEDEC_WREN + PROG + ADDR + DATA
As flashrom communicates with the FTDI, there are additional FTDI-cmds necessary, of course.
This gives the following calls:
ft2232_spi_send_command(XX, XX, ['JEDEC_WREN'], XX)
before: -> send_buf(XX, [FTDI-CMD + 'JEDEC_WREN' + FTDI-CMD], 10)
now: -> save i and buf as they are static, no further function call; buf = [FTDI-CMD + 'JEDEC_WREN' + FTDI-CMD]
ft2232_spi_send_command(XX, XX, ['PROG', 'ADDR', 'DATA'], XX)
before: -> send_buf(XX, [FTDI-CMD + 'PROG' + 'ADDR' + 'DATA' + FTDI-CMD], 270)
now: -> send_buf(XX, [FTDI-CMD + 'JEDEC_WREN' + FTDI-CMD + FTDI-CMD + 'PROG' + 'ADDR' + 'DATA' + FTDI-CMD], 280)
=> saves one send_buf/ftdi_write_data call every page-program or erase action.
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 14
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Comment-Date: Mon, 27 Jul 2020 14:16:39 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43895 )
Change subject: ichspi.c: Take chromiums flash desc sec override msg
......................................................................
ichspi.c: Take chromiums flash desc sec override msg
Line wrapped and a little more descriptive.
Change-Id: I1043bed042f5507788ed2b417bd44d0fe3dc0aa6
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
---
M ichspi.c
1 file changed, 5 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/95/43895/1
diff --git a/ichspi.c b/ichspi.c
index 1cc1cd7..d9f13ef 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1849,9 +1849,11 @@
if (tmp2 & HSFS_FDV)
desc_valid = 1;
if (!(tmp2 & HSFS_FDOPSS) && desc_valid)
- msg_pinfo("The Flash Descriptor Override Strap-Pin is set. Restrictions implied by\n"
- "the Master Section of the flash descriptor are NOT in effect. Please note\n"
- "that Protected Range (PR) restrictions still apply.\n");
+ msg_pinfo("The Flash Descriptor Security Override "
+ "Strap-Pin is set. Restrictions implied\n"
+ "by the FRAP and FREG registers are NOT in "
+ "effect. Please note that Protected\n"
+ "Range (PR) restrictions still apply.\n");
ich_init_opcodes(ich_gen);
if (desc_valid) {
--
To view, visit https://review.coreboot.org/c/flashrom/+/43895
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I1043bed042f5507788ed2b417bd44d0fe3dc0aa6
Gerrit-Change-Number: 43895
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: newchange
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43599 )
Change subject: meson: fix compilation under uClibc-ng
......................................................................
meson: fix compilation under uClibc-ng
fileno requires _POSIX_C_SOURCE to only be defined.
nanosleep requires _POSIX_C_SOURCE to be defined to 199309L.
strndup requires _POSIX_C_SOURCE to be defined to 200809L.
Change-Id: Idb80937bb78e173eb03f2a0c0cdd8925fcd7bfa1
Signed-off-by: Rosen Penev <rosenp(a)gmail.com>
---
M meson.build
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/99/43599/1
diff --git a/meson.build b/meson.build
index 5374e87..ef7ac2c 100644
--- a/meson.build
+++ b/meson.build
@@ -25,7 +25,7 @@
cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
-add_project_arguments('-D_POSIX_C_SOURCE', language : 'c') # required for fileno
+add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
--
To view, visit https://review.coreboot.org/c/flashrom/+/43599
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Idb80937bb78e173eb03f2a0c0cdd8925fcd7bfa1
Gerrit-Change-Number: 43599
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/43598 )
Change subject: endiantest: Fix #if expression
......................................................................
endiantest: Fix #if expression
Without this, `gcc -E endiantest.c` can fail and return the incorrect
endiannes as well as exiting with non-zero. Here is the actual error
shown in the output:
endiantest.c:2:31: error: #if with no expression
#if __FLASHROM_LITTLE_ENDIAN__
I was able to reproduce this using gcc-6.3.0 and clang-4.0.1, but
newer compilers didn't have this issue.
Change-Id: Iba2febd861471ec821a494336e800c2564984332
Signed-off-by: David Hendricks <david.hendricks(a)gmail.com>
---
M endiantest.c
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/98/43598/1
diff --git a/endiantest.c b/endiantest.c
index de44ec5..9766061 100644
--- a/endiantest.c
+++ b/endiantest.c
@@ -1,5 +1,5 @@
#include "platform.h"
-#if __FLASHROM_LITTLE_ENDIAN__
+#if defined __FLASHROM_LITTLE_ENDIAN__
little
#else
big
--
To view, visit https://review.coreboot.org/c/flashrom/+/43598
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Iba2febd861471ec821a494336e800c2564984332
Gerrit-Change-Number: 43598
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
Hello Brian Nemec,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/41533
to review the following change.
Change subject: raiden_debug_spi.c: Adds support for USB SPI protocol V2
......................................................................
raiden_debug_spi.c: Adds support for USB SPI protocol V2
Adds support for the USB SPI V2 protocol and documentation of it.
The protocol version number uses the bInterfaceProtocol field in
USB to identify which device to use, this enables us to support
both V1 and V2 with the same host.
The USB SPI V2 protocol adds the ability to perform multi-packet
USB SPI transfers. This results in fewer USB messages exchanged
and faster flashing speeds.
BUG=b:139058552
BRANCH=none
TEST=Manual testing of ServoMicro and Flashrom when performing
reads, writes, and verification of the EC firmware on Nami
with a USB SPI V1 protocol device
TEST=Manual testing of ServoMicro and Flashrom when performing
reads, writes, and verification of the EC firmware on Nami
with a USB SPI V2 protocol device
TEST=Builds
Signed-off-by: Brian J. Nemec <bnemec(a)chromium.com>
Change-Id: Ie356c63b521c0cc11a4946ffac128ec7139f0bec
---
M raiden_debug_spi.c
1 file changed, 470 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/33/41533/1
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index 6cb32b3..5e07967 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -48,7 +48,10 @@
* include/usb_spi.h
* common/usb_spi.c
*
- * bInterfaceProtocol determines which protocol is used by the USB SPI device.
+ * 2 Versions of the protocol exist in deployed devices:
+ * The raiden_debug_spi.c interface used will switch between them automatically
+ * depending on the protocol version reported in the bInterfaceProtocol
+ *
*
*
* USB SPI Version 1:
@@ -117,8 +120,191 @@
* 0x20001-0x20063 Lower bits store the positive value representation
* of the libusb_error enum. See the libusb documentation:
* http://libusb.sourceforge.net/api-1.0/group__misc.html
+ *
+ *
+ *
+ * USB SPI Version 2:
+ *
+ * USB SPI version 2 adds support for larger SPI transfers and reduces the
+ * number of USB packets transferred. This improves performance when
+ * writing or reading large chunks of memory from a device. A packet ID
+ * field is used to distinguish the different packet types. Additional
+ * packets have been included to query the device for it's configuration
+ * allowing the interface to be used on platforms with different SPI
+ * limitations. It includes validation and a packet to recover from the
+ * situations where USB packets are lost.
+ *
+ *
+ * Example: USB SPI request with 128 byte write and 0 byte read.
+ *
+ * Packet #1 Host to Device:
+ * packet id = PACKET_ID_V2_COMMAND
+ * write count = 128
+ * read count = 0
+ * payload = First 58 bytes from the write buffer,
+ * start is byte 0
+ *
+ * Packet #2 Host to Device:
+ * packet id = PACKET_ID_V2_COMMAND_CONTINUE
+ * data index = 58
+ * payload = next 60 bytes from the write buffer,
+ * starting at byte 58
+ *
+ * Packet #3 Host to Device:
+ * packet id = PACKET_ID_V2_COMMAND_CONTINUE
+ * data index = 118
+ * payload = next 10 bytes from the write buffer,
+ * starting at byte 118
+ *
+ * Packet #4 Device to Host:
+ * packet id = PACKET_ID_V2_RESPONSE
+ * status code = status code from device
+ * payload = 0 bytes
+ *
+ * Command Packet (Host to Device):
+ *
+ * Start of USB SPI command, containing the number of bytes to write and
+ * read and a payload of bytes to write. If the payload is unable to fit
+ * in one USB packet, it contains the first 58 bytes.
+ *
+ * +----------------+------------------+-----------------+------------------------+
+ * | packet id : 2B | write count : 2B | read count : 2B | write payload : <= 58B |
+ * +----------------+------------------+-----------------+------------------------+
+ *
+ * packet id: 2 byte enum defined by packet_id_type
+ * Valid values packet id = PACKET_ID_V2_COMMAND
+ *
+ * write count: 2 byte, zero based count of bytes to write
+ *
+ * read count: 2 byte, zero based count of bytes to read
+ *
+ * write payload: Up to 62 bytes of data to write to SPI, the total
+ * length of all TX packets must match write count.
+ * Due to data alignment constraints, this must be an
+ * even number of bytes unless this is the final packet.
+ *
+ *
+ * Response Packet (Device to Host):
+ *
+ * Start of the USB SPI response, containing the status code and
+ * any bytes read in the payload. If read buffer can not fit in
+ * a single packet, it represents the first 60 bytes.
+ *
+ * +----------------+------------------+-----------------------+
+ * | packet id : 2B | status code : 2B | read payload : <= 60B |
+ * +----------------+------------------+-----------------------+
+ *
+ * packet id: 2 byte enum defined by packet_id_type
+ * Valid values packet id = PACKET_ID_V2_RESPONSE
+ *
+ * status code: 2 byte status code
+ * 0x0000: Success
+ * 0x0001: SPI timeout
+ * 0x0002: Busy, try again
+ * This can happen if someone else has acquired the shared memory
+ * buffer that the SPI driver uses as /dev/null
+ * 0x0003: Write count invalid. The byte limit is platform specific
+ * and is set during the configure USB SPI response.
+ * 0x0004: Read count invalid. The byte limit is platform specific
+ * and is set during the configure USB SPI response.
+ * 0x0005: The SPI bridge is disabled.
+ * 0x0006: The RX continue packet's data index is invalid. This
+ * can indicate a USB transfer failure to the device.
+ * 0x0007: The RX endpoint has received more data than write count.
+ * This can indicate a USB transfer failure to the device.
+ * 0x0008: An unexpected packet arrived that the device could not
+ * process.
+ * 0x8000: Unknown error mask
+ * The bottom 15 bits will contain the bottom 14 bits from the EC
+ * error code.
+ *
+ * read payload: Up to 62 bytes of data read from SPI, the total
+ * length of all RX packets must match read count
+ * unless an error status was returned. Due to data
+ * alignment constraints, this must be a even number
+ * of bytes unless this is the final packet.
+ *
+ *
+ * Continue Packet (Bidirectional):
+ *
+ * Continuation packet for the writes and read buffers. Both packets
+ * follow the same format, a data index counts the number of bytes
+ * previously transferred in the USB SPI transfer and a payload of bytes.
+ *
+ * +----------------+-----------------+-------------------------------+
+ * | packet id : 2B | data index : 2B | write / read payload : <= 60B |
+ * +----------------+-----------------+-------------------------------+
+ *
+ * packet id: 2 byte enum defined by packet_id_type
+ * The packet id has 2 values depending on direction:
+ * packet id = PACKET_ID_V2_COMMAND_CONTINUE indicates the
+ * packet is being transmitted from the host to the device
+ * packet id = PACKET_ID_V2_RESPONSE_CONTINUE indicates the
+ * packet is being transmitted from the device to the host.
+ *
+ * data index: The data index indicates the number of bytes in the
+ * read or write buffers have already been transmitted.
+ * It is used to validate that no packets have been dropped
+ * and that the prior packets have been correctly decoded.
+ * this value corresponds to the position in the destination
+ * destination to start copying the payload into.
+ *
+ * read and write payload:
+ * Contains up to 60 bytes of payload data to transfer to
+ * the SPI write buffer or from the SPI read buffer.
+ *
+ *
+ * Command Get Configuration Packet (Host to Device):
+ *
+ * Query the device to request it's USB SPI configuration indicating
+ * the number of bytes it can write and read.
+ *
+ * +----------------+
+ * | packet id : 2B |
+ * +----------------+
+ *
+ * packet id: 2 byte enum PACKET_ID_V2_COMMAND_GET_USB_SPI_CONFIG
+ *
+ * Response Configuration Packet (Device to Host):
+ *
+ * Response packet form the device to report the maximum write and
+ * read size supported by the device.
+ *
+ * +----------------+----------------------+---------------------+
+ * | packet id : 2B | max write count : 2B | max read count : 2B |
+ * +----------------+----------------------+---------------------+
+ *
+ * packet id: 2 byte enum PACKET_ID_V2_COMMAND_GET_USB_SPI_CONFIG
+ *
+ * max write count : 2 byte count of the maximum number of bytes
+ * the device can write to SPI in one transaction.
+ *
+ * max read count : 2 byte count of the maximum number of bytes
+ * the device can read from SPI in one transaction.
+ *
+ * Command Restart Response Packet (Host to Device):
+ *
+ * Command to restart the response transfer from the device. This enables
+ * the host to recover from a lost packet when reading the response
+ * without restarting the SPI transfer.
+ *
+ * +----------------+
+ * | packet id : 2B |
+ * +----------------+
+ *
+ * packet id: 2 byte enum PACKET_ID_V2_COMMAND_GET_USB_SPI_CONFIG
+ *
+ * send_command return codes have the following format:
+ *
+ * 0x00000: Status code success.
+ * 0x00001-0x0FFFF: Error code returned by the USB SPI device.
+ * 0x10001-0x1FFFF: USB SPI Host error codes
+ * 0x20001-0x20063 Lower bits store the positive value representation
+ * of the libusb_error enum. See the libusb documentation:
+ * http://libusb.sourceforge.net/api-1.0/group__misc.html
*/
+
#include "programmer.h"
#include "spi.h"
#include "usb_device.h"
@@ -138,6 +324,7 @@
#define GOOGLE_VID (0x18D1)
#define GOOGLE_RAIDEN_SPI_SUBCLASS (0x51)
#define GOOGLE_RAIDEN_SPI_PROTOCOL_V1 (0x01)
+#define GOOGLE_RAIDEN_SPI_PROTOCOL_V2 (0x02)
enum {
/* The host failed to transfer the data with no libusb error. */
@@ -185,6 +372,7 @@
*/
#define WRITE_RETRY_ATTEMPTS (3)
#define READ_RETRY_ATTEMPTS (3)
+#define GET_CONFIG_RETRY_ATTEMPTS (3)
#define RETRY_INTERVAL_US (100 * 1000)
/*
@@ -200,6 +388,17 @@
* All of the USB SPI packets have size equal to the max USB packet size of 64B
*/
#define PAYLOAD_SIZE_V1 (62)
+#define PACKET_HEADER_SIZE (2)
+
+#define HOST_VERSION (1)
+
+#define PAYLOAD_SIZE_V2_START (58)
+
+#define PAYLOAD_SIZE_V2_RESPONSE (60)
+
+#define PAYLOAD_SIZE_V2_CONTINUE (60)
+
+#define PAYLOAD_SIZE_V2_ERROR (60)
#define SPI_TRANSFER_V1_MAX (PAYLOAD_SIZE_V1)
@@ -224,10 +423,86 @@
usb_spi_response_v1_t response;
} __attribute__((packed)) usb_spi_packet_v1_t;
+/*
+ * Version 2 protocol specific attributes
+ */
+
+enum packet_id_type {
+
+ /* Request USB SPI configuration data from device. */
+ PACKET_ID_V2_COMMAND_GET_USB_SPI_CONFIG = 0,
+ /* USB SPI configuration data from device. */
+ PACKET_ID_V2_RESPONSE_USB_SPI_CONFIG = 1,
+
+ /* Start a USB SPI transfer and deliver first packet of data to write. */
+ PACKET_ID_V2_COMMAND = 2,
+ /* Additional packets containing write payload. */
+ PACKET_ID_V2_COMMAND_CONTINUE = 3,
+
+ /*
+ * Request the device restart the response enabling us to recover from
+ * packet loss without another SPI transfer.
+ */
+ PACKET_ID_V2_COMMAND_RESTART_RESPONSE = 4,
+
+ /* First packet of USB SPI response with status code and read payload. */
+ PACKET_ID_V2_RESPONSE = 5,
+ /* Additional packets containing read payload. */
+ PACKET_ID_V2_RESPONSE_CONTINUE = 6,
+};
+
+typedef struct {
+ int16_t packet_id;
+} __attribute__((packed)) usb_spi_command_get_configuration_v2_t;
+
+typedef struct {
+ int16_t packet_id;
+ uint16_t max_write_count;
+ uint16_t max_read_count;
+} __attribute__((packed)) usb_spi_response_configuration_v2_t;
+
+typedef struct {
+ int16_t packet_id;
+ int16_t write_count;
+ /* -1 Indicates readback all on halfduplex compliant devices. */
+ int16_t read_count;
+ uint8_t data[PAYLOAD_SIZE_V2_START];
+} __attribute__((packed)) usb_spi_command_v2_t;
+
+typedef struct {
+ int16_t packet_id;
+ uint16_t status_code;
+ uint8_t data[PAYLOAD_SIZE_V2_RESPONSE];
+} __attribute__((packed)) usb_spi_response_v2_t;
+
+typedef struct {
+ int16_t packet_id;
+ uint16_t data_index;
+ uint8_t data[PAYLOAD_SIZE_V2_CONTINUE];
+} __attribute__((packed)) usb_spi_continue_v2_t;
+
+typedef struct {
+ int16_t packet_id;
+} __attribute__((packed)) usb_spi_command_restart_response_v2_t;
+
+typedef struct {
+ union {
+ int16_t packet_id;
+ usb_spi_command_get_configuration_v2_t command_get_config;
+ usb_spi_response_configuration_v2_t response_config;
+ usb_spi_command_restart_response_v2_t restart_response;
+ usb_spi_command_v2_t command;
+ usb_spi_response_v2_t response;
+ usb_spi_continue_v2_t command_continue;
+ usb_spi_continue_v2_t response_continue;
+ };
+} __attribute__((packed)) usb_spi_packet_v2_t;
+
typedef struct {
union {
uint8_t bytes[MAX_USB_PACKET_SIZE];
usb_spi_packet_v1_t packet_v1;
+ usb_spi_packet_v2_t packet_v2;
};
/*
* By storing the number of bytes in the header and knowing that the
@@ -427,6 +702,177 @@
return status;
}
+/*
+ * Version 2 Protocol
+ */
+
+int get_spi_size_v2(struct raiden_debug_spi_data *ctx_data)
+{
+ int status;
+ usb_spi_packet_ctx_t response_config;
+
+ usb_spi_packet_ctx_t command_get_config = {
+ .header_size = sizeof(usb_spi_command_get_configuration_v2_t),
+ .packet_size = sizeof(usb_spi_command_get_configuration_v2_t),
+ .packet_v2.packet_id = PACKET_ID_V2_COMMAND_GET_USB_SPI_CONFIG
+ };
+
+ for (int config_attempt = 0; config_attempt < GET_CONFIG_RETRY_ATTEMPTS;
+ config_attempt++) {
+
+ status = transmit_packet(ctx_data, &command_get_config);
+ if (status) {
+ msg_perr("Raiden: Failed to transmit get config\n"
+ " config attempt = %d\n"
+ " status = %d\n",
+ config_attempt + 1, status);
+ programmer_delay(RETRY_INTERVAL_US);
+ continue;
+ }
+
+ status = receive_packet(ctx_data, &response_config);
+ if (status) {
+ msg_perr("Raiden: Failed to receive packet\n"
+ " config attempt = %d\n"
+ " status = %d\n",
+ config_attempt + 1, status);
+ programmer_delay(RETRY_INTERVAL_US);
+ continue;
+ }
+
+ /*
+ * Perform validation on the packet received to verify it is a valid
+ * configuration. If it is, we are ready to perform transfers.
+ */
+ if ((response_config.packet_v2.packet_id ==
+ PACKET_ID_V2_RESPONSE_USB_SPI_CONFIG) ||
+ (response_config.packet_size ==
+ sizeof(usb_spi_response_configuration_v2_t))) {
+
+ /* Set the parameters from the configuration. */
+ ctx_data->max_spi_write_count =
+ response_config.packet_v2.response_config.max_write_count;
+ ctx_data->max_spi_read_count =
+ response_config.packet_v2.response_config.max_read_count;
+ return status;
+ }
+
+ msg_perr("Raiden: Packet is not a valid config\n"
+ " config attempt = %d\n"
+ " packet id = %d\n"
+ " packet size = %d\n",
+ config_attempt + 1,
+ response_config.packet_v2.packet_id,
+ response_config.packet_size);
+ programmer_delay(RETRY_INTERVAL_US);
+ }
+ return USB_SPI_HOST_INIT_FAILURE;
+}
+
+int restart_response_v2(const struct raiden_debug_spi_data *ctx_data)
+{
+ int status;
+
+ usb_spi_packet_ctx_t restart_response = {
+ .header_size = sizeof(usb_spi_command_restart_response_v2_t),
+ .packet_size = sizeof(usb_spi_command_restart_response_v2_t),
+ .packet_v2.packet_id = PACKET_ID_V2_COMMAND_RESTART_RESPONSE
+ };
+
+ status = transmit_packet(ctx_data, &restart_response);
+ return status;
+}
+
+
+int write_command_v2(const struct raiden_debug_spi_data * ctx_data,
+ usb_spi_transmit_ctx_t* write,
+ usb_spi_receive_ctx_t* read)
+{
+ int status;
+ usb_spi_packet_ctx_t continue_packet;
+
+ usb_spi_packet_ctx_t start_usb_spi_packet = {
+ .header_size = offsetof(usb_spi_command_v2_t, data),
+ .packet_v2.command.packet_id = PACKET_ID_V2_COMMAND,
+ .packet_v2.command.write_count = write->transmit_size,
+ .packet_v2.command.read_count = read->receive_size
+ };
+
+ fill_usb_packet(&start_usb_spi_packet, write);
+ status = transmit_packet(ctx_data, &start_usb_spi_packet);
+ if (status) {
+ return status;
+ }
+
+ while (write->transmit_index < write->transmit_size) {
+ /* Transmit any continue packets. */
+ continue_packet.header_size = offsetof(usb_spi_continue_v2_t, data);
+ continue_packet.packet_v2.command_continue.packet_id =
+ PACKET_ID_V2_COMMAND_CONTINUE;
+ continue_packet.packet_v2.command_continue.data_index =
+ write->transmit_index;
+
+ fill_usb_packet(&continue_packet, write);
+
+ status = transmit_packet(ctx_data, &continue_packet);
+ if (status) {
+ return status;
+ }
+ }
+ return status;
+}
+
+int read_response_v2(const struct raiden_debug_spi_data * ctx_data,
+ usb_spi_transmit_ctx_t* write,
+ usb_spi_receive_ctx_t* read)
+{
+ int status = -1;
+ usb_spi_packet_ctx_t response;
+
+ /* Receive the payload to the servo micro. */
+ while (read->receive_index < read->receive_size) {
+
+ status = receive_packet(ctx_data, &response);
+ if (status) {
+ /* Return the transfer error. */
+ return status;
+ }
+ if (response.packet_v2.packet_id == PACKET_ID_V2_RESPONSE) {
+ /*
+ * The host should only see this packet if an error occurs
+ * on the device or if it's the first response packet.
+ */
+ if (response.packet_v2.response.status_code) {
+ return response.packet_v2.response.status_code;
+ }
+ if (read->receive_index) {
+ msg_perr("Raiden: Unexpected packet id = %d",
+ response.packet_v2.response.packet_id);
+ return USB_SPI_HOST_RX_UNEXPECTED_PACKET;
+ }
+ response.header_size = offsetof(usb_spi_response_v2_t, data);
+ } if (response.packet_v2.packet_id ==
+ PACKET_ID_V2_RESPONSE_CONTINUE) {
+
+ /* We validate that no packets were missed. */
+ if (read->receive_index !=
+ response.packet_v2.response_continue.data_index) {
+ return USB_SPI_HOST_RX_BAD_DATA_INDEX;
+ }
+ response.header_size = offsetof(usb_spi_continue_v2_t, data);
+ } else {
+ msg_perr("Raiden: Unexpected packet id = %d",
+ response.packet_v2.packet_id);
+ return USB_SPI_HOST_RX_UNEXPECTED_PACKET;
+ }
+ status = read_usb_packet(read, &response);
+ if (status) {
+ return status;
+ }
+ }
+ return status;
+}
+
static int send_command(const struct flashctx *flash,
unsigned int write_count,
unsigned int read_count,
@@ -464,6 +910,8 @@
write_ctx.transmit_index = 0;
if (ctx_data->protocol_version == GOOGLE_RAIDEN_SPI_PROTOCOL_V1) {
status = write_command_v1(ctx_data, &write_ctx, &read_ctx);
+ } else {
+ status = write_command_v2(ctx_data, &write_ctx, &read_ctx);
}
if (status) {
@@ -490,6 +938,8 @@
read_ctx.receive_index = 0;
if (ctx_data->protocol_version == GOOGLE_RAIDEN_SPI_PROTOCOL_V1) {
status = read_response_v1(ctx_data, &write_ctx, &read_ctx);
+ } else {
+ status = read_response_v2(ctx_data, &write_ctx, &read_ctx);
}
if (status == 0) {
@@ -513,6 +963,15 @@
/* Reattempting will not result in a recovery. */
return status;
}
+ /*
+ * Protocol version 2 includes multi-packet messages, we can
+ * restart only the response operation without performing SPI
+ * transfer.
+ */
+ if (ctx_data->protocol_version ==
+ GOOGLE_RAIDEN_SPI_PROTOCOL_V2) {
+ restart_response_v2(ctx_data);
+ }
programmer_delay(RETRY_INTERVAL_US);
} else {
/* We were successful at performing the SPI transfer. */
@@ -579,6 +1038,7 @@
static int configure_protocol(struct spi_master *ctx_spi)
{
+ int status = 0;
struct raiden_debug_spi_data *ctx_data =
(struct raiden_debug_spi_data *)ctx_spi->data;
@@ -593,6 +1053,15 @@
ctx_data->max_spi_write_count= SPI_TRANSFER_V1_MAX;
ctx_data->max_spi_read_count = SPI_TRANSFER_V1_MAX;
break;
+ case GOOGLE_RAIDEN_SPI_PROTOCOL_V2:
+ /*
+ * Protocol V2 requires the host to query the device for
+ * it's maximum read and write sizes
+ */
+ status = get_spi_size_v2(ctx_data);
+ if (status) {
+ return status;
+ }
default:
msg_pdbg("Raiden: Unknown USB SPI protocol version = %d",
ctx_data->protocol_version);
@@ -692,7 +1161,6 @@
usb_match_value_default(&match.vid, GOOGLE_VID);
usb_match_value_default(&match.class, LIBUSB_CLASS_VENDOR_SPEC);
usb_match_value_default(&match.subclass, GOOGLE_RAIDEN_SPI_SUBCLASS);
- usb_match_value_default(&match.protocol, GOOGLE_RAIDEN_SPI_PROTOCOL_V1);
ret = LIBUSB(libusb_init(NULL));
if (ret != 0) {
--
To view, visit https://review.coreboot.org/c/flashrom/+/41533
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie356c63b521c0cc11a4946ffac128ec7139f0bec
Gerrit-Change-Number: 41533
Gerrit-PatchSet: 1
Gerrit-Owner: Brian Nemec <bnemec(a)google.com>
Gerrit-Reviewer: Brian Nemec <bnemec(a)chromium.org>
Gerrit-MessageType: newchange
Hello Brian Nemec,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/41532
to review the following change.
Change subject: raiden_debug_spi.c: Refactor to support multiple protocols
......................................................................
raiden_debug_spi.c: Refactor to support multiple protocols
Refactoring of the USB SPI protocol to support multiple protocols.
The changes include:
* Setting of USB SPI limits based on the device's USB protocol
* Creation of context states to keep track of bytes written to
and read from the device and individual USB packets.
* Creation of helper functions for handling transfer of data
between the USB packets and the data buffers.
* Removal of magic numbers on the USB return codes. Some renaming
of to make the protocol version clear.
BUG=b:139058552
BRANCH=none
TEST=Manual testing of ServoMicro and Flashrom when performing
reads, writes, and verification of the EC firmware on Nami.
TEST=Builds
Signed-off-by: Brian J. Nemec <bnemec(a)chromium.com>
Change-Id: Id404af14e55fa0884e29f28880206aaad4deba66
---
M raiden_debug_spi.c
1 file changed, 370 insertions(+), 166 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/32/41532/1
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index ac74c0b..b08d9e0 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -42,28 +42,37 @@
*
* https://chromium.googlesource.com/chromiumos/platform/ec
*
- * The protocol for the USB-SPI bridge is documented in the following file in
- * that respository:
+ * The protocol for the USB-SPI bridge is implemented in the following files
+ * in that repository:
*
- * chip/stm32/usb_spi.c
+ * include/usb_spi.h
+ * common/usb_spi.c
*
- * Version 1:
- * SPI transactions of up to 62B in each direction with every command having
- * a response. The initial packet from host contains a 2B header indicating
- * write and read counts with an optional payload length equal to the write
- * count. The device will respond with a message that reports the 2B status
- * code and an optional payload response length equal to read count.
+ * bInterfaceProtocol determines which protocol is used by the USB SPI device.
*
- * Message Format:
*
- * Command Packet:
+ * USB SPI Version 1:
+ *
+ * SPI transactions of up to 62B in each direction with every command having
+ * a response. The initial packet from host contains a 2B header indicating
+ * write and read counts with an optional payload length equal to the write
+ * count. The device will respond with a message that reports the 2B status
+ * code and an optional payload response length equal to read count.
+ *
+ *
+ * Command First Packet (Host to Device):
+ *
+ * USB SPI command, containing the number of bytes to write and read
+ * and a payload of bytes to write.
+ *
* +------------------+-----------------+------------------------+
* | write count : 1B | read count : 1B | write payload : <= 62B |
* +------------------+-----------------+------------------------+
*
* write count: 1 byte, zero based count of bytes to write
*
- * read count: 1 byte, zero based count of bytes to read
+ * read count: 1 byte, zero based count of bytes to read. Half duplex
+ * mode is enabled with '-1'
*
* write payload: Up to 62 bytes of data to write to SPI, the total
* length of all TX packets must match write count.
@@ -71,6 +80,10 @@
* even number of bytes unless this is the final packet.
*
* Response Packet:
+ *
+ * USB SPI response, containing the status code and any bytes of the
+ * read payload.
+ *
* +-------------+-----------------------+
* | status : 2B | read payload : <= 62B |
* +-------------+-----------------------+
@@ -81,8 +94,8 @@
* 0x0002: Busy, try again
* This can happen if someone else has acquired the shared memory
* buffer that the SPI driver uses as /dev/null
- * 0x0003: Write count invalid (V1 > 62B)
- * 0x0004: Read count invalid (V1 > 62B)
+ * 0x0003: Write count invalid (over 62 bytes)
+ * 0x0004: Read count invalid (over 62 bytes)
* 0x0005: The SPI bridge is disabled.
* 0x8000: Unknown error mask
* The bottom 15 bits will contain the bottom 15 bits from the EC
@@ -115,24 +128,46 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stddef.h>
/* FIXME: Add some programmer IDs here */
const struct dev_entry devs_raiden[] = {
{0},
};
-#define GOOGLE_VID (0x18D1)
-#define GOOGLE_RAIDEN_SPI_SUBCLASS (0x51)
-#define GOOGLE_RAIDEN_SPI_PROTOCOL (0x01)
+#define GOOGLE_VID (0x18D1)
+#define GOOGLE_RAIDEN_SPI_SUBCLASS (0x51)
+#define GOOGLE_RAIDEN_SPI_PROTOCOL_V1 (0x01)
+
+enum {
+ /* The host failed to transfer the data with no libusb error. */
+ USB_SPI_HOST_TX_BAD_TRANSFER = 0x10001,
+ /* We did not receive the expected USB packet. */
+ USB_SPI_HOST_RX_UNEXPECTED_PACKET = 0x18002,
+ /* We received a continue packet with an invalid data index.*/
+ USB_SPI_HOST_RX_BAD_DATA_INDEX = 0x18003,
+ /* We too much data. */
+ USB_SPI_HOST_RX_DATA_OVERFLOW = 0x18004,
+ /* We too little data. */
+ USB_SPI_HOST_RX_READ_FAILURE = 0x18005,
+ /* We were unable to configure the device. */
+ USB_SPI_HOST_INIT_FAILURE = 0x18006,
+};
enum usb_spi_error {
- USB_SPI_SUCCESS = 0x0000,
- USB_SPI_TIMEOUT = 0x0001,
- USB_SPI_BUSY = 0x0002,
- USB_SPI_WRITE_COUNT_INVALID = 0x0003,
- USB_SPI_READ_COUNT_INVALID = 0x0004,
- USB_SPI_DISABLED = 0x0005,
- USB_SPI_UNKNOWN_ERROR = 0x8000,
+ USB_SPI_SUCCESS = 0x0000,
+ USB_SPI_TIMEOUT = 0x0001,
+ USB_SPI_BUSY = 0x0002,
+ USB_SPI_WRITE_COUNT_INVALID = 0x0003,
+ USB_SPI_READ_COUNT_INVALID = 0x0004,
+ USB_SPI_DISABLED = 0x0005,
+ /* The RX continue packet's data index is invalid. */
+ USB_SPI_RX_BAD_DATA_INDEX = 0x0006,
+ /* The RX endpoint has received more data than write count. */
+ USB_SPI_RX_DATA_OVERFLOW = 0x0007,
+ /* An unexpected packet arrived on the device. */
+ USB_SPI_RX_UNEXPECTED_PACKET = 0x0008,
+ USB_SPI_UNKNOWN_ERROR = 0x8000,
};
enum raiden_debug_spi_request {
@@ -142,42 +177,95 @@
RAIDEN_DEBUG_SPI_REQ_ENABLE_EC = 0x0003,
};
-#define PACKET_HEADER_SIZE (2)
-#define MAX_PACKET_SIZE (64)
-#define PAYLOAD_SIZE (MAX_PACKET_SIZE - PACKET_HEADER_SIZE)
-
/*
* Servo Micro has an error where it is capable of acknowledging USB packets
* without loading it into the USB endpoint buffers or triggering interrupts.
* See crbug.com/952494. Retry mechanisms have been implemented to recover
* from these rare failures allowing the process to continue.
*/
-#define WRITE_RETY_ATTEMPTS (3)
-#define READ_RETY_ATTEMPTS (3)
-#define RETY_INTERVAL_US (100 * 1000)
+#define WRITE_RETRY_ATTEMPTS (3)
+#define READ_RETRY_ATTEMPTS (3)
+#define RETRY_INTERVAL_US (100 * 1000)
/*
* This timeout is so large because the Raiden SPI timeout is 800ms.
*/
#define TRANSFER_TIMEOUT_MS (200 + 800)
-struct raiden_debug_spi_data {
- struct usb_device *dev;
- uint8_t in_ep;
- uint8_t out_ep;
-};
+/*
+ * USB permits a maximum bulk transfer of 64B.
+ */
+#define MAX_USB_PACKET_SIZE (64)
+/*
+ * All of the USB SPI packets have size equal to the max USB packet size of 64B
+ */
+#define PAYLOAD_SIZE_V1 (62)
+
+#define SPI_TRANSFER_V1_MAX (PAYLOAD_SIZE_V1)
+
+/*
+ * Version 1 protocol specific attributes
+ */
typedef struct {
int8_t write_count;
/* -1 Indicates readback all on halfduplex compliant devices. */
int8_t read_count;
- uint8_t data[PAYLOAD_SIZE];
-} __attribute__((packed)) usb_spi_command_t;
+ uint8_t data[PAYLOAD_SIZE_V1];
+} __attribute__((packed)) usb_spi_command_v1_t;
typedef struct {
uint16_t status_code;
- uint8_t data[PAYLOAD_SIZE];
-} __attribute__((packed)) usb_spi_response_t;
+ uint8_t data[PAYLOAD_SIZE_V1];
+} __attribute__((packed)) usb_spi_response_v1_t;
+
+typedef union {
+ usb_spi_command_v1_t command;
+ usb_spi_response_v1_t response;
+} __attribute__((packed)) usb_spi_packet_v1_t;
+
+typedef struct {
+ union {
+ uint8_t bytes[MAX_USB_PACKET_SIZE];
+ usb_spi_packet_v1_t packet_v1;
+ };
+ /*
+ * By storing the number of bytes in the header and knowing that the
+ * USB data packets are all 64B long, we are able to use the header
+ * size to store the offset of the buffer and it's size without
+ * duplicating variables that can go out of sync.
+ */
+ int header_size;
+ /* Number of bytes in the packet */
+ int packet_size;
+} usb_spi_packet_ctx_t;
+
+typedef struct {
+ /* Buffer we are reading data from. */
+ const uint8_t *buffer;
+ /* Total size of the transmit transfer. */
+ int transmit_size;
+ /* Number of bytes transmitted. */
+ int transmit_index;
+} usb_spi_transmit_ctx_t;
+
+typedef struct {
+ /* Buffer we are writing data into. */
+ uint8_t *buffer;
+ /* Total size of the receive transfer. */
+ int receive_size;
+ /* Number of bytes received. */
+ int receive_index;
+} usb_spi_receive_ctx_t;
+
+struct raiden_debug_spi_data {
+ struct usb_device *dev;
+ uint8_t in_ep;
+ uint8_t out_ep;
+ uint8_t protocol_version;
+ uint16_t max_spi_write_count;
+ uint16_t max_spi_read_count;
+};
/*
* This function will return true when an error code can potentially recover
@@ -212,167 +300,239 @@
return (const struct raiden_debug_spi_data *)flash->mst->spi.data;
}
-static int write_command(const struct flashctx *flash,
- unsigned int write_count,
- unsigned int read_count,
- const unsigned char *write_buffer,
- unsigned char *read_buffer)
-{
+/*
+ * Fill the data section in the USB packets.
+ */
+static int fill_usb_packet(usb_spi_packet_ctx_t* dst,
+ usb_spi_transmit_ctx_t* src) {
+ int transfer_size = src->transmit_size - src->transmit_index;
+ int max_buffer_size = MAX_USB_PACKET_SIZE - dst->header_size;
+ uint8_t *packet_buffer = dst->bytes + dst->header_size;
- int transferred;
- int ret;
- usb_spi_command_t command_packet;
- const struct raiden_debug_spi_data * ctx_data = get_raiden_data_from_context(flash);
-
- if (write_count > PAYLOAD_SIZE) {
- msg_perr("Raiden: Invalid write_count of %d\n", write_count);
- return SPI_INVALID_LENGTH;
+ if (transfer_size > max_buffer_size) {
+ transfer_size = max_buffer_size;
}
+ memcpy(packet_buffer, src->buffer + src->transmit_index, transfer_size);
- if (read_count > PAYLOAD_SIZE) {
- msg_perr("Raiden: Invalid read_count of %d\n", read_count);
- return SPI_INVALID_LENGTH;
- }
-
- command_packet.write_count = write_count;
- command_packet.read_count = read_count;
-
- memcpy(command_packet.data, write_buffer, write_count);
-
- ret = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
- ctx_data->out_ep,
- (void*)&command_packet,
- write_count + PACKET_HEADER_SIZE,
- &transferred,
- TRANSFER_TIMEOUT_MS));
- if (ret != 0) {
- msg_perr("Raiden: OUT transfer failed\n"
- " write_count = %d\n"
- " read_count = %d\n",
- write_count, read_count);
- return ret;
- }
-
- if ((unsigned) transferred != write_count + PACKET_HEADER_SIZE) {
- msg_perr("Raiden: Write failure (wrote %d, expected %d)\n",
- transferred, write_count + PACKET_HEADER_SIZE);
- return 0x10001;
- }
-
+ dst->packet_size = dst->header_size + transfer_size;
+ src->transmit_index += transfer_size;
return 0;
}
-static int read_response(const struct flashctx *flash,
- unsigned int write_count,
- unsigned int read_count,
- const unsigned char *write_buffer,
- unsigned char *read_buffer)
-{
+static int read_usb_packet(usb_spi_receive_ctx_t* dst,
+ const usb_spi_packet_ctx_t* src) {
+ int max_read_length = dst->receive_size - dst->receive_index;
+ int bytes_in_buffer = src->packet_size - src->header_size;
+ const uint8_t *packet_buffer = src->bytes + src->header_size;
+
+ if (bytes_in_buffer > max_read_length) {
+ /*
+ * An error occurred, we should not receive more data than
+ * the buffer can support.
+ */
+ msg_perr("Raiden: Receive packet overflowed\n"
+ " bytes_in_buffer = %d\n"
+ " max_read_length = %d\n"
+ " receive_index = %d\n"
+ " receive_size = %d\n",
+ bytes_in_buffer, max_read_length,
+ dst->receive_size, dst->receive_index);
+ return USB_SPI_HOST_RX_DATA_OVERFLOW;
+ }
+ memcpy(dst->buffer + dst->receive_index, packet_buffer, bytes_in_buffer);
+
+ dst->receive_index += bytes_in_buffer;
+ return 0;
+}
+
+static int transmit_packet(const struct raiden_debug_spi_data * ctx_data,
+ usb_spi_packet_ctx_t* packet) {
int transferred;
- int ret;
- usb_spi_response_t response_packet;
- const struct raiden_debug_spi_data * ctx_data = get_raiden_data_from_context(flash);
+ int status = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
+ ctx_data->out_ep,
+ packet->bytes,
+ packet->packet_size,
+ &transferred,
+ TRANSFER_TIMEOUT_MS));
+ if (status || transferred != packet->packet_size) {
+ msg_perr("Raiden: OUT transfer failed\n"
+ " transferred = %d\n"
+ " packet_size = %d\n"
+ " status = %d\n",
+ transferred, packet->packet_size, status);
+ if (status == 0) {
+ return USB_SPI_HOST_TX_BAD_TRANSFER;
+ }
+ }
+ return status;
+}
- ret = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
- ctx_data->in_ep,
- (void*)&response_packet,
- read_count + PACKET_HEADER_SIZE,
- &transferred,
- TRANSFER_TIMEOUT_MS));
- if (ret != 0) {
+static int receive_packet(const struct raiden_debug_spi_data * ctx_data,
+ usb_spi_packet_ctx_t* packet) {
+ int transferred;
+ int status = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
+ ctx_data->in_ep,
+ packet->bytes,
+ MAX_USB_PACKET_SIZE,
+ &transferred,
+ TRANSFER_TIMEOUT_MS));
+ packet->packet_size = transferred;
+ if (status) {
msg_perr("Raiden: IN transfer failed\n"
- " write_count = %d\n"
- " read_count = %d\n",
- write_count, read_count);
- return ret;
+ " transferred = %d\n"
+ " status = %d\n",
+ transferred, status);
}
+ return status;
+}
- if ((unsigned) transferred != read_count + PACKET_HEADER_SIZE) {
- msg_perr("Raiden: Read failure (read %d, expected %d)\n",
- transferred, read_count + PACKET_HEADER_SIZE);
- return 0x10002;
+/*
+ * Version 1 Protocol
+ */
+
+static int write_command_v1(const struct raiden_debug_spi_data * ctx_data,
+ usb_spi_transmit_ctx_t* write,
+ usb_spi_receive_ctx_t* read)
+{
+ int status;
+ usb_spi_packet_ctx_t command = {
+ .header_size = offsetof(usb_spi_command_v1_t, data),
+ .packet_v1.command.write_count = write->transmit_size,
+ .packet_v1.command.read_count = read->receive_size
+ };
+
+ fill_usb_packet(&command, write);
+ status = transmit_packet(ctx_data, &command);
+ return status;
+}
+
+static int read_response_v1(const struct raiden_debug_spi_data * ctx_data,
+ usb_spi_transmit_ctx_t* write,
+ usb_spi_receive_ctx_t* read)
+{
+ int status;
+ usb_spi_packet_ctx_t response;
+
+ status = receive_packet(ctx_data, &response);
+ if (status) {
+ /* Return the transfer error since the status_code is unreliable */
+ return status;
}
+ if (response.packet_v1.response.status_code) {
+ return response.packet_v1.response.status_code;
+ }
+ response.header_size = offsetof(usb_spi_response_v1_t, data);
- memcpy(read_buffer, response_packet.data, read_count);
-
- return response_packet.status_code;
+ status = read_usb_packet(read, &response);
+ return status;
}
static int send_command(const struct flashctx *flash,
- unsigned int write_count,
- unsigned int read_count,
- const unsigned char *write_buffer,
- unsigned char *read_buffer)
+ unsigned int write_count,
+ unsigned int read_count,
+ const unsigned char *write_buffer,
+ unsigned char *read_buffer)
{
+ const struct raiden_debug_spi_data * ctx_data =
+ get_raiden_data_from_context(flash);
int status = -1;
+ usb_spi_transmit_ctx_t write_ctx = {
+ .buffer = write_buffer,
+ .transmit_size = write_count
+ };
+ usb_spi_receive_ctx_t read_ctx = {
+ .buffer = read_buffer,
+ .receive_size = read_count
+ };
- for (int write_attempt = 0; write_attempt < WRITE_RETY_ATTEMPTS;
+ if (write_count > ctx_data->max_spi_write_count) {
+ msg_perr("Raiden: Invalid write count of %d, Max %d, \n",
+ write_count, ctx_data->max_spi_write_count);
+ return SPI_INVALID_LENGTH;
+ }
+
+ if (read_count > ctx_data->max_spi_read_count) {
+ msg_perr("Raiden: Invalid read count of %d, Max %d\n",
+ read_count, ctx_data->max_spi_write_count);
+ return SPI_INVALID_LENGTH;
+ }
+
+ for (int write_attempt = 0; write_attempt < WRITE_RETRY_ATTEMPTS;
write_attempt++) {
- status = write_command(flash, write_count, read_count,
- write_buffer, read_buffer);
+ /* Make sure we always reset the write context. */
+ write_ctx.transmit_index = 0;
+ if (ctx_data->protocol_version == GOOGLE_RAIDEN_SPI_PROTOCOL_V1) {
+ status = write_command_v1(ctx_data, &write_ctx, &read_ctx);
+ }
if (status) {
/* Write operation failed. */
msg_perr("Raiden: Write command failed\n"
- "Write attempt = %d\n"
- "status = %d\n",
- write_attempt + 1, status);
+ " write count = %d\n"
+ " read count = %d\n"
+ " transmitted bytes = %d\n"
+ " write attempt = %d\n"
+ " status = %d\n",
+ write_count, read_count, write_ctx.transmit_index,
+ write_attempt + 1, status);
if (!retry_recovery(status)) {
/* Reattempting will not result in a recovery. */
return status;
}
- programmer_delay(RETY_INTERVAL_US);
+ programmer_delay(RETRY_INTERVAL_US);
continue;
}
- for (int read_attempt = 0; read_attempt < READ_RETY_ATTEMPTS; read_attempt++) {
+ for (int read_attempt = 0; read_attempt < READ_RETRY_ATTEMPTS;
+ read_attempt++) {
- status = read_response(flash, write_count, read_count,
- write_buffer, read_buffer);
+ /* Make sure we always reset the read context. */
+ read_ctx.receive_index = 0;
+ if (ctx_data->protocol_version == GOOGLE_RAIDEN_SPI_PROTOCOL_V1) {
+ status = read_response_v1(ctx_data, &write_ctx, &read_ctx);
+ }
- if (status != 0) {
+ if (status == 0) {
+ if (read_ctx.receive_size != read_ctx.receive_index) {
+ status = USB_SPI_HOST_RX_READ_FAILURE;
+ }
+ }
+
+ if (status) {
/* Read operation failed. */
msg_perr("Raiden: Read response failed\n"
- "Write attempt = %d\n"
- "Read attempt = %d\n"
- "status = %d\n",
- write_attempt + 1, read_attempt + 1, status);
+ " write count = %d\n"
+ " read count = %d\n"
+ " received bytes = %d\n"
+ " write attempt = %d\n"
+ " read attempt = %d\n"
+ " status = %d\n",
+ write_count, read_count, read_ctx.receive_index,
+ write_attempt + 1, read_attempt + 1, status);
if (!retry_recovery(status)) {
/* Reattempting will not result in a recovery. */
return status;
}
- programmer_delay(RETY_INTERVAL_US);
+ programmer_delay(RETRY_INTERVAL_US);
} else {
/* We were successful at performing the SPI transfer. */
return status;
}
}
}
+
return status;
}
-/*
- * Unfortunately there doesn't seem to be a way to specify the maximum number
- * of bytes that your SPI device can read/write, these values are the maximum
- * data chunk size that flashrom will package up with an additional five bytes
- * of command for the flash device, resulting in a 62 byte packet, that we then
- * add two bytes to in either direction, making our way up to the 64 byte
- * maximum USB packet size for the device.
- *
- * The largest command that flashrom generates is the byte program command, so
- * we use that command header maximum size here.
- */
-#define MAX_DATA_SIZE (PAYLOAD_SIZE - JEDEC_BYTE_PROGRAM_OUTSIZE)
-
static struct spi_master spi_master_raiden_debug = {
- .features = SPI_MASTER_4BA,
- .max_data_read = MAX_DATA_SIZE,
- .max_data_write = MAX_DATA_SIZE,
- .command = send_command,
- .multicommand = default_spi_send_multicommand,
- .read = default_spi_read,
- .write_256 = default_spi_write_256,
- .write_aai = default_spi_write_aai,
+ .features = SPI_MASTER_4BA,
+ .max_data_read = 0,
+ .max_data_write = 0,
+ .command = send_command,
+ .multicommand = default_spi_send_multicommand,
+ .read = default_spi_read,
+ .write_256 = default_spi_write_256,
+ .write_aai = default_spi_write_aai,
};
static int match_endpoint(struct libusb_endpoint_descriptor const *descriptor,
@@ -405,9 +565,9 @@
if (in_count != 1 || out_count != 1) {
msg_perr("Raiden: Failed to find one IN and one OUT endpoint\n"
- " found %d IN and %d OUT endpoints\n",
- in_count,
- out_count);
+ " found %d IN and %d OUT endpoints\n",
+ in_count,
+ out_count);
return 1;
}
@@ -417,22 +577,60 @@
return 0;
}
+static int configure_protocol(struct spi_master *ctx_spi)
+{
+ struct raiden_debug_spi_data *ctx_data =
+ (struct raiden_debug_spi_data *)ctx_spi->data;
+
+ ctx_data->protocol_version =
+ ctx_data->dev->interface_descriptor->bInterfaceProtocol;
+ switch(ctx_data->protocol_version) {
+ case GOOGLE_RAIDEN_SPI_PROTOCOL_V1:
+ /*
+ * Protocol V1 is supported by adjusting the max data
+ * read and write sizes which results in no continue packets.
+ */
+ ctx_data->max_spi_write_count= SPI_TRANSFER_V1_MAX;
+ ctx_data->max_spi_read_count = SPI_TRANSFER_V1_MAX;
+ break;
+ default:
+ msg_pdbg("Raiden: Unknown USB SPI protocol version = %d",
+ ctx_data->protocol_version);
+ return USB_SPI_HOST_INIT_FAILURE;
+ }
+ /*
+ * Unfortunately there doesn't seem to be a way to specify the maximum number
+ * of bytes that your SPI device can read/write, these values are the maximum
+ * data chunk size that flashrom will package up with an additional five bytes
+ * of command for the flash device.
+ *
+ * The largest command that flashrom generates is the byte program command, so
+ * we use that command header maximum size here.
+ */
+
+ ctx_spi->max_data_write = ctx_data->max_spi_write_count -
+ JEDEC_BYTE_PROGRAM_OUTSIZE;
+ ctx_spi->max_data_read = ctx_data->max_spi_read_count -
+ JEDEC_BYTE_PROGRAM_OUTSIZE;
+ return 0;
+}
+
static int raiden_debug_spi_shutdown(void * data)
{
- struct raiden_debug_spi_data * ctx_data =
+ struct raiden_debug_spi_data * ctx_data =
(struct raiden_debug_spi_data *)data;
int ret = LIBUSB(libusb_control_transfer(
- ctx_data->dev->handle,
- LIBUSB_ENDPOINT_OUT |
- LIBUSB_REQUEST_TYPE_VENDOR |
- LIBUSB_RECIPIENT_INTERFACE,
- RAIDEN_DEBUG_SPI_REQ_DISABLE,
- 0,
- ctx_data->dev->interface_descriptor->bInterfaceNumber,
- NULL,
- 0,
- TRANSFER_TIMEOUT_MS));
+ ctx_data->dev->handle,
+ LIBUSB_ENDPOINT_OUT |
+ LIBUSB_REQUEST_TYPE_VENDOR |
+ LIBUSB_RECIPIENT_INTERFACE,
+ RAIDEN_DEBUG_SPI_REQ_DISABLE,
+ 0,
+ ctx_data->dev->interface_descriptor->bInterfaceNumber,
+ NULL,
+ 0,
+ TRANSFER_TIMEOUT_MS));
if (ret != 0) {
msg_perr("Raiden: Failed to disable SPI bridge\n");
return ret;
@@ -610,7 +808,13 @@
data->in_ep = in_endpoint;
data->out_ep = out_endpoint;
+ /* The host side needs to be configured based on the device connected */
spi_master_raiden_debug.data = data;
+ if (configure_protocol(&spi_master_raiden_debug)) {
+ msg_perr("Raiden: Error configuring protocol %d\n",
+ data->dev->interface_descriptor->bInterfaceProtocol);
+ return 1;
+ }
register_spi_master(&spi_master_raiden_debug);
register_shutdown(raiden_debug_spi_shutdown, data);
--
To view, visit https://review.coreboot.org/c/flashrom/+/41532
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id404af14e55fa0884e29f28880206aaad4deba66
Gerrit-Change-Number: 41532
Gerrit-PatchSet: 1
Gerrit-Owner: Brian Nemec <bnemec(a)google.com>
Gerrit-Reviewer: Brian Nemec <bnemec(a)chromium.org>
Gerrit-MessageType: newchange
Hello Brian Nemec,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/43550
to review the following change.
Change subject: raiden_debug_spi.c: Adds USB context states and helper functions
......................................................................
raiden_debug_spi.c: Adds USB context states and helper functions
Adds context states to handle the USB packets, these allow us to
simplify the process of loading data from the transmit buffer
into a USB packets' data section and from a USB packet to it's
receive buffers. These will also keep track of the size of the USB
packet allowing a simpler interface to transmit them.
Helper functions have been added to help with copying data between
the transmit and receive context states to and from the USB packets.
BUG=b:139058552
BRANCH=none
TEST=Manual testing of ServoMicro and Flashrom when performing
reads, writes, and verification of the EC firmware on Nami.
TEST=Builds
Signed-off-by: Brian J. Nemec <bnemec(a)chromium.com>
Change-Id: Id7b598b39923b4b8c1b6905e5d5c5a2be4078f96
---
M raiden_debug_spi.c
1 file changed, 202 insertions(+), 59 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/50/43550/1
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index cb7f809..1711ce6 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -155,6 +155,26 @@
GOOGLE_RAIDEN_SPI_PROTOCOL_V2 = 0x02,
};
+enum {
+ /* The host failed to transfer the data with no libusb error. */
+ USB_SPI_HOST_TX_BAD_TRANSFER = 0x10001,
+ /* The number of bytes written did not match expected. */
+ USB_SPI_HOST_TX_WRITE_FAILURE = 0x10002,
+
+
+ /* We did not receive the expected USB packet. */
+ USB_SPI_HOST_RX_UNEXPECTED_PACKET = 0x11001,
+ /* We received a continue packet with an invalid data index. */
+ USB_SPI_HOST_RX_BAD_DATA_INDEX = 0x11002,
+ /* We too much data. */
+ USB_SPI_HOST_RX_DATA_OVERFLOW = 0x11003,
+ /* The number of bytes read did not match expected. */
+ USB_SPI_HOST_RX_READ_FAILURE = 0x11004,
+
+ /* We were unable to configure the device. */
+ USB_SPI_HOST_INIT_FAILURE = 0x12001,
+};
+
enum usb_spi_error {
USB_SPI_SUCCESS = 0x0000,
USB_SPI_TIMEOUT = 0x0001,
@@ -213,6 +233,27 @@
uint8_t data[PAYLOAD_SIZE_V1];
} __attribute__((packed));
+union usb_spi_packet_v1 {
+ struct usb_spi_command_v1 command;
+ struct usb_spi_response_v1 response;
+} __attribute__((packed));
+
+struct usb_spi_packet_ctx {
+ union {
+ uint8_t bytes[USB_MAX_PACKET_SIZE];
+ union usb_spi_packet_v1 packet_v1;
+ };
+ /*
+ * By storing the number of bytes in the header and knowing that the
+ * USB data packets are all 64B long, we are able to use the header
+ * size to store the offset of the buffer and it's size without
+ * duplicating variables that can go out of sync.
+ */
+ size_t header_size;
+ /* Number of bytes in the packet */
+ size_t packet_size;
+};
+
struct usb_spi_transmit_ctx {
/* Buffer we are reading data from. */
const uint8_t *buffer;
@@ -265,9 +306,131 @@
}
/*
- * Version 1 Protocol: Responsible for constructing the packet to start
- * a USB SPI transfer. Write and read counts and payloads to write from
- * the write_buffer are transmitted to the device.
+ * Read data into the receive buffer.
+ *
+ * @param dst Destination receive context we are writing data to.
+ * @param src Source packet context we are reading data from.
+ *
+ * @returns status code 0 on success.
+ * USB_SPI_HOST_RX_DATA_OVERFLOW if the source packet is too
+ * large to fit in read buffer.
+ */
+static int read_usb_packet(struct usb_spi_receive_ctx *dst,
+ const struct usb_spi_packet_ctx *src)
+{
+ size_t max_read_length = dst->receive_size - dst->receive_index;
+ size_t bytes_in_buffer = src->packet_size - src->header_size;
+ const uint8_t *packet_buffer = src->bytes + src->header_size;
+
+ if (bytes_in_buffer > max_read_length) {
+ /*
+ * An error occurred, we should not receive more data than
+ * the buffer can support.
+ */
+ msg_perr("Raiden: Receive packet overflowed\n"
+ " bytes_in_buffer = %zu\n"
+ " max_read_length = %zu\n"
+ " receive_index = %zu\n"
+ " receive_size = %zu\n",
+ bytes_in_buffer, max_read_length,
+ dst->receive_size, dst->receive_index);
+ return USB_SPI_HOST_RX_DATA_OVERFLOW;
+ }
+ memcpy(dst->buffer + dst->receive_index, packet_buffer,
+ bytes_in_buffer);
+
+ dst->receive_index += bytes_in_buffer;
+ return 0;
+}
+
+/*
+ * Fill the USB packet with data from the transmit buffer.
+ *
+ * @param dst Destination packet context we are writing data to.
+ * @param src Source transmit context we are reading data from.
+ */
+static void fill_usb_packet(struct usb_spi_packet_ctx *dst,
+ struct usb_spi_transmit_ctx *src)
+{
+ size_t transmit_size = src->transmit_size - src->transmit_index;
+ size_t max_buffer_size = USB_MAX_PACKET_SIZE - dst->header_size;
+ uint8_t *packet_buffer = dst->bytes + dst->header_size;
+
+ if (transmit_size > max_buffer_size)
+ transmit_size = max_buffer_size;
+
+ memcpy(packet_buffer, src->buffer + src->transmit_index, transmit_size);
+
+ dst->packet_size = dst->header_size + transmit_size;
+ src->transmit_index += transmit_size;
+}
+
+/*
+ * Receive the data from the device USB endpoint and store in the packet.
+ *
+ * @param ctx_data Raiden SPI config.
+ * @param packet Destination packet used to store the endpoint data.
+ *
+ * @returns Returns status code with 0 on success.
+ */
+static int receive_packet(const struct flashctx *flash,
+ struct usb_spi_packet_ctx *packet)
+{
+ int received;
+ const struct raiden_debug_spi_data * ctx_data = get_raiden_data_from_context(flash);
+ int status = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
+ ctx_data->in_ep,
+ packet->bytes,
+ USB_MAX_PACKET_SIZE,
+ &received,
+ TRANSFER_TIMEOUT_MS));
+ packet->packet_size = received;
+ if (status) {
+ msg_perr("Raiden: IN transfer failed\n"
+ " received = %d\n"
+ " status = 0x%05x\n",
+ received, status);
+ }
+ return status;
+}
+
+/*
+ * Transmit data from the packet to the device's USB endpoint.
+ *
+ * @param flash Flash context storing SPI capabilities and USB device
+ * information.
+ * @param packet Source packet we will write to the endpoint data.
+ *
+ * @returns Returns status code with 0 on success.
+ */
+static int transmit_packet(const struct flashctx *flash,
+ struct usb_spi_packet_ctx *packet)
+{
+ int transferred;
+ const struct raiden_debug_spi_data * ctx_data = get_raiden_data_from_context(flash);
+ int status = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
+ ctx_data->out_ep,
+ packet->bytes,
+ packet->packet_size,
+ &transferred,
+ TRANSFER_TIMEOUT_MS));
+ if (status || (size_t)transferred != packet->packet_size) {
+ if (!status) {
+ /* No error was reported, but we didn't transmit the data expected. */
+ status = USB_SPI_HOST_TX_BAD_TRANSFER;
+ }
+ msg_perr("Raiden: OUT transfer failed\n"
+ " transferred = %d\n"
+ " packet_size = %zu\n"
+ " status = 0x%05x\n",
+ transferred, packet->packet_size, status);
+
+ }
+ return status;
+}
+
+/*
+ * Version 1 protocol command to start a USB SPI transfer and write the payload.
*
* @param flash Flash context storing SPI capabilities and USB device
* information.
@@ -280,38 +443,17 @@
struct usb_spi_transmit_ctx *write,
struct usb_spi_receive_ctx *read)
{
+ struct usb_spi_packet_ctx command = {
+ .header_size = offsetof(struct usb_spi_command_v1, data),
+ .packet_v1.command.write_count = write->transmit_size,
+ .packet_v1.command.read_count = read->receive_size
+ };
- int transferred;
- int ret;
- struct usb_spi_command_v1 command_packet;
- const struct raiden_debug_spi_data * ctx_data = get_raiden_data_from_context(flash);
+ /* Reset the write context to the start. */
+ write->transmit_index = 0;
- command_packet.write_count = write->transmit_size;
- command_packet.read_count = read->receive_size;
-
- memcpy(command_packet.data, write->buffer, write->transmit_size);
-
- ret = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
- ctx_data->out_ep,
- (void*)&command_packet,
- write->transmit_size + PACKET_HEADER_SIZE,
- &transferred,
- TRANSFER_TIMEOUT_MS));
- if (ret != 0) {
- msg_perr("Raiden: OUT transfer failed\n"
- " write_count = %zu\n"
- " read_count = %zu\n",
- write->transmit_size, read->receive_size);
- return ret;
- }
-
- if ((unsigned) transferred != write->transmit_size + PACKET_HEADER_SIZE) {
- msg_perr("Raiden: Write failure (wrote %d, expected %zu)\n",
- transferred, write->transmit_size + PACKET_HEADER_SIZE);
- return 0x10001;
- }
-
- return 0;
+ fill_usb_packet(&command, write);
+ return transmit_packet(flash, &command);
}
/*
@@ -330,34 +472,24 @@
struct usb_spi_transmit_ctx *write,
struct usb_spi_receive_ctx *read)
{
- int transferred;
- int ret;
- struct usb_spi_response_v1 response_packet;
- const struct raiden_debug_spi_data * ctx_data = get_raiden_data_from_context(flash);
+ int status;
+ struct usb_spi_packet_ctx response;
- ret = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle,
- ctx_data->in_ep,
- (void*)&response_packet,
- read->receive_size + PACKET_HEADER_SIZE,
- &transferred,
- TRANSFER_TIMEOUT_MS));
- if (ret != 0) {
- msg_perr("Raiden: IN transfer failed\n"
- " write_count = %zu\n"
- " read_count = %zu\n",
- write->transmit_size, read->receive_size);
- return ret;
+ /* Reset the read context to the start. */
+ read->receive_index = 0;
+
+ status = receive_packet(flash, &response);
+ if (status) {
+ /* Return the transfer error since the status_code is unreliable */
+ return status;
}
-
- if ((unsigned) transferred != read->receive_size + PACKET_HEADER_SIZE) {
- msg_perr("Raiden: Read failure (read %d, expected %zu)\n",
- transferred, read->receive_size + PACKET_HEADER_SIZE);
- return 0x10002;
+ if (response.packet_v1.response.status_code) {
+ return response.packet_v1.response.status_code;
}
+ response.header_size = offsetof(struct usb_spi_response_v1, data);
- memcpy(read->buffer, response_packet.data, read->receive_size);
-
- return response_packet.status_code;
+ status = read_usb_packet(read, &response);
+ return status;
}
/*
@@ -413,6 +545,12 @@
status = write_command_v1(flash, &write_ctx, &read_ctx);
+ if (!status &&
+ (write_ctx.transmit_index != write_ctx.transmit_size)) {
+ /* No errors were reported, but write is incomplete. */
+ status = USB_SPI_HOST_TX_WRITE_FAILURE;
+ }
+
if (status) {
/* Write operation failed. */
msg_perr("Raiden: Write command failed\n"
@@ -437,8 +575,13 @@
status = read_response_v1(flash, &write_ctx, &read_ctx);
if (!status) {
- /* Successful transfer. */
- return status;
+ if (read_ctx.receive_size == read_ctx.receive_index) {
+ /* Successful transfer. */
+ return status;
+ } else {
+ /* Report the error from the failed read. */
+ status = USB_SPI_HOST_RX_READ_FAILURE;
+ }
}
if (status) {
--
To view, visit https://review.coreboot.org/c/flashrom/+/43550
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id7b598b39923b4b8c1b6905e5d5c5a2be4078f96
Gerrit-Change-Number: 43550
Gerrit-PatchSet: 1
Gerrit-Owner: Brian Nemec <bnemec(a)google.com>
Gerrit-Reviewer: Brian Nemec <bnemec(a)chromium.org>
Gerrit-MessageType: newchange
Hello Brian Nemec,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/41597
to review the following change.
Change subject: raiden_debug_spi.c: Cleanup of the USB SPI protocol
......................................................................
raiden_debug_spi.c: Cleanup of the USB SPI protocol
Performs some cleanup of the USB SPI protocol:
* Minor cleanup of the comment descriptor for the protocol.
This adds the location of another relevant file, corrects the
omission of one of the protocol modes, makes the direction
of the packets explicit, and minor formating changes.
* Fixing typos in constants associated with the retry mechanism
* Removed an explicit comparison of 0 in a conditional
BUG=b:139058552
BRANCH=none
TEST=Builds
Signed-off-by: Brian J. Nemec <bnemec(a)chromium.com>
Change-Id: I17e62dabee2724eecf8d5a1a7827f06f0c7514df
---
M raiden_debug_spi.c
1 file changed, 38 insertions(+), 23 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/97/41597/1
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index 5259981..b18d580 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -42,35 +42,50 @@
*
* https://chromium.googlesource.com/chromiumos/platform/ec
*
- * The protocol for the USB-SPI bridge is documented in the following file in
- * that respository:
+ * The protocol for the USB-SPI bridge is implemented in the following files
+ * in that repository:
*
+ * chip/stm32/usb_spi.h
* chip/stm32/usb_spi.c
*
- * Version 1:
- * SPI transactions of up to 62B in each direction with every command having
- * a response. The initial packet from host contains a 2B header indicating
- * write and read counts with an optional payload length equal to the write
- * count. The device will respond with a message that reports the 2B status
- * code and an optional payload response length equal to read count.
+ * bInterfaceProtocol determines which protocol is used by the USB SPI device.
*
- * Message Format:
*
- * Command Packet:
+ * USB SPI Version 1:
+ *
+ * SPI transactions of up to 62B in each direction with every command having
+ * a response. The initial packet from host contains a 2B header indicating
+ * write and read counts with an optional payload length equal to the write
+ * count. The device will respond with a message that reports the 2B status
+ * code and an optional payload response length equal to read count.
+ *
+ *
+ * Message Packets:
+ *
+ * Command First Packet (Host to Device):
+ *
+ * USB SPI command, containing the number of bytes to write and read
+ * and a payload of bytes to write.
+ *
* +------------------+-----------------+------------------------+
* | write count : 1B | read count : 1B | write payload : <= 62B |
* +------------------+-----------------+------------------------+
*
* write count: 1 byte, zero based count of bytes to write
*
- * read count: 1 byte, zero based count of bytes to read
+ * read count: 1 byte, zero based count of bytes to read. Half duplex
+ * mode is enabled with '-1'
*
* write payload: Up to 62 bytes of data to write to SPI, the total
* length of all TX packets must match write count.
* Due to data alignment constraints, this must be an
* even number of bytes unless this is the final packet.
*
- * Response Packet:
+ * Response Packet (Device to Host):
+ *
+ * USB SPI response, containing the status code and any bytes of the
+ * read payload.
+ *
* +-------------+-----------------------+
* | status : 2B | read payload : <= 62B |
* +-------------+-----------------------+
@@ -81,8 +96,8 @@
* 0x0002: Busy, try again
* This can happen if someone else has acquired the shared memory
* buffer that the SPI driver uses as /dev/null
- * 0x0003: Write count invalid (V1 > 62B)
- * 0x0004: Read count invalid (V1 > 62B)
+ * 0x0003: Write count invalid (over 62 bytes)
+ * 0x0004: Read count invalid (over 62 bytes)
* 0x0005: The SPI bridge is disabled.
* 0x8000: Unknown error mask
* The bottom 15 bits will contain the bottom 15 bits from the EC
@@ -100,7 +115,7 @@
*
* 0x00000: Status code success.
* 0x00001-0x0FFFF: Error code returned by the USB SPI device.
- * 0x10001-0x1FFFF: The host has determined an error has occurred.
+ * 0x10001-0x1FFFF: USB SPI Host error codes
* 0x20001-0x20063 Lower bits store the positive value representation
* of the libusb_error enum. See the libusb documentation:
* http://libusb.sourceforge.net/api-1.0/group__misc.html
@@ -156,9 +171,9 @@
* See crbug.com/952494. Retry mechanisms have been implemented to recover
* from these rare failures allowing the process to continue.
*/
-#define WRITE_RETY_ATTEMPTS (3)
-#define READ_RETY_ATTEMPTS (3)
-#define RETY_INTERVAL_US (100 * 1000)
+#define WRITE_RETRY_ATTEMPTS (3)
+#define READ_RETRY_ATTEMPTS (3)
+#define RETRY_INTERVAL_US (100 * 1000)
/*
* This timeout is so large because the Raiden SPI timeout is 800ms.
@@ -310,7 +325,7 @@
{
int status = -1;
- for (int write_attempt = 0; write_attempt < WRITE_RETY_ATTEMPTS;
+ for (int write_attempt = 0; write_attempt < WRITE_RETRY_ATTEMPTS;
write_attempt++) {
status = write_command(flash, write_count, read_count,
@@ -326,15 +341,15 @@
/* Reattempting will not result in a recovery. */
return status;
}
- programmer_delay(RETY_INTERVAL_US);
+ programmer_delay(RETRY_INTERVAL_US);
continue;
}
- for (int read_attempt = 0; read_attempt < READ_RETY_ATTEMPTS; read_attempt++) {
+ for (int read_attempt = 0; read_attempt < READ_RETRY_ATTEMPTS; read_attempt++) {
status = read_response(flash, write_count, read_count,
write_buffer, read_buffer);
- if (status != 0) {
+ if (status) {
/* Read operation failed. */
msg_perr("Raiden: Read response failed\n"
"Write attempt = %d\n"
@@ -345,7 +360,7 @@
/* Reattempting will not result in a recovery. */
return status;
}
- programmer_delay(RETY_INTERVAL_US);
+ programmer_delay(RETRY_INTERVAL_US);
} else {
/* We were successful at performing the SPI transfer. */
return status;
--
To view, visit https://review.coreboot.org/c/flashrom/+/41597
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I17e62dabee2724eecf8d5a1a7827f06f0c7514df
Gerrit-Change-Number: 41597
Gerrit-PatchSet: 1
Gerrit-Owner: Brian Nemec <bnemec(a)google.com>
Gerrit-Reviewer: Brian Nemec <bnemec(a)chromium.org>
Gerrit-MessageType: newchange
Martijn Berger has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/39965 )
Change subject: pcidev: On arm64 we are not getting a valid BAR0 address
......................................................................
pcidev: On arm64 we are not getting a valid BAR0 address
It seems that there is some code to work around a possible bug in
old versions of libpci. This trusts libpci if it is new enough
Change-Id: I8bd32c6344b0831a949c3853abeb84905420922a
Signed-off-by: Martijn Berger <martijn.berger(a)gmail.com>
---
M pcidev.c
M programmer.h
2 files changed, 30 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/65/39965/1
diff --git a/pcidev.c b/pcidev.c
index 54c1fd3..973acde 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -30,20 +30,47 @@
TYPE_UNKNOWN
};
+int pci_bar_nuber_from_offset(int offset)
+{
+ switch (offset) {
+ case PCI_BASE_ADDRESS_0:
+ return 0;
+ case PCI_BASE_ADDRESS_1:
+ return 1;
+ case PCI_BASE_ADDRESS_2:
+ return 2;
+ case PCI_BASE_ADDRESS_3:
+ return 3;
+ case PCI_BASE_ADDRESS_4:
+ return 4;
+ case PCI_BASE_ADDRESS_5:
+ return 5;
+ default:
+ return -1;
+ }
+ return -1;
+}
+
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar)
{
uint64_t addr;
uint32_t upperaddr;
uint8_t headertype;
uint16_t supported_cycles;
+ int bar_number;
enum pci_bartype bartype = TYPE_UNKNOWN;
headertype = pci_read_byte(dev, PCI_HEADER_TYPE) & 0x7f;
msg_pspew("PCI header type 0x%02x\n", headertype);
+ bar_number = pci_bar_nuber_from_offset(bar);
- /* Don't use dev->base_addr[x] (as value for 'bar'), won't work on older libpci. */
- addr = pci_read_long(dev, bar);
+ if (PCI_LIB_VERSION >= 0x030500 && bar_number > -1) {
+ addr = dev->base_addr[bar_number];
+ } else {
+ /* Don't use dev->base_addr[x] (as value for 'bar'), won't work on older libpci. */
+ addr = pci_read_long(dev, bar);
+ }
/* Sanity checks. */
switch (headertype) {
diff --git a/programmer.h b/programmer.h
index 9a41be1..5d4c1d7 100644
--- a/programmer.h
+++ b/programmer.h
@@ -190,6 +190,7 @@
// FIXME: This needs to be local, not global(?)
extern struct pci_access *pacc;
int pci_init_common(void);
+int pci_bar_nuber_from_offset(int offset);
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
/* rpci_write_* are reversible writes. The original PCI config space register
--
To view, visit https://review.coreboot.org/c/flashrom/+/39965
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I8bd32c6344b0831a949c3853abeb84905420922a
Gerrit-Change-Number: 39965
Gerrit-PatchSet: 1
Gerrit-Owner: Martijn Berger
Gerrit-MessageType: newchange
Hello build bot (Jenkins), Nico Huber,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/43349
to look at the new patch set (#4).
Change subject: Add Gemini Lake support
......................................................................
Add Gemini Lake support
FIXME: Split detailed softstrap printing into its own commit
Signed-off-by: Angel Pons <th3fanbus(a)gmail.com>
Change-Id: I926a44176558115a2c833ef0954956eeb75061ff
---
M chipset_enable.c
M ich_descriptors.c
M ich_descriptors.h
M ichspi.c
M programmer.h
M util/ich_descriptors_tool/ich_descriptors_tool.c
6 files changed, 638 insertions(+), 14 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/49/43349/4
--
To view, visit https://review.coreboot.org/c/flashrom/+/43349
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I926a44176558115a2c833ef0954956eeb75061ff
Gerrit-Change-Number: 43349
Gerrit-PatchSet: 4
Gerrit-Owner: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-MessageType: newpatchset
Hello build bot (Jenkins), Nico Huber,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/43349
to look at the new patch set (#3).
Change subject: Add Gemini Lake support
......................................................................
Add Gemini Lake support
FIXME: Split detailed softstrap printing into its own commit
Signed-off-by: Angel Pons <th3fanbus(a)gmail.com>
Change-Id: I926a44176558115a2c833ef0954956eeb75061ff
---
M chipset_enable.c
M ich_descriptors.c
M ich_descriptors.h
M ichspi.c
M programmer.h
M util/ich_descriptors_tool/ich_descriptors_tool.c
6 files changed, 608 insertions(+), 14 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/49/43349/3
--
To view, visit https://review.coreboot.org/c/flashrom/+/43349
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I926a44176558115a2c833ef0954956eeb75061ff
Gerrit-Change-Number: 43349
Gerrit-PatchSet: 3
Gerrit-Owner: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-MessageType: newpatchset
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/43349 )
Change subject: Add Gemini Lake support
......................................................................
Patch Set 2:
This change is ready for review.
--
To view, visit https://review.coreboot.org/c/flashrom/+/43349
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I926a44176558115a2c833ef0954956eeb75061ff
Gerrit-Change-Number: 43349
Gerrit-PatchSet: 2
Gerrit-Owner: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-CC: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Comment-Date: Fri, 10 Jul 2020 15:19:23 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/42556 )
Change subject: [WIP] Add uncrustify config
......................................................................
[WIP] Add uncrustify config
Similar to CB:38673, this attempts to add a config file for uncrustify
as an alternative to clang-format, which has some limitations as
mentioned in the other patch.
This adds a config file which is a copy of the linux.cfg file. Newer
versions of this patch will tweak the config file as needed for
flashrom.
Change-Id: Ib6bd3ab49e841768f07c2705f71be66e9308bbca
Signed-off-by: David Hendricks <david.hendricks(a)gmail.com>
---
M 82802ab.c
M amd_imc.c
M at45db.c
M atahpt.c
M atapromise.c
M atavia.c
M bitbang_spi.c
M board_enable.c
M buspirate_spi.c
M cbtable.c
M ch341a_spi.c
M chipdrivers.h
M chipset_enable.c
M cli_classic.c
M cli_common.c
M cli_output.c
M coreboot_tables.h
M custom_baud.c
M custom_baud.h
M dediprog.c
M developerbox_spi.c
M digilent_spi.c
M dmi.c
M drkaiser.c
M dummyflasher.c
M edi.c
M edi.h
M en29lv640b.c
M ene.h
M flash.h
M flashchips.c
M flashchips.h
M flashrom.c
M fmap.c
M fmap.h
M ft2232_spi.c
M gfxnvidia.c
M helpers.c
M hwaccess.c
M hwaccess.h
M i2c_helper.h
M i2c_helper_linux.c
M ich_descriptors.c
M ich_descriptors.h
M ichspi.c
M internal.c
M it8212.c
M it85spi.c
M it87spi.c
M jedec.c
M jlink_spi.c
M layout.c
M layout.h
M libflashrom.c
M libflashrom.h
M linux_mtd.c
M linux_spi.c
M lspcon_i2c_spi.c
M mcp6x_spi.c
M mstarddc_spi.c
M ni845x_spi.c
M nic3com.c
M nicintel.c
M nicintel_eeprom.c
M nicintel_spi.c
M nicnatsemi.c
M nicrealtek.c
M ogp_spi.c
M os.h
M pcidev.c
M physmap.c
M pickit2_spi.c
M platform.h
M pony_spi.c
M print.c
M print_wiki.c
M processor_enable.c
M programmer.c
M programmer.h
M raiden_debug_spi.c
M rayer_spi.c
M realtek_mst_i2c_spi.c
M satamv.c
M satasii.c
M sb600spi.c
M serial.c
M serprog.c
M serprog.h
M sfdp.c
M spi.c
M spi.h
M spi25.c
M spi25_statusreg.c
M spi95.c
M sst28sf040.c
M sst_fwhub.c
M stlinkv3_spi.c
M udelay.c
A uncrustify.cfg
M usb_device.c
M usb_device.h
M usbblaster_spi.c
M usbdev.c
M w39.c
M wbsio_spi.c
105 files changed, 17,980 insertions(+), 17,840 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/56/42556/1
--
To view, visit https://review.coreboot.org/c/flashrom/+/42556
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ib6bd3ab49e841768f07c2705f71be66e9308bbca
Gerrit-Change-Number: 42556
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
Simon Buhrow has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/40477 )
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
Patch Set 14:
Needs Patch 43282 ! If not data will be lost.
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 14
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Comment-Date: Wed, 08 Jul 2020 07:24:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Simon Buhrow has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/40477 )
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
Patch Set 14:
(1 comment)
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c
File ft2232_spi.c:
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@403
PS11, Line 403: if (ftdi_write_data_set_chunksize(ftdic, 280)) {
: /*
: * 280 bytes =
: * + 9 B (CMD)
: * + 1 B (WREN)
: * + 9 B (CMD)
: * + 1 B (op)
: * + 4 B (addr)
: * + 256 B (page data)
: *
: * With op: PageProgram or Erase; CMD: FTDI-Chip commands
: */
> I don't recall suggesting that (my memory is terrible). […]
I don´t get your "suggesting that". But this might be because of my very bad english, I´m sorry!
Nevertheless I removed it from this commit it as you suggested.
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 14
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Comment-Date: Wed, 08 Jul 2020 07:18:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Simon Buhrow
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-MessageType: comment
Hello build bot (Jenkins), Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/40477
to look at the new patch set (#14).
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
Every ftdi_write_data() call is quite time consuming as the ftdi-chips
seems to take always 2-3ms to respond.
This leads to what the comment already says: Minimize USB transfers
by packing as many commands as possible together.
So I packed the WREN command together with the following operation
which can be program or erase operation.
This saves about 1 minute when programming a 128MBit Flash with my
config!
I´m using ftdi-2232H chip. That´s why I put it at this place.
If anyone has a good overview about all programmers:
This could be implemented in spi_write_cmd() in case that it is
compatible to all programmers
or this principle could be transfered to other programmers which act
in a similar way.
Signed-off-by: Simon Buhrow <simon.buhrow(a)posteo.de>
Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
---
M ft2232_spi.c
1 file changed, 24 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/77/40477/14
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 14
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-MessageType: newpatchset
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/40477 )
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c
File ft2232_spi.c:
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@403
PS11, Line 403: if (ftdi_write_data_set_chunksize(ftdic, 280)) {
: /*
: * 280 bytes =
: * + 9 B (CMD)
: * + 1 B (WREN)
: * + 9 B (CMD)
: * + 1 B (op)
: * + 4 B (addr)
: * + 256 B (page data)
: *
: * With op: PageProgram or Erase; CMD: FTDI-Chip commands
: */
> This goes with the time saving changes in ft2232_spi_send_command() below. […]
I don't recall suggesting that (my memory is terrible). In any case, the 1st commit would be much easier to +2 and submit than the 3rd commit (I still need to understand and test it)
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 13
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Comment-Date: Tue, 07 Jul 2020 13:30:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Simon Buhrow
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-MessageType: comment
Simon Buhrow has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/40477 )
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
Patch Set 13:
(4 comments)
Thanks for your ideas!
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c
File ft2232_spi.c:
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@403
PS11, Line 403: if (ftdi_write_data_set_chunksize(ftdic, 280)) {
: /*
: * 280 bytes =
: * + 9 B (CMD)
: * + 1 B (WREN)
: * + 9 B (CMD)
: * + 1 B (op)
: * + 4 B (addr)
: * + 256 B (page data)
: *
: * With op: PageProgram or Erase; CMD: FTDI-Chip commands
: */
> Increasing the chunksize can be the 1st commit
This goes with the time saving changes in ft2232_spi_send_command() below. That´s why I think your proposed 1st and 3rd commit go together.
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@481
PS11, Line 481: static unsigned char buf[FTDI_HW_BUFFER_SIZE];
> Using a fixed-size buffer can be the 2nd commit
Done.
OK, I see that this does not necessarily go with the time saving changes! Thanks!
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@483
PS11, Line 483: static int i = 0;
> This line is part of the 3rd commit
Done
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@541
PS11, Line 541: if (writearr[0] == JEDEC_WREN) {
: /* Return to get second op (Program or Erase) without resetting buf nor i*/
: return 0;
: } else {
: ret = send_buf(ftdic, buf, i);
: i = 0;
: }
> This is the rest of the 3rd commit
Done.
This is the main part of time saving change.
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 13
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Comment-Date: Tue, 07 Jul 2020 13:11:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-MessageType: comment
Hello build bot (Jenkins), Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/40477
to look at the new patch set (#13).
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
Every ftdi_write_data() call is quite time consuming as the ftdi-chips
seems to take always 2-3ms to respond.
This leads to what the comment already says: Minimize USB transfers
by packing as many commands as possible together.
So I packed the WREN command together with the following operation
which can be program or erase operation.
This saves about 1 minute when programming a 128MBit Flash with my
config!
I´m using ftdi-2232H chip. That´s why I put it at this place.
If anyone has a good overview about all programmers:
This could be implemented in spi_write_cmd() in case that it is
compatible to all programmers
or this principle could be transfered to other programmers which act
in a similar way.
Signed-off-by: Simon Buhrow <simon.buhrow(a)posteo.de>
Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
---
M ft2232_spi.c
1 file changed, 36 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/77/40477/13
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 13
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-MessageType: newpatchset
Hello build bot (Jenkins), Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/40477
to look at the new patch set (#12).
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
Every ftdi_write_data() call is quite time consuming as the ftdi-chips
seems to take always 2-3ms to respond.
This leads to what the comment already says: Minimize USB transfers
by packing as many commands as possible together.
So I packed the WREN command together with the following operation
which can be program or erase operation.
This saves about 1 minute when programming a 128MBit Flash with my
config!
See timings WREN in extra ftdi_write_data() call:
https://ibb.co/0c1J25d
WREN packed with op:
https://ibb.co/7G1hLkj
I´m using ftdi-2232H chip. That´s why I put it at this place.
If anyone has a good overview about all programmers:
This could be implemented in spi_write_cmd() in case that it is
compatible to all programmers
or this principle could be transfered to other programmers which act
in a similar way.
Signed-off-by: Simon Buhrow <simon.buhrow(a)posteo.de>
Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
---
M ft2232_spi.c
1 file changed, 36 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/77/40477/12
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 12
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-MessageType: newpatchset
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/40477 )
Change subject: ft2232_spi.c: Pack WREN and op in one ftdi_write_data() call
......................................................................
Patch Set 11:
(5 comments)
> Patch Set 11:
>
> Anyone having time to give some feedback?
Well, I see three different changes on this commit, and would prefer to split them up.
https://review.coreboot.org/c/flashrom/+/40477/8//COMMIT_MSG
Commit Message:
https://review.coreboot.org/c/flashrom/+/40477/8//COMMIT_MSG@17
PS8, Line 17: https://ibb.co/0c1J25d
> How do I better? Is there a better way to provide images? Just let me know.
I wouldn't provide them in a commit message
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c
File ft2232_spi.c:
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@403
PS11, Line 403: if (ftdi_write_data_set_chunksize(ftdic, 280)) {
: /*
: * 280 bytes =
: * + 9 B (CMD)
: * + 1 B (WREN)
: * + 9 B (CMD)
: * + 1 B (op)
: * + 4 B (addr)
: * + 256 B (page data)
: *
: * With op: PageProgram or Erase; CMD: FTDI-Chip commands
: */
Increasing the chunksize can be the 1st commit
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@481
PS11, Line 481: static unsigned char buf[FTDI_HW_BUFFER_SIZE];
Using a fixed-size buffer can be the 2nd commit
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@483
PS11, Line 483: static int i = 0;
This line is part of the 3rd commit
https://review.coreboot.org/c/flashrom/+/40477/11/ft2232_spi.c@541
PS11, Line 541: if (writearr[0] == JEDEC_WREN) {
: /* Return to get second op (Program or Erase) without resetting buf nor i*/
: return 0;
: } else {
: ret = send_buf(ftdic, buf, i);
: i = 0;
: }
This is the rest of the 3rd commit
--
To view, visit https://review.coreboot.org/c/flashrom/+/40477
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4a07499ec5ef0af23818593f45dc427285a9e8a
Gerrit-Change-Number: 40477
Gerrit-PatchSet: 11
Gerrit-Owner: Simon Buhrow
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Comment-Date: Sat, 04 Jul 2020 18:30:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Simon Buhrow
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-MessageType: comment