FreeCalypso > hg > fc-usbser-tools
changeset 66:85256d5aa559
ftee-fix-cksum program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 12 Sep 2023 23:19:05 +0000 |
parents | 225dc1d9f2f1 |
children | 742c41f44658 |
files | .hgignore fteeprom/Makefile fteeprom/ftee-fix-cksum.c |
diffstat | 3 files changed, 82 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue Sep 12 22:23:30 2023 +0000 +++ b/.hgignore Tue Sep 12 23:19:05 2023 +0000 @@ -11,6 +11,7 @@ ^duart28/fc-duart28-conf$ ^fteeprom/ftee-decode$ +^fteeprom/ftee-fix-cksum$ ^fteeprom/ftee-gen2232c$ ^fteeprom/ftee-gen2232h$ ^fteeprom/ftee-gen232r$
--- a/fteeprom/Makefile Tue Sep 12 22:23:30 2023 +0000 +++ b/fteeprom/Makefile Tue Sep 12 23:19:05 2023 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -PROGS= ftee-decode ftee-gen2232c ftee-gen2232h ftee-gen232r ftee-mkblank \ - fteeprom-erase fteeprom-prog fteeprom-read +PROGS= ftee-decode ftee-fix-cksum ftee-gen2232c ftee-gen2232h ftee-gen232r \ + ftee-mkblank fteeprom-erase fteeprom-prog fteeprom-read LIBS= ../libftmini/libftmini.a ../libuwrap/libuwrap.a INSTALL_PREFIX= /opt/freecalypso @@ -13,6 +13,9 @@ ftee-decode: ftee-decode.o read_eeprom_image.o ${CC} ${CFLAGS} -o $@ $@.o read_eeprom_image.o +ftee-fix-cksum: ftee-fix-cksum.o read_eeprom_image.o + ${CC} ${CFLAGS} -o $@ $@.o read_eeprom_image.o + ftee-gen2232c: ftee-gen2232c.o filesearch.o ${CC} ${CFLAGS} -o $@ $@.o filesearch.o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fteeprom/ftee-fix-cksum.c Tue Sep 12 23:19:05 2023 +0000 @@ -0,0 +1,76 @@ +/* + * 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); +}