FreeCalypso > hg > fc-usbser-tools
view fteeprom/ftee-fix-cksum.c @ 68:5cbde3c80c24
fteeprom-{erase,prog}: detach logic: change to detach by default
As it turns out, detaching all ttyUSB interfaces of a multichannel device
does not require outside knowledge of how many channels there are, as in
our previous -d option design that is being removed here - instead we can
read the bNumInterfaces constant from the USB device's config descriptor
and thus know how many interfaces there are in total. Based on this
discovery, change the design of fteeprom-{erase,prog} as follows:
* remove -d option;
* flip the default to where we detach all interfaces by default;
* add -n option to NOT detach any interfaces.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 13 Sep 2023 06:37:03 +0000 |
parents | 85256d5aa559 |
children |
line wrap: on
line source
/* * Sometimes it is useful to be able to edit FTDI EEPROM hex images * by hand, for special situations and experiments that are too unique * to automate. However, the need for passing checksum gets in the way. * This program reads an FTDI EEPROM image from a file (or from stdin), * recomputes a new checksum and re-emits the checksum-fixed EEPROM hex * image on stdout. */ #include <sys/types.h> #include <string.h> #include <strings.h> #include <stdio.h> #include <stdlib.h> extern unsigned eeprom_size; extern u_short eeprom[256]; static unsigned chksum_size; static void do_checksum() { u_short chksum = 0xAAAA; unsigned n; for (n = 0; n < chksum_size - 1; n++) { chksum ^= eeprom[n]; chksum = (chksum << 1) | (chksum >> 15); } eeprom[n] = chksum; } static void emit_output() { unsigned n, col; for (n = 0; n < eeprom_size; n++) { col = n & 7; if (col == 0) printf("%02X:", n * 2); printf(" %04X", eeprom[n]); if (col == 7) putchar('\n'); } } main(argc, argv) char **argv; { if (argc != 2) { fprintf(stderr, "usage: %s eeprom-image-file\n", argv[0]); exit(1); } if (strcmp(argv[1], "-")) read_eeprom_from_file(argv[1]); else read_eeprom_from_stdin(); switch (eeprom_size) { case 64: chksum_size = 64; break; case 128: case 256: chksum_size = 128; break; default: fprintf(stderr, "BUG: invalid EEPROM size not caught earlier\n"); exit(1); } do_checksum(); emit_output(); exit(0); }