changeset 7:b2c891299e83

ftee-gen*: look for EEPROM config file in /opt/freecalypso/ftdi
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 04 Sep 2023 20:37:52 +0000
parents d4151cef9d95
children 1415508e7ea2
files fteeprom/Makefile fteeprom/filesearch.c fteeprom/ftee-gen2232c.c fteeprom/ftee-gen2232h.c fteeprom/ftee-gen232r.c
diffstat 5 files changed, 43 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/fteeprom/Makefile	Mon Sep 04 06:38:29 2023 +0000
+++ b/fteeprom/Makefile	Mon Sep 04 20:37:52 2023 +0000
@@ -9,14 +9,14 @@
 
 all:	${PROGS}
 
-ftee-gen2232c:	ftee-gen2232c.c
-	${CC} ${CFLAGS} -o $@ $@.c
+ftee-gen2232c:	ftee-gen2232c.o filesearch.o
+	${CC} ${CFLAGS} -o $@ $@.o filesearch.o
 
-ftee-gen2232h:	ftee-gen2232h.c
-	${CC} ${CFLAGS} -o $@ $@.c
+ftee-gen2232h:	ftee-gen2232h.o filesearch.o
+	${CC} ${CFLAGS} -o $@ $@.o filesearch.o
 
-ftee-gen232r:	ftee-gen232r.c
-	${CC} ${CFLAGS} -o $@ $@.c
+ftee-gen232r:	ftee-gen232r.o filesearch.o
+	${CC} ${CFLAGS} -o $@ $@.o filesearch.o
 
 ftee-mkblank:	ftee-mkblank.c
 	${CC} ${CFLAGS} -o $@ $@.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fteeprom/filesearch.c	Mon Sep 04 20:37:52 2023 +0000
@@ -0,0 +1,28 @@
+/*
+ * This module implements the function that searches for FTDI EEPROM config
+ * files in a dedicated installation directory.  It is based on the version
+ * in fc-sim-tools that looks in the sim-scripts directory.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+static char ftdi_install_dir[] = "/opt/freecalypso/ftdi";
+
+FILE *
+open_eeprom_config_file(req_filename)
+	char *req_filename;
+{
+	char pathbuf[256];
+	FILE *f;
+
+	if (!index(req_filename, '/') && strlen(req_filename) < 128) {
+		sprintf(pathbuf, "%s/%s", ftdi_install_dir, req_filename);
+		f = fopen(pathbuf, "r");
+		if (f)
+			return f;
+	}
+	f = fopen(req_filename, "r");
+	return f;
+}
--- a/fteeprom/ftee-gen2232c.c	Mon Sep 04 06:38:29 2023 +0000
+++ b/fteeprom/ftee-gen2232c.c	Mon Sep 04 20:37:52 2023 +0000
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+extern FILE *open_eeprom_config_file();
+
 char *configfile, *serial;
 
 u_short vid = 0x0403, pid = 0x6010;
@@ -66,7 +68,7 @@
 	int lineno;
 	char *cp, *np;
 
-	inf = fopen(configfile, "r");
+	inf = open_eeprom_config_file(configfile);
 	if (!inf) {
 		perror(configfile);
 		exit(1);
--- a/fteeprom/ftee-gen2232h.c	Mon Sep 04 06:38:29 2023 +0000
+++ b/fteeprom/ftee-gen2232h.c	Mon Sep 04 20:37:52 2023 +0000
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+extern FILE *open_eeprom_config_file();
+
 char *configfile, *serial;
 
 u_short vid = 0x0403, pid = 0x6010;
@@ -66,7 +68,7 @@
 	int lineno;
 	char *cp, *np;
 
-	inf = fopen(configfile, "r");
+	inf = open_eeprom_config_file(configfile);
 	if (!inf) {
 		perror(configfile);
 		exit(1);
--- a/fteeprom/ftee-gen232r.c	Mon Sep 04 06:38:29 2023 +0000
+++ b/fteeprom/ftee-gen232r.c	Mon Sep 04 20:37:52 2023 +0000
@@ -5,6 +5,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+extern FILE *open_eeprom_config_file();
+
 u_short vid = 0x0403, pid = 0x6001;
 char *manuf, *product;
 u_char byte00 = 0x00, byte01 = 0x40;
@@ -24,7 +26,7 @@
 	int lineno;
 	char *cp, *np;
 
-	inf = fopen(filename, "r");
+	inf = open_eeprom_config_file(filename);
 	if (!inf) {
 		perror(filename);
 		exit(1);