FreeCalypso > hg > fc-usbser-tools
comparison fteeprom/fteeprom-erase.c @ 46:d682cac178c2
fteeprom-erase: implement -d option for interface detach
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 02:59:10 +0000 |
parents | 2746b160afb7 |
children | 5cbde3c80c24 |
comparison
equal
deleted
inserted
replaced
45:a94bd4002076 | 46:d682cac178c2 |
---|---|
17 #include <usb.h> | 17 #include <usb.h> |
18 #include "../libuwrap/find_dev.h" | 18 #include "../libuwrap/find_dev.h" |
19 #include "../libuwrap/open_close.h" | 19 #include "../libuwrap/open_close.h" |
20 #include "../libftmini/eeprom_func.h" | 20 #include "../libftmini/eeprom_func.h" |
21 | 21 |
22 char *device_selector; | |
23 int detach_num; | |
24 | |
25 process_cmdline(argc, argv) | |
26 char **argv; | |
27 { | |
28 int c; | |
29 extern int optind; | |
30 extern char *optarg; | |
31 | |
32 while ((c = getopt(argc, argv, "d:")) != EOF) { | |
33 switch (c) { | |
34 case 'd': | |
35 detach_num = atoi(optarg); | |
36 switch (detach_num) { | |
37 case 0: | |
38 case 1: | |
39 case 2: | |
40 case 4: | |
41 break; | |
42 default: | |
43 fprintf(stderr, "error: invalid -d argument\n"); | |
44 exit(1); | |
45 } | |
46 continue; | |
47 default: | |
48 /* error msg already printed */ | |
49 exit(1); | |
50 } | |
51 } | |
52 if (argc != optind + 1) { | |
53 fprintf(stderr, "usage: %s [options] device-selector\n", | |
54 argv[0]); | |
55 exit(1); | |
56 } | |
57 device_selector = argv[optind]; | |
58 } | |
59 | |
22 main(argc, argv) | 60 main(argc, argv) |
23 char **argv; | 61 char **argv; |
24 { | 62 { |
25 struct usb_device *dev; | 63 struct usb_device *dev; |
26 usb_dev_handle *usbh; | 64 usb_dev_handle *usbh; |
27 | 65 |
28 if (argc != 2) { | 66 process_cmdline(argc, argv); |
29 fprintf(stderr, "usage: %s device-selector\n"); | 67 dev = find_usbdev_by_desc_string(device_selector); |
30 exit(1); | |
31 } | |
32 dev = find_usbdev_by_desc_string(argv[1]); | |
33 if (!dev) { | 68 if (!dev) { |
34 fprintf(stderr, "error: specified USB device not found\n"); | 69 fprintf(stderr, "error: specified USB device not found\n"); |
35 exit(1); | 70 exit(1); |
36 } | 71 } |
37 usbh = usb_open(dev); | 72 usbh = usb_open(dev); |
38 if (!usbh) { | 73 if (!usbh) { |
39 fprintf(stderr, "error: usb_open() failed\n"); | 74 fprintf(stderr, "error: usb_open() failed\n"); |
40 exit(1); | 75 exit(1); |
41 } | 76 } |
77 if (detach_num) | |
78 usbwrap_claim_all_ifs(usbh, detach_num); | |
42 ftmini_erase_eeprom(usbh); | 79 ftmini_erase_eeprom(usbh); |
43 usb_close(usbh); | 80 usb_close(usbh); |
44 exit(0); | 81 exit(0); |
45 } | 82 } |