johnsonh@waymo.com has uploaded this change for review.

View Change

ft2232_spi: Add FTDI search by description.

This adds to the search-by-serial functionality with
search-by-description (product string). This is useful when e.g. one has
multiple FTDIs in a system and wants the serial numbers to reflect the
system-level serial number, and the description to reflect the
subcomponent names.

Tested manually by running with both serial and description searches, on
a machine with multiple FTDIs plugged in. Ensured that when two devices
with the same vid/pid/serial number are plugged in, description can still
be used to differentiate.

Change-Id: Ib4be23247995710900175f5f16e38db577ef08fa
Signed-off-by: Harry Johnson <johnsonh@waymo.com>
---
M ft2232_spi.c
1 file changed, 20 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/64/56164/1
diff --git a/ft2232_spi.c b/ft2232_spi.c
index d853b09..756a603 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -498,10 +498,29 @@
msg_perr("Unable to select channel (%s).\n", ftdi_get_error_string(&ftdic));
}

+ // Prefer search by serial if possible.
arg = extract_programmer_param("serial");
- f = ftdi_usb_open_desc(&ftdic, ft2232_vid, ft2232_type, NULL, arg);
+ if (arg && strlen(arg)) {
+ f = ftdi_usb_open_desc(&ftdic, ft2232_vid, ft2232_type, NULL, arg);
+ free(arg);
+ goto usb_opened;
+ }
free(arg);

+ // If serial unavailable, allow search by description.
+ arg = extract_programmer_param("description");
+ if (arg && strlen(arg)) {
+ f = ftdi_usb_open_desc(&ftdic, ft2232_vid, ft2232_type, arg, NULL);
+ free(arg);
+ goto usb_opened;
+ }
+ free(arg);
+
+ // If serial and description unavailable, search by VID/PID only.
+ f = ftdi_usb_open_desc(&ftdic, ft2232_vid, ft2232_type, NULL, NULL);
+
+usb_opened:
+
if (f < 0 && f != -5) {
msg_perr("Unable to open FTDI device: %d (%s)\n", f,
ftdi_get_error_string(&ftdic));

To view, visit change 56164. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ib4be23247995710900175f5f16e38db577ef08fa
Gerrit-Change-Number: 56164
Gerrit-PatchSet: 1
Gerrit-Owner: johnsonh@waymo.com
Gerrit-MessageType: newchange