David Hendricks has uploaded this change for review.
dediprog: add serial argument
A quick hack to be able to select dediprogs by USB serial argument by
just adding a @serial_number parameter to dediprog_open() and using it
in preference to @id if available (since it is more specific).
Change-Id: I9cdfbce6cf941c16bf7b7364aa4166b91369e661
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
---
M dediprog.c
M flashrom.8.tmpl
2 files changed, 23 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/06/37406/1
diff --git a/dediprog.c b/dediprog.c
index 175e099..480cf67 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1006,15 +1006,19 @@
/*
* Open a dediprog_handle with the USB device at the given index.
* @index index of the USB device
+ * @serial_number serial number of the USB device (id is ignored then)
* @return 0 for success, -1 for error, -2 for busy device
*/
-static int dediprog_open(int index)
+static int dediprog_open(int index, char *serial_number)
{
const uint16_t vid = devs_dediprog[0].vendor_id;
const uint16_t pid = devs_dediprog[0].device_id;
int ret;
- dediprog_handle = usb_dev_get_by_vid_pid_number(usb_ctx, vid, pid, (unsigned int) index);
+ if (serial_number)
+ dediprog_handle = usb_dev_get_by_vid_pid_serial(usb_ctx, vid, pid, serial_number);
+ else
+ dediprog_handle = usb_dev_get_by_vid_pid_number(usb_ctx, vid, pid, (unsigned int) index);
if (!dediprog_handle) {
msg_perr("Could not find a Dediprog programmer on USB.\n");
libusb_exit(usb_ctx);
@@ -1057,7 +1061,8 @@
int dediprog_init(void)
{
- char *voltage, *id_str, *device, *spispeed, *target_str;
+ char *voltage, *id_str, *device, *spispeed, *target_str,
+ *serial_number;
int spispeed_idx = 1;
int millivolt = 3500;
int id = -1; /* -1 defaults to enumeration order */
@@ -1091,6 +1096,7 @@
msg_pinfo("Setting voltage to %i mV\n", millivolt);
}
+ serial_number = extract_programmer_param("serial");
id_str = extract_programmer_param("id");
if (id_str) {
char prefix0, prefix1;
@@ -1183,9 +1189,14 @@
return 1;
}
- if (id != -1) {
+ if (serial_number) {
+ if (dediprog_open(0, serial_number)) {
+ return 1;
+ }
+ found_id = dediprog_read_id();
+ } else if (id != -1) {
for (i = 0; ; i++) {
- ret = dediprog_open(i);
+ ret = dediprog_open(i, NULL);
if (ret == -1) {
/* no dev */
libusb_exit(usb_ctx);
@@ -1218,7 +1229,7 @@
break;
}
} else {
- if (dediprog_open(usedevice)) {
+ if (dediprog_open(usedevice, NULL)) {
return 1;
}
found_id = dediprog_read_id();
@@ -1276,6 +1287,5 @@
if (register_spi_master(&spi_master_dediprog) || dediprog_set_leds(LED_NONE))
return 1;
-
return 0;
}
diff --git a/flashrom.8.tmpl b/flashrom.8.tmpl
index 27f3846..5af1a38 100644
--- a/flashrom.8.tmpl
+++ b/flashrom.8.tmpl
@@ -928,6 +928,12 @@
.BR 0V ", " 1.8V ", " 2.5V ", " 3.5V
or the equivalent in mV.
.sp
+You can use the
+.B serial
+parameter to explicitly specify which dediprog device should be used
+based on their USB serial number::
+.sp
+.B " flashrom \-p dediprog:serial=1230A12"
An optional
.B device
parameter specifies which of multiple connected Dediprog devices should be used.
To view, visit change 37406. To unsubscribe, or for help writing mail filters, visit settings.