FreeCalypso > hg > fc-usbser-tools
comparison cp2102/write_eeprom_main.c @ 96:c6d04771bf6a
cp2102-write-eeprom program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Sep 2023 02:38:59 +0000 |
parents | |
children | 8d35346f1d46 |
comparison
equal
deleted
inserted
replaced
95:a378bf95c26c | 96:c6d04771bf6a |
---|---|
1 /* | |
2 * This program reads a CP2102 EEPROM image from an Intel HEX file | |
3 * and writes it into a physical CP2102 USB device. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <unistd.h> | |
12 #include <usb.h> | |
13 #include "../libuwrap/find_dev.h" | |
14 #include "../libuwrap/open_close.h" | |
15 #include "cp210x_defs.h" | |
16 | |
17 u_char eeprom[SIZE_EEPROM]; | |
18 char *device_selector, *input_filename; | |
19 int no_detach; | |
20 | |
21 process_cmdline(argc, argv) | |
22 char **argv; | |
23 { | |
24 int c; | |
25 extern int optind; | |
26 extern char *optarg; | |
27 | |
28 while ((c = getopt(argc, argv, "n")) != EOF) { | |
29 switch (c) { | |
30 case 'n': | |
31 no_detach = 1; | |
32 continue; | |
33 default: | |
34 /* error msg already printed */ | |
35 exit(1); | |
36 } | |
37 } | |
38 if (argc != optind + 2) { | |
39 fprintf(stderr, | |
40 "usage: %s [options] device-selector eeprom-image\n", | |
41 argv[0]); | |
42 exit(1); | |
43 } | |
44 device_selector = argv[optind]; | |
45 input_filename = argv[optind + 1]; | |
46 } | |
47 | |
48 main(argc, argv) | |
49 char **argv; | |
50 { | |
51 struct usb_device *dev; | |
52 usb_dev_handle *usbh; | |
53 | |
54 process_cmdline(argc, argv); | |
55 read_intel_hex(input_filename); | |
56 dev = find_usbdev_by_desc_string(device_selector); | |
57 if (!dev) { | |
58 fprintf(stderr, "error: specified USB device not found\n"); | |
59 exit(1); | |
60 } | |
61 usbh = usb_open(dev); | |
62 if (!usbh) { | |
63 fprintf(stderr, "error: usb_open() failed\n"); | |
64 exit(1); | |
65 } | |
66 if (!no_detach) | |
67 usbwrap_claim_all_ifs(usbh); | |
68 write_eeprom(usbh); | |
69 usb_close(usbh); | |
70 exit(0); | |
71 } |