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
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
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