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

@ -104,15 +104,100 @@ void raiden_debug_basic_lifecycle_test_success(void **state)
.fallback_open_state = &raiden_debug_fallback_open_state,
};
/*
* 12 is the length of programmer param string for 3-digit address.
* Address can be max 3-digit because it needs to fit into uint8_t.
*/
char raiden_debug_param[12];
snprintf(raiden_debug_param, 12, "address=%d", USB_DEVICE_ADDRESS);
char raiden_debug_param[32];
snprintf(raiden_debug_param, sizeof(raiden_debug_param),
"address=%d", USB_DEVICE_ADDRESS);
run_basic_lifecycle(state, &raiden_debug_io, &programmer_raiden_debug_spi, raiden_debug_param);
}
void raiden_debug_targetAP_basic_lifecycle_test_success(void **state)
{
struct io_mock_fallback_open_state raiden_debug_fallback_open_state = {
.noc = 0,
.paths = { NULL },
};
const struct io_mock raiden_debug_io = {
.libusb_get_device_list = raiden_debug_libusb_get_device_list,
.libusb_free_device_list = raiden_debug_libusb_free_device_list,
.libusb_get_device_descriptor = raiden_debug_libusb_get_device_descriptor,
.libusb_get_config_descriptor = raiden_debug_libusb_get_config_descriptor,
.libusb_free_config_descriptor = raiden_debug_libusb_free_config_descriptor,
.fallback_open_state = &raiden_debug_fallback_open_state,
};
char raiden_debug_param[32];
snprintf(raiden_debug_param, sizeof(raiden_debug_param),
"address=%d,target=AP", USB_DEVICE_ADDRESS);
run_basic_lifecycle(state, &raiden_debug_io, &programmer_raiden_debug_spi, raiden_debug_param);
}
void raiden_debug_targetEC_basic_lifecycle_test_success(void **state)
{
struct io_mock_fallback_open_state raiden_debug_fallback_open_state = {
.noc = 0,
.paths = { NULL },
};
const struct io_mock raiden_debug_io = {
.libusb_get_device_list = raiden_debug_libusb_get_device_list,
.libusb_free_device_list = raiden_debug_libusb_free_device_list,
.libusb_get_device_descriptor = raiden_debug_libusb_get_device_descriptor,
.libusb_get_config_descriptor = raiden_debug_libusb_get_config_descriptor,
.libusb_free_config_descriptor = raiden_debug_libusb_free_config_descriptor,
.fallback_open_state = &raiden_debug_fallback_open_state,
};
char raiden_debug_param[32];
snprintf(raiden_debug_param, sizeof(raiden_debug_param),
"address=%d,target=ec", USB_DEVICE_ADDRESS);
run_basic_lifecycle(state, &raiden_debug_io, &programmer_raiden_debug_spi, raiden_debug_param);
}
void raiden_debug_target0_basic_lifecycle_test_success(void **state)
{
struct io_mock_fallback_open_state raiden_debug_fallback_open_state = {
.noc = 0,
.paths = { NULL },
};
const struct io_mock raiden_debug_io = {
.libusb_get_device_list = raiden_debug_libusb_get_device_list,
.libusb_free_device_list = raiden_debug_libusb_free_device_list,
.libusb_get_device_descriptor = raiden_debug_libusb_get_device_descriptor,
.libusb_get_config_descriptor = raiden_debug_libusb_get_config_descriptor,
.libusb_free_config_descriptor = raiden_debug_libusb_free_config_descriptor,
.fallback_open_state = &raiden_debug_fallback_open_state,
};
char raiden_debug_param[32];
snprintf(raiden_debug_param, sizeof(raiden_debug_param),
"address=%d,target=0", USB_DEVICE_ADDRESS);
run_basic_lifecycle(state, &raiden_debug_io, &programmer_raiden_debug_spi, raiden_debug_param);
}
void raiden_debug_target1_basic_lifecycle_test_success(void **state)
{
struct io_mock_fallback_open_state raiden_debug_fallback_open_state = {
.noc = 0,
.paths = { NULL },
};
const struct io_mock raiden_debug_io = {
.libusb_get_device_list = raiden_debug_libusb_get_device_list,
.libusb_free_device_list = raiden_debug_libusb_free_device_list,
.libusb_get_device_descriptor = raiden_debug_libusb_get_device_descriptor,
.libusb_get_config_descriptor = raiden_debug_libusb_get_config_descriptor,
.libusb_free_config_descriptor = raiden_debug_libusb_free_config_descriptor,
.fallback_open_state = &raiden_debug_fallback_open_state,
};
char raiden_debug_param[32];
snprintf(raiden_debug_param, sizeof(raiden_debug_param),
"address=%d,target=1", USB_DEVICE_ADDRESS);
run_basic_lifecycle(state, &raiden_debug_io, &programmer_raiden_debug_spi, raiden_debug_param);
}
#else
SKIP_TEST(raiden_debug_basic_lifecycle_test_success)
SKIP_TEST(raiden_debug_targetAP_basic_lifecycle_test_success)
SKIP_TEST(raiden_debug_targetEC_basic_lifecycle_test_success)
SKIP_TEST(raiden_debug_target0_basic_lifecycle_test_success)
SKIP_TEST(raiden_debug_target1_basic_lifecycle_test_success)
#endif /* CONFIG_RAIDEN_DEBUG_SPI */

View File

@ -463,6 +463,10 @@ int main(int argc, char *argv[])
cmocka_unit_test(dummy_all_buses_test_success),
cmocka_unit_test(nicrealtek_basic_lifecycle_test_success),
cmocka_unit_test(raiden_debug_basic_lifecycle_test_success),
cmocka_unit_test(raiden_debug_targetAP_basic_lifecycle_test_success),
cmocka_unit_test(raiden_debug_targetEC_basic_lifecycle_test_success),
cmocka_unit_test(raiden_debug_target0_basic_lifecycle_test_success),
cmocka_unit_test(raiden_debug_target1_basic_lifecycle_test_success),
cmocka_unit_test(dediprog_basic_lifecycle_test_success),
cmocka_unit_test(linux_mtd_probe_lifecycle_test_success),
cmocka_unit_test(linux_spi_probe_lifecycle_test_success),

View File

@ -54,6 +54,10 @@ void dummy_null_prog_param_test_success(void **state);
void dummy_all_buses_test_success(void **state);
void nicrealtek_basic_lifecycle_test_success(void **state);
void raiden_debug_basic_lifecycle_test_success(void **state);
void raiden_debug_targetAP_basic_lifecycle_test_success(void **state);
void raiden_debug_targetEC_basic_lifecycle_test_success(void **state);
void raiden_debug_target0_basic_lifecycle_test_success(void **state);
void raiden_debug_target1_basic_lifecycle_test_success(void **state);
void dediprog_basic_lifecycle_test_success(void **state);
void linux_mtd_probe_lifecycle_test_success(void **state);
void linux_spi_probe_lifecycle_test_success(void **state);