libftdi-git Archives

Subject: A library to talk to FTDI chips branch, master, updated. v1.5-11-gaf6971c

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sun, 2 May 2021 09:32:51 +0200 (CEST)
The branch, master has been updated
       via  af6971c184e7d31c304adf139fd836bb3ddeb8e6 (commit)
       via  31865800dffc58f2db3ae06a7bbba61bb279b265 (commit)
       via  231d8d35405dd0423db6cb1950ae77df9f742aa6 (commit)
       via  9d638dab09426be6349d41a269281921febcfa34 (commit)
       via  1050ad206d3ff01e5b5bac08a44b25ed0d9b5488 (commit)
       via  cb9b8a53f1536640fe4d8dfccf79268fbbd49180 (commit)
      from  45ebed3754aa2814583f4d433155f87f24f5351f (commit)


- Log -----------------------------------------------------------------
commit af6971c184e7d31c304adf139fd836bb3ddeb8e6
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Sun May 2 09:32:02 2021 +0200

    Add Tomasz Wasilczyk <twasilczyk@xxxxxxxxxx> to AUTHORS

commit 31865800dffc58f2db3ae06a7bbba61bb279b265
Author: Tomasz Wasilczyk <twasilczyk@xxxxxxxxxx>
Date:   Wed Apr 21 12:43:34 2021 -0700

    Don't set EEPROM serial when it's not used.
    
    This makes a difference in USB enumeration -- if serial is missing,
    its string is not present in string descriptor list.

commit 231d8d35405dd0423db6cb1950ae77df9f742aa6
Author: Tomasz Wasilczyk <twasilczyk@xxxxxxxxxx>
Date:   Wed Apr 21 12:42:08 2021 -0700

    Remove legacy EEPROM fields from FT4232H.
    
    These are not present when flashed with FT_Prog tool.

commit 9d638dab09426be6349d41a269281921febcfa34
Author: Tomasz Wasilczyk <twasilczyk@xxxxxxxxxx>
Date:   Wed Apr 21 12:39:52 2021 -0700

    Don't fail reading missing strings.
    
    This happens i.e. when serial number is not set -- in such case the
    string is missing from string descriptor list.

commit 1050ad206d3ff01e5b5bac08a44b25ed0d9b5488
Author: Tomasz Wasilczyk <tomkiewi@xxxxxxxxx>
Date:   Thu Mar 11 15:47:06 2021 -0800

    ftdi_eeprom_initdefaults const arguments
    
    This function don't need to modify its arguments.

commit cb9b8a53f1536640fe4d8dfccf79268fbbd49180
Author: Tomasz Wasilczyk <tomkiewi@xxxxxxxxx>
Date:   Thu Mar 11 15:43:12 2021 -0800

    Don't spam stderr when flashing FT232H eeprom

-----------------------------------------------------------------------

Summary of changes:
 AUTHORS    |    1 +
 src/ftdi.c |   58 ++++++++++++++++++++++++++++++++++++----------------------
 src/ftdi.h |    4 ++--
 3 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index e8f5a69..bd31f0a 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -83,6 +83,7 @@ see Changelog for full details:
   Thomas Klose <thomas.klose@xxxxxxxxxxxxx>
   Tim Ansell <mithro@xxxxxxxxxx>
   Tom Saunders <trsaunders@xxxxxxxxx>
+  Tomasz Wasilczyk <twasilczyk@xxxxxxxxxx>
   Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
   Vladimir Yakovlev <nagos@xxxxxxxx>
   Wilfried Holzke <libftdi@xxxxxxxxxx>
diff --git a/src/ftdi.c b/src/ftdi.c
index 03d7b07..92c5fae 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -485,27 +485,39 @@ int ftdi_usb_get_strings2(struct ftdi_context *ftdi, 
struct libusb_device *dev,
     if (libusb_get_device_descriptor(dev, &desc) < 0)
         ftdi_error_return(-11, "libusb_get_device_descriptor() failed");
 
-    if (manufacturer != NULL)
+    if (manufacturer != NULL && mnf_len > 0)
     {
-        if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, 
desc.iManufacturer, (unsigned char *)manufacturer, mnf_len) < 0)
+        if (desc.iManufacturer == 0)
+        {
+            manufacturer[0] = '\0';
+        }
+        else if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, 
desc.iManufacturer, (unsigned char *)manufacturer, mnf_len) < 0)
         {
             ftdi_usb_close_internal (ftdi);
             ftdi_error_return(-7, "libusb_get_string_descriptor_ascii() 
failed");
         }
     }
 
-    if (description != NULL)
+    if (description != NULL && desc_len > 0)
     {
-        if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, desc.iProduct, 
(unsigned char *)description, desc_len) < 0)
+        if (desc.iProduct == 0)
+        {
+            description[0] = '\0';
+        }
+        else if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, 
desc.iProduct, (unsigned char *)description, desc_len) < 0)
         {
             ftdi_usb_close_internal (ftdi);
             ftdi_error_return(-8, "libusb_get_string_descriptor_ascii() 
failed");
         }
     }
 
-    if (serial != NULL)
+    if (serial != NULL && serial_len > 0)
     {
-        if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, 
desc.iSerialNumber, (unsigned char *)serial, serial_len) < 0)
+        if (desc.iSerialNumber == 0)
+        {
+            serial[0] = '\0';
+        }
+        else if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, 
desc.iSerialNumber, (unsigned char *)serial, serial_len) < 0)
         {
             ftdi_usb_close_internal (ftdi);
             ftdi_error_return(-9, "libusb_get_string_descriptor_ascii() 
failed");
@@ -2576,8 +2588,8 @@ int ftdi_set_error_char(struct ftdi_context *ftdi,
     \retval -2: No struct ftdi_eeprom
     \retval -3: No connected device or device not yet opened
 */
-int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer,
-                             char * product, char * serial)
+int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, const char * 
manufacturer,
+                             const char * product, const char * serial)
 {
     struct ftdi_eeprom *eeprom;
 
@@ -2594,7 +2606,7 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, 
char * manufacturer,
         ftdi_error_return(-3, "No connected device or device not yet opened");
 
     eeprom->vendor_id = 0x0403;
-    eeprom->use_serial = 1;
+    eeprom->use_serial = (serial != NULL);
     if ((ftdi->type == TYPE_AM) || (ftdi->type == TYPE_BM) ||
             (ftdi->type == TYPE_R))
         eeprom->product_id = 0x6001;
@@ -3089,19 +3101,23 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
     }
     output[0x11] = product_size*2 + 2;
 
-    // Addr 12: Offset of the serial string + 0x80, calculated later
-    // Addr 13: Length of serial string
-    output[0x12] = i | 0x80; // calculate offset
-    output[i & eeprom_size_mask] = serial_size*2 + 2, i++;
-    output[i & eeprom_size_mask] = 0x03, i++;
-    for (j = 0; j < serial_size; j++)
-    {
-        output[i & eeprom_size_mask] = eeprom->serial[j], i++;
-        output[i & eeprom_size_mask] = 0x00, i++;
+    if (eeprom->use_serial) {
+        // Addr 12: Offset of the serial string + 0x80, calculated later
+         // Addr 13: Length of serial string
+         output[0x12] = i | 0x80; // calculate offset
+         output[i & eeprom_size_mask] = serial_size*2 + 2, i++;
+         output[i & eeprom_size_mask] = 0x03, i++;
+         for (j = 0; j < serial_size; j++)
+         {
+             output[i & eeprom_size_mask] = eeprom->serial[j], i++;
+             output[i & eeprom_size_mask] = 0x00, i++;
+         }
+         output[0x13] = serial_size*2 + 2;
     }
 
     // Legacy port name and PnP fields for FT2232 and newer chips
-    if (ftdi->type > TYPE_BM)
+    // It doesn't appear when written with FT_Prog for FT4232H chip.
+    if (ftdi->type > TYPE_BM && ftdi->type != TYPE_4232H)
     {
         output[i & eeprom_size_mask] = 0x02; /* as seen when written with 
FTD2XX */
         i++;
@@ -3111,8 +3127,6 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
         i++;
     }
 
-    output[0x13] = serial_size*2 + 2;
-
     if (ftdi->type > TYPE_AM) /* use_serial not used in AM devices */
     {
         if (eeprom->use_serial)
@@ -3421,7 +3435,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
             set_ft232h_cbus(eeprom, output);
 
             output[0x1e] = eeprom->chip;
-            fprintf(stderr,"FIXME: Build FT232H specific EEPROM settings\n");
+            /* FIXME: Build FT232H specific EEPROM settings */
             break;
         case TYPE_230X:
             output[0x00] = 0x80; /* Actually, leave the default value */
diff --git a/src/ftdi.h b/src/ftdi.h
index fb45008..0603335 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -609,8 +609,8 @@ extern "C"
 
     /* init eeprom for the given FTDI type */
     int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi,
-                                 char * manufacturer, char *product,
-                                 char * serial);
+                                 const char * manufacturer, const char 
*product,
+                                 const char * serial);
     int ftdi_eeprom_build(struct ftdi_context *ftdi);
     int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose);
 


hooks/post-receive
-- 
A library to talk to FTDI chips

--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • A library to talk to FTDI chips branch, master, updated. v1.5-11-gaf6971c, libftdi-git <=