[flashrom] Add a "device" parameter for Dediprog

David Hendricks dhendrix at google.com
Thu Nov 1 18:12:01 CET 2012


This patch adds a "device" parameter for Dediprog which enables use of
multiple dediprogs connected to a single machine. Very handy for test racks.

Example usage:
flashrom -p dediprog:device=0
flashrom -p dediprog:device=1
etc...

The patch was originally written by Nathan Laredo, I'm just forwarding it
upstream:
Signed-off-by: Nathan Laredo <nil at google.com>
Signed-off-by: David Hendricks <dhendrix at google.com>

Index: dediprog.c
===================================================================
--- dediprog.c  (revision 1620)
+++ dediprog.c  (working copy)
@@ -46,7 +46,9 @@
 #endif

 /* Might be useful for other USB devices as well. static for now. */
-static struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid)
+/* device parameter allows user to specify one device of multiple
installed */
+static struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid,
+                                                int device)
 {
        struct usb_bus *bus;
        struct usb_device *dev;
@@ -54,8 +56,11 @@
        for (bus = usb_get_busses(); bus; bus = bus->next)
                for (dev = bus->devices; dev; dev = dev->next)
                        if ((dev->descriptor.idVendor == vid) &&
-                           (dev->descriptor.idProduct == pid))
-                               return dev;
+                           (dev->descriptor.idProduct == pid)) {
+                               if (device == 0)
+                                       return dev;
+                               device--;
+                        }

        return NULL;
 }
@@ -777,8 +782,9 @@
 int dediprog_init(void)
 {
        struct usb_device *dev;
-       char *voltage;
+       char *voltage, *device;
        int millivolt = 3500;
+       int usedevice = 0;
        int ret;

        msg_pspew("%s\n", __func__);
@@ -792,11 +798,21 @@
                msg_pinfo("Setting voltage to %i mV\n", millivolt);
        }

+       device = extract_programmer_param("device");
+       if (device) {
+               usedevice = strtol(device, NULL, 0);
+               free(device);
+               if (usedevice < 0)
+                       return 1;
+               msg_pinfo("Using device %i\n", usedevice);
+       }
+
+
        /* Here comes the USB stuff. */
        usb_init();
        usb_find_busses();
        usb_find_devices();
-       dev = get_device_by_vid_pid(0x0483, 0xdada);
+       dev = get_device_by_vid_pid(0x0483, 0xdada, usedevice);
        if (!dev) {
                msg_perr("Could not find a Dediprog SF100 on USB!\n");
                return 1;

-- 
David Hendricks (dhendrix)
Systems Software Engineer, Google Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.flashrom.org/pipermail/flashrom/attachments/20121101/987619e1/attachment.html>


More information about the flashrom mailing list