# HG changeset patch # User Mychaela Falconia # Date 1695687830 0 # Node ID d069e2a6760e3c7775bae4a05ca712b43a21f09c # Parent 201503e4be18cf9dde6cdaff61e48164adb18c7a ftee-gen2232h: add ftdi-chip and eeprom settings diff -r 201503e4be18 -r d069e2a6760e fteeprom/ftee-gen2232h.c --- a/fteeprom/ftee-gen2232h.c Mon Sep 25 23:23:32 2023 +0000 +++ b/fteeprom/ftee-gen2232h.c Tue Sep 26 00:23:50 2023 +0000 @@ -1,3 +1,8 @@ +/* + * This program constructs a configuration EEPROM image for an FT2232H chip + * based on a configuration source file giving various settings. + */ + #include #include #include @@ -18,22 +23,26 @@ u_char group0, group1, group2, group3; u_short eeprom[128]; -u_char eeprom_chip = 0x46; +u_char eeprom_chip = 0x46, eeprom_chip_cmdline; unsigned eeprom_size, eeprom_string_ptr; +static void process_cmdline(argc, argv) char **argv; { int c; extern int optind; - while ((c = getopt(argc, argv, "bB")) != EOF) { + while ((c = getopt(argc, argv, "bBs")) != EOF) { switch (c) { case 'b': - eeprom_chip = 0x56; + eeprom_chip = eeprom_chip_cmdline = 0x56; continue; case 'B': - eeprom_chip = 0x66; + eeprom_chip = eeprom_chip_cmdline = 0x66; + continue; + case 's': + eeprom_chip = eeprom_chip_cmdline = 0x46; continue; default: /* error msg already printed */ @@ -50,17 +59,43 @@ serial = argv[optind+1]; } -init_eeprom_size() +static void +ftdi_chip_setting(arg, filename_for_errs, lineno) + char *arg, *filename_for_errs; +{ + if (!strcasecmp(arg, "FT2232H")) + return; + if (!strcasecmp(arg, "FT2232x")) + return; + fprintf(stderr, "%s line %d: config is for wrong FTDI chip\n", + filename_for_errs, lineno); + exit(1); +} + +static void +eeprom_setting(arg, filename_for_errs, lineno) + char *arg, *filename_for_errs; { - if (eeprom_chip == 0x46) { - eeprom_size = 64; - eeprom_string_ptr = 0x0D; - } else { - eeprom_size = 128; - eeprom_string_ptr = 0x4D; + if (!strcasecmp(arg, "93C46")) + eeprom_chip = 0x46; + else if (!strcasecmp(arg, "93C56")) + eeprom_chip = 0x56; + else if (!strcasecmp(arg, "93C66")) + eeprom_chip = 0x66; + else { + fprintf(stderr, "%s line %d: invalid eeprom setting\n", + filename_for_errs, lineno); + exit(1); + } + if (eeprom_chip_cmdline && eeprom_chip_cmdline != eeprom_chip) { + fprintf(stderr, + "%s line %d: eeprom setting disagrees with command line option\n", + filename_for_errs, lineno); + exit(1); } } +static void read_config_file() { FILE *inf; @@ -124,6 +159,10 @@ group2 = strtoul(cp, 0, 16); else if (!strcmp(np, "group3")) group3 = strtoul(cp, 0, 16); + else if (!strcmp(np, "ftdi-chip")) + ftdi_chip_setting(cp, configfile, lineno); + else if (!strcmp(np, "eeprom")) + eeprom_setting(cp, configfile, lineno); else { fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", configfile, lineno, np); @@ -141,6 +180,19 @@ } } +static void +init_eeprom_size() +{ + if (eeprom_chip == 0x46) { + eeprom_size = 64; + eeprom_string_ptr = 0x0D; + } else { + eeprom_size = 128; + eeprom_string_ptr = 0x4D; + } +} + +static int write_string(str) char *str; { @@ -158,6 +210,7 @@ return (longlen << 8) | 0x80 | (startptr << 1); } +static void fill_eeprom() { u_char byte09; @@ -183,6 +236,7 @@ eeprom[12] = eeprom_chip; } +static void do_checksum() { u_short chksum = 0xAAAA; @@ -195,6 +249,7 @@ eeprom[n] = chksum; } +static void emit_output() { unsigned n, col;