As we had left out the list in the last emails, here the patch again.

In the config file it adds the usb params to usbasp, adds a usbasp-clone
which only defines usb pid/vid and a nibobee programmer.

In the code it checks for pid/vid as given and product and vendor when
defined in config file. In case the programmer is "usbasp" and it does
not find one, it checks for a nibobee, if -P nibobee is given, or for an
old usbasp. In both cases you get a warning to use the new nibobee entry
in first case, and to update the firmware in second one.

Kind regards,

René
 
Am 15.01.2012 20:04, schrieb Joerg Wunsch:
> As René Liebscher wrote:
>
>>    Also, why are we making original USBasp, it's old version and
>>    NIBObee special cases hardcoded into usbasp_open function?
>>    Shouldn't the code be made generic and these 3 also moved to
>>    config file?
> Yes, probably.

Index: avrdude.conf.in
===================================================================
--- avrdude.conf.in     (revision 1039)
+++ avrdude.conf.in     (working copy)
@@ -570,9 +570,47 @@
   id    = "usbasp";
   desc  = "USBasp, http://www.fischl.de/usbasp/";;
   type  = usbasp;
+  usbvid     = 0x16C0; # VOTI
+  usbpid     = 0x05DC; # Obdev's free shared PID
+  usbvendor  = "www.fischl.de";
+  usbproduct = "USBasp";
+
+  # following variants are autodetected for id "usbasp"
+
+  # original usbasp from fischl.de
+  # see above "usbasp"
+
+  # old usbasp from fischl.de
+  #usbvid     = 0x03EB; # ATMEL
+  #usbpid     = 0xC7B4; # (unoffical) USBasp
+  #usbvendor  = "www.fischl.de";
+  #usbproduct = "USBasp";
+
+  # NIBObee (only if -P nibobee is given on command line)
+  # see below "nibobee"
 ;
 
 programmer
+  id    = "nibobee";
+  desc  = "NIBObee";
+  type  = usbasp;
+  usbvid     = 0x16C0; # VOTI
+  usbpid     = 0x092F; # NIBObee PID
+  usbvendor  = "www.nicai-systems.com";
+  usbproduct = "NIBObee";
+;
+
+programmer
+  id    = "usbasp-clone";
+  desc  = "Any usbasp clone with correct VID/PID";
+  type  = usbasp;
+  usbvid    = 0x16C0; # VOTI
+  usbpid    = 0x05DC; # Obdev's free shared PID
+  #usbvendor  = "";
+  #usbproduct = "";
+;
+
+programmer
   id    = "usbtiny";
   desc  = "USBtiny simple USB programmer, 
http://www.ladyada.net/make/usbtinyisp/";;
   type  = usbtiny;
Index: usbasp.c
===================================================================
--- usbasp.c    (revision 1038)
+++ usbasp.c    (working copy)
@@ -262,45 +262,48 @@
                            "%s: Warning: cannot open USB device: %s\n",
                            progname, strerror(libusb_to_errno(r)));
                     continue;
-                }
-                if (vendorName == NULL && productName == NULL) {
-                   /* name does not matter */
-                    break;
-                }
-                /* now check whether the names match: */
-               r = libusb_get_string_descriptor_ascii(handle, 
descriptor.iManufacturer & 0xff, string, sizeof(string));
-                if (r < 0) {
+            }
+            errorCode = 0;
+            /* now check whether the names match: */
+            /* if vendorName not given ignore it (any vendor matches) */
+           r = libusb_get_string_descriptor_ascii(handle, 
descriptor.iManufacturer & 0xff, string, sizeof(string));
+            if (r < 0) {
+                if ((vendorName != NULL) && (vendorName[0] != 0)) {
                     errorCode = USB_ERROR_IO;
                     fprintf(stderr,
                            "%s: Warning: cannot query manufacturer for device: 
%s\n",
                            progname, strerror(libusb_to_errno(r)));
-                } else {
+               }
+            } else {
+               if (verbose > 1)
+                   fprintf(stderr,
+                           "%s: seen device from vendor ->%s<-\n",
+                           progname, string);
+                if ((vendorName != NULL) && (vendorName[0] != 0) && 
(strcmp(string, vendorName) != 0))
                     errorCode = USB_ERROR_NOTFOUND;
-                   if (verbose > 1)
-                       fprintf(stderr,
-                               "%s: seen device from vendor ->%s<-\n",
-                               progname, string);
-                    if (strcmp(string, vendorName) == 0){
-                       r = libusb_get_string_descriptor_ascii(handle, 
descriptor.iProduct & 0xff, string, sizeof(string));
-                        if (r < 0) {
-                            errorCode = USB_ERROR_IO;
-                            fprintf(stderr,
-                                   "%s: Warning: cannot query product for 
device: %s\n",
-                                   progname, strerror(libusb_to_errno(r)));
-                        } else {
-                            errorCode = USB_ERROR_NOTFOUND;
-                           if (verbose > 1)
-                               fprintf(stderr,
-                                       "%s: seen product ->%s<-\n",
-                                       progname, string);
-                            if(strcmp(string, productName) == 0)
-                                break;
-                        }
-                    }
-                }
-                libusb_close(handle);
-                handle = NULL;
             }
+            /* if productName not given ignore it (any product matches) */
+           r = libusb_get_string_descriptor_ascii(handle, descriptor.iProduct 
& 0xff, string, sizeof(string));
+            if (r < 0) {
+                if ((productName != NULL) && (productName[0] != 0)) {
+                    errorCode = USB_ERROR_IO;
+                    fprintf(stderr,
+                           "%s: Warning: cannot query product for device: 
%s\n",
+                           progname, strerror(libusb_to_errno(r)));
+               }
+            } else {
+               if (verbose > 1)
+                   fprintf(stderr,
+                           "%s: seen product ->%s<-\n",
+                           progname, string);
+                if((productName != NULL) && (productName[0] != 0) && 
(strcmp(string, productName) != 0))
+                    errorCode = USB_ERROR_NOTFOUND;
+            }
+            if (errorCode == 0)
+                break;
+            libusb_close(handle);
+            handle = NULL;
+        }
     }
     if (handle != NULL){
         errorCode = 0;
@@ -339,43 +342,46 @@
                            progname, usb_strerror());
                     continue;
                 }
-                if(vendorName == NULL && productName == NULL){
-                   /* name does not matter */
-                    break;
-                }
+                errorCode = 0;
                 /* now check whether the names match: */
+                /* if vendorName not given ignore it (any vendor matches) */
                 len = usb_get_string_simple(handle, 
dev->descriptor.iManufacturer,
                                            string, sizeof(string));
                 if(len < 0){
+                    if ((vendorName != NULL) && (vendorName[0] != 0)) {
                     errorCode = USB_ERROR_IO;
                     fprintf(stderr,
                            "%s: Warning: cannot query manufacturer for device: 
%s\n",
                            progname, usb_strerror());
-                }else{
-                    errorCode = USB_ERROR_NOTFOUND;
+                   }
+                } else {
                    if (verbose > 1)
                        fprintf(stderr,
                                "%s: seen device from vendor ->%s<-\n",
                                progname, string);
-                    if(strcmp(string, vendorName) == 0){
-                        len = usb_get_string_simple(handle, 
dev->descriptor.iProduct,
-                                                   string, sizeof(string));
-                        if(len < 0){
-                            errorCode = USB_ERROR_IO;
-                            fprintf(stderr,
-                                   "%s: Warning: cannot query product for 
device: %s\n",
-                                   progname, usb_strerror());
-                        }else{
-                            errorCode = USB_ERROR_NOTFOUND;
-                           if (verbose > 1)
-                               fprintf(stderr,
-                                       "%s: seen product ->%s<-\n",
-                                       progname, string);
-                            if(strcmp(string, productName) == 0)
-                                break;
-                        }
-                    }
+                    if((vendorName != NULL) && (vendorName[0] != 0) && 
(strcmp(string, vendorName) != 0))
+                        errorCode = USB_ERROR_NOTFOUND;
                 }
+                /* if productName not given ignore it (any product matches) */
+                len = usb_get_string_simple(handle, dev->descriptor.iProduct,
+                                           string, sizeof(string));
+                if(len < 0){
+                    if ((productName != NULL) && (productName[0] != 0)) {
+                        errorCode = USB_ERROR_IO;
+                        fprintf(stderr,
+                               "%s: Warning: cannot query product for device: 
%s\n",
+                               progname, usb_strerror());
+                   }
+                } else {
+                   if (verbose > 1)
+                       fprintf(stderr,
+                               "%s: seen product ->%s<-\n",
+                               progname, string);
+                    if((productName != NULL) && (productName[0] != 0) && 
(strcmp(string, productName) != 0))
+                        errorCode = USB_ERROR_NOTFOUND;
+                }
+                if (errorCode == 0)
+                    break;
                 usb_close(handle);
                 handle = NULL;
             }
@@ -400,38 +406,51 @@
 #else
   usb_init();
 #endif
-  if(strcasecmp(port, "nibobee") == 0) {
-    if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_NIBOBEE_VID, 
"www.nicai-systems.com",
-                   USBASP_NIBOBEE_PID, "NIBObee") != 0) {
-      fprintf(stderr,
-             "%s: error: could not find USB device "
-             "\"NIBObee\" with vid=0x%x pid=0x%x\n",
-             progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
-      return -1;
-      
+  if (usbOpenDevice(&PDATA(pgm)->usbhandle, pgm->usbvid, pgm->usbvendor,
+                 pgm->usbpid, pgm->usbproduct) != 0) {
+    /* try alternatives */
+    if(strcasecmp(ldata(lfirst(pgm->id)), "usbasp") == 0) {
+    /* for id usbasp autodetect some variants */
+      if(strcasecmp(port, "nibobee") == 0) {
+        fprintf(stderr,
+               "%s: warning: Using \"-C usbasp -P nibobee\" is deprecated,"
+               "use \"-C nibobee\" instead.\n",
+               progname);
+        if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_NIBOBEE_VID, 
"www.nicai-systems.com",
+                       USBASP_NIBOBEE_PID, "NIBObee") != 0) {
+          fprintf(stderr,
+                 "%s: error: could not find USB device "
+                 "\"NIBObee\" with vid=0x%x pid=0x%x\n",
+                 progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID);
+          return -1;
+        }
+        return 0;
+      }
+      /* check if device with old VID/PID is available */
+      if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_OLD_VID, 
"www.fischl.de",
+                            USBASP_OLD_PID, "USBasp") == 0) {
+        /* found USBasp with old IDs */
+        fprintf(stderr,
+               "%s: Warning: Found USB device \"USBasp\" with "
+               "old VID/PID! Please update firmware of USBasp!\n",
+               progname);
+       return 0;
+      }
+    /* original USBasp is specified in config file, so no need to check it 
again here */
+    /* no alternative found => fall through to generic error message */
     }
-  } else if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_SHARED_VID, 
"www.fischl.de",
-                   USBASP_SHARED_PID, "USBasp") != 0) {
 
-    /* check if device with old VID/PID is available */
-    if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_OLD_VID, "www.fischl.de",
-                     USBASP_OLD_PID, "USBasp") != 0) {
-
-      /* no USBasp found */
-      fprintf(stderr,
-             "%s: error: could not find USB device "
-             "\"USBasp\" with vid=0x%x pid=0x%x\n",
-             progname, USBASP_SHARED_VID, USBASP_SHARED_PID);
-      return -1;
-
-    } else {
-
-      /* found USBasp with old IDs */
-      fprintf(stderr,
-             "%s: Warning: Found USB device \"USBasp\" with "
-             "old VID/PID! Please update firmware of USBasp!\n",
-             progname);
+    fprintf(stderr,
+            "%s: error: could not find USB device with vid=0x%x pid=0x%x",
+            progname, pgm->usbvid, pgm->usbpid);
+    if (pgm->usbvendor[0] != 0) {
+       fprintf(stderr, " vendor='%s'", pgm->usbvendor);
     }
+    if (pgm->usbproduct[0] != 0) {
+       fprintf(stderr, " product='%s'", pgm->usbproduct);
+    }
+    fprintf(stderr,"\n");
+    return -1;
   }
 
   return 0;
_______________________________________________
avrdude-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avrdude-dev

Reply via email to