Package: avrdude
Version: 6.3-20171130+svn1429-2+b1
Severity: important
Tags: patch upstream

Dear Maintainer,

I recently upgraded avrdude from debian version 6.3-5.  After upgrading I was
unable to use my default programmer, arduino-ft232r without setting a -P port
parameter on the command line.  Upstream patch 8580 modified ft245r.c to allow
selection of a particular ftdi device based on the serial number of the device.
Unfortunately this patch has broken the ability for avrdude to automatically
select the first ftdi port for ft245r devices, which include arduino-ft232r.

Furthermore, there is no way to specify the serial number in the .avrduderc
file which has effect with these ft245r devices.  All attempts to set
"default_serial" or "default_parallel" with the correct "usb:SERIAL_NUM" which
work with the -P parameter failed to get past the conditional at line 554 of
ft245r.c.  Attempts to create a custom programmer with a parent of
arduino-ft232r or ft245r which attempted different combinations of setting
"usbdev" and "usbsn" to the appropriate serial number failed to satisfy the
aforementioned conditional.

I consider the upstream patch 8580 as ill formed in that it breaks existing
configurations without providing a way to specify a device serial number in
.avrduderc via either the default_serial or through a custom programmer with
usbdev or usbsn specified.  I am not sure how to incorporate the previous
behavior which selected the first ftdi device and "just worked" in version
6.3-5 with the added functionality for allowing users with multiple ftdi
devices to select a particular one via serial number.

The upstream patch 8580 is also logically incorrect in that the "else if"
conditional on line 573 is unreachable.  Any port which does not satisfy the
sscanf conditional at line 554 will immediately shortcut to the error return at
line 558.  A correct patch must strncmp "port" with DEFAULT_USB for
strlen(DEFAULT_USB) and then check if "port" is longer than strlen(DEFAULT_USB) 
 and then it can perform the sscanf conditional at line 554.

The upstream patch is also broken for the parsing of ftX style ports in the
conditional at 573.  Comparing "device" with "ft" is not correct.  The correct
comparison is between "port" and "ft".

-- System Information:
Debian Release: 10.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, armel, arm64

Kernel: Linux 4.12.0-2-amd64 (SMP w/2 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8), 
LANGUAGE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages avrdude depends on:
ii  libc6              2.28-8
ii  libelf1            0.176-1
ii  libftdi1           0.20-4+b1
ii  libhidapi-libusb0  0.9.0+dfsg-1
ii  libncurses6        6.1+20181013-2
ii  libreadline8       8.0-3
ii  libtinfo6          6.1+20181013-2
ii  libusb-0.1-4       2:0.1.12-32

avrdude recommends no packages.

Versions of packages avrdude suggests:
pn  avrdude-doc     <none>
pn  dfu-programmer  <none>

-- no debconf information
--- ft245r.c.old        2019-01-01 15:31:09.000000000 -0500
+++ ft245r.c    2019-10-13 20:07:20.097474440 -0400
@@ -550,13 +550,18 @@
 
     strcpy(pgm->port, port);
 
+    if ((strcmp(port, DEFAULT_USB) == 0)) {
+      devnum = 0;
+      avrdude_message(MSG_INFO,
+          "%s: ft245r_open(): default device identifier '%s'\n",
+          progname, port);
     // read device string cut after 8 chars (max. length of serial number)
-    if ((sscanf(port, "usb:%8s", device) != 1)) {
+    } else if ((strncmp(port, DEFAULT_USB, strlen(DEFAULT_USB)) == 0) &&
+        (strcmp(port, DEFAULT_USB) > 0) &&
+        (sscanf(port, "usb:%8s", device) != 1)) {
       avrdude_message(MSG_INFO,
           "%s: ft245r_open(): invalid device identifier '%8s'\n",
-          progname, device);
-      return -1;
-    } else {
+          progname, device); return -1; } else {
       if (strlen(device) == 8 ){ // serial number
         if (verbose >= 2) {
           avrdude_message(MSG_INFO,
@@ -570,8 +575,8 @@
         // and use first device with matching serial (should be unique)
         devnum = 0;
       }
-      else if (strncmp("ft", device, 2) || strlen(device) <= 8)  { // classic 
device number
-        char *startptr = device + 2;
+      else if ((strncmp("ft", port, 2) == 0))  { // classic device number
+        char *startptr = port + 2;
         char *endptr = NULL;
         devnum = strtol(startptr,&endptr,10);
         if ((startptr==endptr) || (*endptr != '\0')) {
@@ -584,10 +589,9 @@
             devnum);
       }
     }
-
     // if something went wrong before abort with helpful message
     if (devnum < 0) {
-      avrdude_message(MSG_INFO, "%s: ft245r_open(): invalid portname '%s': 
use^ 'ft[0-9]+' or serial number\n",
+      avrdude_message(MSG_INFO, "%s: ft245r_open(): invalid portname '%s': 
use^ default 'usb', 'ft[0-9]+' or 'usb:XXXXXXXX' substituting the serial 
number\n",
           progname,port);
       return -1;
     }

Reply via email to