FreeCalypso > hg > fc-usbser-tools
comparison cp2102/update_eeprom.c @ 99:c59011177e2e
cp2102-update-eeprom program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Sep 2023 05:25:39 +0000 |
parents | cp2102/write_eeprom_main.c@1cacc1ae56f0 |
children |
comparison
equal
deleted
inserted
replaced
98:1cacc1ae56f0 | 99:c59011177e2e |
---|---|
1 /* | |
2 * This program locates a CP2102 device via libusb, reads its internal EEPROM, | |
3 * applies user-requested patches to the EEPROM image, and then reprograms | |
4 * the physical EEPROM with the patched version. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <unistd.h> | |
13 #include <usb.h> | |
14 #include "../libuwrap/find_dev.h" | |
15 #include "../libuwrap/open_close.h" | |
16 #include "cp210x_defs.h" | |
17 | |
18 extern struct usb_device *find_cp2102_device(); | |
19 | |
20 u_char eeprom[SIZE_EEPROM]; | |
21 char *device_selector, *baud_change; | |
22 int no_detach; | |
23 | |
24 process_cmdline(argc, argv) | |
25 char **argv; | |
26 { | |
27 int c; | |
28 extern int optind; | |
29 extern char *optarg; | |
30 | |
31 while ((c = getopt(argc, argv, "b:d:n")) != EOF) { | |
32 switch (c) { | |
33 case 'b': | |
34 baud_change = optarg; | |
35 continue; | |
36 case 'd': | |
37 device_selector = optarg; | |
38 continue; | |
39 case 'n': | |
40 no_detach = 1; | |
41 continue; | |
42 default: | |
43 usage: | |
44 fprintf(stderr, | |
45 "usage: %s [hw-options] eeprom-changes\n", | |
46 argv[0]); | |
47 exit(1); | |
48 } | |
49 } | |
50 if (argc == optind && !baud_change) | |
51 goto usage; | |
52 } | |
53 | |
54 main(argc, argv) | |
55 char **argv; | |
56 { | |
57 struct usb_device *dev; | |
58 usb_dev_handle *usbh; | |
59 extern int optind; | |
60 | |
61 process_cmdline(argc, argv); | |
62 dev = find_cp2102_device(device_selector); | |
63 usbh = usb_open(dev); | |
64 if (!usbh) { | |
65 fprintf(stderr, "error: usb_open() failed\n"); | |
66 exit(1); | |
67 } | |
68 read_eeprom(usbh); | |
69 if (baud_change) | |
70 apply_eeprom_patch_baud(baud_change); | |
71 for (; optind < argc; optind++) | |
72 apply_eeprom_patch_file(argv[optind]); | |
73 if (!no_detach) | |
74 usbwrap_claim_all_ifs(usbh); | |
75 write_eeprom(usbh); | |
76 usb_close(usbh); | |
77 exit(0); | |
78 } |