FreeCalypso > hg > fc-usbser-tools
comparison doc/FTDI-EEPROM-tools @ 35:f548ae912622
doc/FTDI-EEPROM-tools: update for 2023 sans-libftdi version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 10 Sep 2023 00:18:20 +0000 |
| parents | f5fbcf1ff032 |
| children | 9cfe3223fbf8 |
comparison
equal
deleted
inserted
replaced
| 34:f5fbcf1ff032 | 35:f548ae912622 |
|---|---|
| 37 * if the goal is to generate a new EEPROM config from scratch, as opposed to | 37 * if the goal is to generate a new EEPROM config from scratch, as opposed to |
| 38 restoring a saved backup, we currently have generators only for FT2232C/D, | 38 restoring a saved backup, we currently have generators only for FT2232C/D, |
| 39 for FT2232H and for FT232R, with the last one considered experimental and not | 39 for FT2232H and for FT232R, with the last one considered experimental and not |
| 40 proven. | 40 proven. |
| 41 | 41 |
| 42 libftdi dependency | 42 No more libftdi dependency! |
| 43 ================== | 43 =========================== |
| 44 | 44 |
| 45 We use libftdi (which is in turn layered on libusb) to issue the special USB | 45 Our initial implementation of fteeprom-* tools was based on libftdi; more |
| 46 control pipe commands to FTDI chips which are needed to read and write their | 46 specifically, one had to use an old libftdi-0.x version, as these old versions |
| 47 EEPROMs. We use old-style libftdi-0.x (-lftdi on the link line) as opposed to | 47 were the only ones that allowed writing to the EEPROM directly with |
| 48 libftdi1 (-lftdi1) because the new versions took away the ability to write to | 48 ftdi_write_eeprom_location() API calls. However, the present version has been |
| 49 the EEPROM directly with ftdi_write_eeprom_location() calls, forcing users to | 49 reimplemented to NOT use libftdi at all - instead we have our own minilibs, |
| 50 go through libftdi1's own EEPROM smarts, which we don't want to do - our tools | 50 maintained as part of fc-usbser-tools package, that are built on top of |
| 51 are all about more direct user empowerment at the lowest level. | 51 libusb-0.x API. (The version of libftdi we used previously was also built on |
| 52 top of the same libusb-0.x API, hence no change in that dependency.) The | |
| 53 libusb-0.x API we use consists of <usb.h> include header and -lusb link library | |
| 54 pull-in; on "modern" systems these pieces will typically be provided by | |
| 55 libusb-compat-0.1 package wrapping around libusb-1.x, but in the spirit of Holy | |
| 56 retrocomputing, really old systems can be used with native libusb-0.1. | |
| 52 | 57 |
| 53 Selecting the device to operate on | 58 Selecting the device to operate on |
| 54 ================================== | 59 ================================== |
| 55 | 60 |
| 56 Our fteeprom-read, fteeprom-prog and fteeprom-erase tools take a device selector | 61 Our fteeprom-read, fteeprom-prog and fteeprom-erase tools take a device selector |
| 57 argument, selecting the device to operate on. This required argument is the | 62 argument, selecting the device to operate on. The design of this device |
| 58 string to be passed to the ftdi_usb_open_string() function in libftdi, allowing | 63 selector mechanism has been copied from libftdi; while we no longer use libftdi, |
| 59 the device to be operated on to be selected in one of several ways. Copying | 64 we found its device selector mechanism to be a really good design and we have |
| 60 from libftdi documentation, the available formats are: | 65 fully reimplemented it. The device selector argument is a string in one of the |
| 61 | 66 following formats (some wording copied from libftdi documentation): |
| 62 d:<devicenode> - path of bus and device-node (e.g. "003/001") within usb device | 67 |
| 63 tree (usually at /proc/bus/usb/) | 68 d:<devicenode> - path of bus and device-node (e.g. "003/001") within USB device |
| 69 tree as enumerated via libusb-0.x API. Libftdi documentation said | |
| 70 /proc/bus/usb, but at least on Mother's Slackware 14.2 system, the observed | |
| 71 location of this device tree is /dev/bus/usb. | |
| 64 | 72 |
| 65 i:<vendor>:<product> - first device with given vendor and product id, ids can | 73 i:<vendor>:<product> - first device with given vendor and product id, ids can |
| 66 be decimal, octal (preceded by "0") or hex (preceded by "0x") | 74 be decimal, octal (preceded by "0") or hex (preceded by "0x") |
| 67 | 75 |
| 68 i:<vendor>:<product>:<index> - as above with index being the number of the | 76 i:<vendor>:<product>:<index> - as above with index being the number of the |
| 110 | 118 |
| 111 The output of fteeprom-read is in the same format as the input to fteeprom-prog, | 119 The output of fteeprom-read is in the same format as the input to fteeprom-prog, |
| 112 thus you can redirect the output to a file and get a restorable backup copy of | 120 thus you can redirect the output to a file and get a restorable backup copy of |
| 113 your EEPROM. | 121 your EEPROM. |
| 114 | 122 |
| 115 It also needs to be noted that if the FTDI device has the kernel's ftdi_sio | 123 Change from previous version |
| 116 driver attached to it (ttyUSB device present) when you run fteeprom-read (same | 124 ---------------------------- |
| 117 for fteeprom-prog and fteeprom-erase), the act of running any of our EEPROM | 125 |
| 118 tools will cause it to unbind, i.e., the ttyUSB device will disappear. If the | 126 In the original libftdi-based implementation of fteeprom-read, the act of |
| 119 device being operated on is a dual-channel FT2232x, then only the ttyUSB device | 127 reading the EEPROM was invasive: libftdi's open function would unbind the |
| 120 corresponding to Channel A will disappear, while the Channel B ttyUSB device | 128 kernel's ftdi_sio driver (Channel A ttyUSB device disappears) and |
| 121 will stay. | 129 reset/reinitialize the SIO channel itself. However, it turns out that these |
| 130 invasive steps aren't needed if the goal is only to read the EEPROM - the | |
| 131 necessary USB control endpoint transactions can be done while the kernel's | |
| 132 ftdi_sio driver remains attached with ttyUSBx devices intact on all channels. | |
| 133 The current version of fteeprom-read has been fixed to be non-invasive in this | |
| 134 regard: you can now freely read the EEPROM of any connected FTDI device | |
| 135 *without* bumping off that device's ttyUSB. | |
| 122 | 136 |
| 123 Programming the EEPROM | 137 Programming the EEPROM |
| 124 ====================== | 138 ====================== |
| 125 | 139 |
| 126 In terms of the primitives provided over USB, writing to EEPROMs sitting behind | 140 In terms of the primitives provided over USB, writing to EEPROMs sitting behind |
| 210 what does one need a bigger EEPROM for... | 224 what does one need a bigger EEPROM for... |
| 211 | 225 |
| 212 For the format of config files read by our ftee-gen2232[ch] tools and what | 226 For the format of config files read by our ftee-gen2232[ch] tools and what |
| 213 settings can be tweaked, read the source code. | 227 settings can be tweaked, read the source code. |
| 214 | 228 |
| 229 Installation directory for EEPROM config files | |
| 230 ---------------------------------------------- | |
| 231 | |
| 232 If the name of the config file passed to ftee-gen* does not contain any '/' | |
| 233 characters, the named file is sought first in an installation directory | |
| 234 (/opt/freecalypso/ftdi) and then in the current directory. To suppress this | |
| 235 search path and read EEPROM config files only from the current directory, | |
| 236 specify your config file as ./name - filenames (pathnames) containing slashes | |
| 237 are read as-is. | |
| 238 | |
| 239 This installation directory and search mechanism have been added in order to | |
| 240 allow standard (usually developed at FreeCalypso HQ) FTDI EEPROM configs which | |
| 241 end users can then program into their boards by executing a fixed command line | |
| 242 given in a manual. | |
| 243 | |
| 244 FT232R differences | |
| 245 ================== | |
| 246 | |
| 247 The EEPROM generator tool for FT232R is ftee-gen232r; it works on the same | |
| 248 principle as ftee-gen2232[ch] for FT2232x. However, when you run fteeprom-prog | |
| 249 to program FT232R's internal EEPROM (whether you are restoring a backup or | |
| 250 programming the output of ftee-gen232r), you need to add -r option before the | |
| 251 device selector string. This option tells fteeprom-prog to execute the | |
| 252 FT232R-specific magic sequence (documented in FT232R-notes) before proceeding | |
| 253 to actual EEPROM writes - without this option the EEPROM content will be garbage | |
| 254 (bitwise AND of old and new EEPROM images), producing the appearance of a | |
| 255 bricked chip. | |
| 256 | |
| 257 In the previous libftdi-based version of fteeprom-prog the magic sequence in | |
| 258 question was executed unconditionally - however, because it is needed only for | |
| 259 FT232R and because we could simplify our new sans-libftdi code by implementing | |
| 260 it in an FT232R-only manner (no support for different "index" values for | |
| 261 multichannel FTDI devices), we've changed it from unconditional to -r option. | |
| 262 | |
| 263 Experiments show that fteeprom-prog -r option appears to be harmless (though | |
| 264 unnecessary) on FT2232D and FT2232H - however, Mother's recommendation is to | |
| 265 use it only on FT232R devices. | |
| 266 | |
| 215 Erasing the EEPROM (making it blank) | 267 Erasing the EEPROM (making it blank) |
| 216 ==================================== | 268 ==================================== |
| 217 | 269 |
| 218 If you are playing with a "generic" FT2232x breakout board that is made for | 270 If you are playing with a "generic" FT2232x breakout board that is made for |
| 219 tinkering, as opposed to a more finished product, such boards are typically | 271 tinkering, as opposed to a more finished product, such boards are typically |
| 239 pipelines: | 291 pipelines: |
| 240 | 292 |
| 241 ftee-mkblank | fteeprom-prog <device-selector> -- blank a 93C46 EEPROM | 293 ftee-mkblank | fteeprom-prog <device-selector> -- blank a 93C46 EEPROM |
| 242 ftee-mkblank -b | fteeprom-prog <device-selector> -- blank a 93C56 EEPROM | 294 ftee-mkblank -b | fteeprom-prog <device-selector> -- blank a 93C56 EEPROM |
| 243 ftee-mkblank -B | fteeprom-prog <device-selector> -- blank a 93C66 EEPROM | 295 ftee-mkblank -B | fteeprom-prog <device-selector> -- blank a 93C66 EEPROM |
| 296 | |
| 297 USB replug after EEPROM programming or erasure | |
| 298 ============================================== | |
| 299 | |
| 300 Unlike fteeprom-read, our fteeprom-prog and fteeprom-erase utilities do command | |
| 301 the kernel's ftdi_sio driver to unbind. On single-channel devices the effect | |
| 302 is that the sole ttyUSB character device associated with the given USB device | |
| 303 disappears; on multichannel devices the effect is that ttyUSB corresponding to | |
| 304 Channel A disappears, while Channel B ttyUSB device remains. In order to bring | |
| 305 back the bumped-off ttyUSB device, and in order to make the FTDI chip itself | |
| 306 reread and apply the new EEPROM config, you have to physically unplug and replug | |
| 307 the USB device. | |
| 308 | |
| 309 Why is physical plug/unplug manipulation needed, why can't we command the needed | |
| 310 effect via software? As it turns out, there are no *valid* reasons why it can't | |
| 311 be done - but we are not currently able to do so because Linux kernel USB | |
| 312 maintainers are being pricks and won't support functionality that doesn't fit | |
| 313 into their worldview. Given that Harald Welte discovered this problem back in | |
| 314 2017: | |
| 315 | |
| 316 https://laforge.gnumonks.org/blog/20170524-usb-port-powercycle/ | |
| 317 https://marc.info/?l=linux-usb&m=149557709602259&w=2 | |
| 318 | |
| 319 (the thread shows Harald's good-faith attempt to reason with those pricks and | |
| 320 their dismissive responses) and given my own (Mother Mychaela's) sour experience | |
| 321 with trying to get a simple patch into ftdi_sio (adding support for a quirk- | |
| 322 requiring FT2232x-based hardware device), the situation with Linux currently | |
| 323 looks hopeless. |
