Patchwork Add a "device" parameter for Dediprog

login
register
about
Submitter David Hendricks
Date 2012-11-01 17:12:01
Message ID <CAKOoyUecW6jOx9Cr6faeu=e-R7SqLk7T=OB8zd7jYbYFiOwxHw@mail.gmail.com>
Download mbox | patch
Permalink /patch/3781/
State Superseded
Headers show

Comments

David Hendricks - 2012-11-01 17:12:01
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@google.com>
Signed-off-by: David Hendricks <dhendrix@google.com>

        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;

Patch

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;