# HG changeset patch # User Mychaela Falconia # Date 1695878739 0 # Node ID c59011177e2e8582405755a4767fe50d6e076c75 # Parent 1cacc1ae56f03a915f233b1320df3de69ffef459 cp2102-update-eeprom program written, compiles diff -r 1cacc1ae56f0 -r c59011177e2e .hgignore --- a/.hgignore Thu Sep 28 04:45:13 2023 +0000 +++ b/.hgignore Thu Sep 28 05:25:39 2023 +0000 @@ -8,6 +8,7 @@ ^cp2102/cp2102-read-baudtab$ ^cp2102/cp2102-read-eeprom$ ^cp2102/cp2102-read-partno$ +^cp2102/cp2102-update-eeprom$ ^cp2102/cp2102-write-eeprom$ ^cp2102/file_rw_test$ diff -r 1cacc1ae56f0 -r c59011177e2e cp2102/Makefile --- a/cp2102/Makefile Thu Sep 28 04:45:13 2023 +0000 +++ b/cp2102/Makefile Thu Sep 28 05:25:39 2023 +0000 @@ -2,7 +2,7 @@ CFLAGS= -O2 PROGS= cp2102-decode-baudtab cp2102-decode-ee-desc cp2102-patch-ee-image \ cp2102-read-baudtab cp2102-read-eeprom cp2102-read-partno \ - cp2102-write-eeprom + cp2102-update-eeprom cp2102-write-eeprom NOINST= file_rw_test LIBS= ../libuwrap/libuwrap.a @@ -22,6 +22,8 @@ read_eeprom_main.o READ_PARTNO_OBJS= find_dev.o read_partno.o RW_TEST_OBJS= intel_hex_in.o intel_hex_out.o file_rw_test.o +UPDATE_EEPROM_OBJS= apply_eeprom_patch.o find_dev.o read_eeprom.o \ + update_eeprom.o write_eeprom.o WRITE_EEPROM_OBJS= find_dev.o intel_hex_in.o write_eeprom.o \ write_eeprom_main.o @@ -45,6 +47,9 @@ cp2102-read-partno: ${READ_PARTNO_OBJS} ${LIBS} ${CC} ${CFLAGS} -o $@ ${READ_PARTNO_OBJS} ${LIBS} -lusb +cp2102-update-eeprom: ${UPDATE_EEPROM_OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${UPDATE_EEPROM_OBJS} ${LIBS} -lusb + cp2102-write-eeprom: ${WRITE_EEPROM_OBJS} ${LIBS} ${CC} ${CFLAGS} -o $@ ${WRITE_EEPROM_OBJS} ${LIBS} -lusb diff -r 1cacc1ae56f0 -r c59011177e2e cp2102/update_eeprom.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cp2102/update_eeprom.c Thu Sep 28 05:25:39 2023 +0000 @@ -0,0 +1,78 @@ +/* + * This program locates a CP2102 device via libusb, reads its internal EEPROM, + * applies user-requested patches to the EEPROM image, and then reprograms + * the physical EEPROM with the patched version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "../libuwrap/find_dev.h" +#include "../libuwrap/open_close.h" +#include "cp210x_defs.h" + +extern struct usb_device *find_cp2102_device(); + +u_char eeprom[SIZE_EEPROM]; +char *device_selector, *baud_change; +int no_detach; + +process_cmdline(argc, argv) + char **argv; +{ + int c; + extern int optind; + extern char *optarg; + + while ((c = getopt(argc, argv, "b:d:n")) != EOF) { + switch (c) { + case 'b': + baud_change = optarg; + continue; + case 'd': + device_selector = optarg; + continue; + case 'n': + no_detach = 1; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [hw-options] eeprom-changes\n", + argv[0]); + exit(1); + } + } + if (argc == optind && !baud_change) + goto usage; +} + +main(argc, argv) + char **argv; +{ + struct usb_device *dev; + usb_dev_handle *usbh; + extern int optind; + + process_cmdline(argc, argv); + dev = find_cp2102_device(device_selector); + usbh = usb_open(dev); + if (!usbh) { + fprintf(stderr, "error: usb_open() failed\n"); + exit(1); + } + read_eeprom(usbh); + if (baud_change) + apply_eeprom_patch_baud(baud_change); + for (; optind < argc; optind++) + apply_eeprom_patch_file(argv[optind]); + if (!no_detach) + usbwrap_claim_all_ifs(usbh); + write_eeprom(usbh); + usb_close(usbh); + exit(0); +}