1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-01 22:21:16 +02:00

raiden: Support target index with generic REQ_ENABLE

Some devices such as the GSC knows how it is wired to AP and EC flash
chips, and can be told which specific device to talk to.  Other devices
such as Servo Micro and HyperDebug are generic, and do not know how they
are wired, the caller is responsible for first configure the appropriate
MUXes or buffers, and then tell the debugger which port to use (Servo
Micro has just one SPI port, HyperDebug is the first that has multiple).
The Raiden protocol allows both the cases of USB devices knowing their
wiring and not.

If I were to declare the protocol in Rust, this is how the information
of the Raiden protocol "enable request" would be encoded:
```
enum {
  EnableGeneric(u8),
  EnableAp,
  EnableEc,
  ...
}
```

The first label `EnableGeneric(u8)` is to be used with HyperDebug that
does not know how its ports are wired, and allow access by index.
The other labels `EnableAp` and `EnableEc` are to be used with the GSC.

The actual transmission of the enum above uses the bRequest and low byte
of wValue of a USB control request, but that is a detail and not
conceptually important.

Until now, `-p raiden_debug_spi:target=AP` or `...:target=EC` could be
used to make flashrom use `EnableAp` or `EnableEc`, and if neither was
given, it would default to `EnableGeneric`, which now that wValue is
used means `EnableGeneric(0)`.

I find it rather straight-forward, that `-p raiden_debug_spi:target=1`,
`...:target=2`, etc. should translate to `EnableGeneric(1)`, etc.

This patchset achieves this, by adding a second 16-bit parameter value,
next to request_enable.

I have tested that flashrom can detect the same Winbond flash chip
"W25Q128.V..M" with two different Raiden USB devices as below.

TEST=flashrom -p raiden_debug_spi:serial=0701B044-91AC3132,target=AP
TEST=flashrom -p raiden_debug_spi:serial=205635783236,target=1

Signed-off-by: Jes B. Klinke <jbk@chromium.org>
Change-Id: I03bf4f3210186fb5937b42e298761907b03e08b7
Reviewed-on: https://review.coreboot.org/c/flashrom/+/77999
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Jes B. Klinke
2023-04-13 22:18:30 -07:00
committed by Anastasia Klimchuk
parent 86110b4077
commit ea91d4fcf4
5 changed files with 132 additions and 19 deletions

View File

@ -1450,29 +1450,43 @@ static int get_ap_request_type(const struct programmer_cfg *cfg)
return ap_request;
}
static int get_target(const struct programmer_cfg *cfg)
static int decode_programmer_param(const struct programmer_cfg *cfg, uint8_t *request,
uint16_t *request_parameter)
{
/**
* REQ_ENABLE doesn't specify a target bus, and will be rejected
* by adapters that support more than one target.
*/
int request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE;
uint8_t request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE;
uint16_t parameter = 0;
int ret = 0;
char *target_str = extract_programmer_param_str(cfg, "target");
printf("FISK: %s\n", target_str);
if (target_str) {
if (!strcasecmp(target_str, "ap"))
char *endptr;
int index = strtol(target_str, &endptr, 0);
if (*target_str && !*endptr && index >= 0 && index < 256) {
request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE;
parameter = index;
} else if (!strcasecmp(target_str, "ap"))
request_enable = get_ap_request_type(cfg);
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;
ret = 1;
}
}
free(target_str);
msg_pinfo("Raiden target: %d\n", request_enable);
if (ret == 0) {
msg_pinfo("Raiden target: %d,%d\n", request_enable, parameter);
return request_enable;
*request = request_enable;
*request_parameter = parameter;
}
return ret;
}
static void free_dev_list(struct usb_device **dev_lst)
@ -1493,10 +1507,12 @@ static int raiden_debug_spi_init(const struct programmer_cfg *cfg)
bool found = false;
int ret;
int request_enable = get_target(cfg);
if (request_enable < 0) {
uint8_t request_enable;
uint16_t request_parameter;
ret = decode_programmer_param(cfg, &request_enable, &request_parameter);
if (ret != 0) {
free(serial);
return 1;
return ret;
}
usb_match_init(cfg, &match);
@ -1588,7 +1604,7 @@ loop_end:
LIBUSB_REQUEST_TYPE_VENDOR |
LIBUSB_RECIPIENT_INTERFACE,
request_enable,
0,
request_parameter,
device->interface_descriptor->bInterfaceNumber,
NULL,
0,