usb 1.7.2-prebuild

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.github/workflows/prebuild.yml +62 -0
  2. package/.gitmodules +3 -0
  3. package/LICENSE +7 -0
  4. package/Readme.md +339 -0
  5. package/binding.gyp +90 -0
  6. package/libusb/.gitattributes +11 -0
  7. package/libusb/.private/README.txt +5 -0
  8. package/libusb/.private/bd.cmd +89 -0
  9. package/libusb/.private/bm.sh +54 -0
  10. package/libusb/.private/bwince.cmd +57 -0
  11. package/libusb/.private/post-rewrite.sh +28 -0
  12. package/libusb/.private/pre-commit.sh +42 -0
  13. package/libusb/.private/wbs.txt +61 -0
  14. package/libusb/.private/wbs_wince.txt +42 -0
  15. package/libusb/AUTHORS +78 -0
  16. package/libusb/COPYING +504 -0
  17. package/libusb/ChangeLog +211 -0
  18. package/libusb/INSTALL +234 -0
  19. package/libusb/INSTALL_WIN.txt +73 -0
  20. package/libusb/Makefile.am +28 -0
  21. package/libusb/NEWS +2 -0
  22. package/libusb/PORTING +94 -0
  23. package/libusb/README +28 -0
  24. package/libusb/README.git +41 -0
  25. package/libusb/TODO +2 -0
  26. package/libusb/Xcode/common.xcconfig +49 -0
  27. package/libusb/Xcode/debug.xcconfig +29 -0
  28. package/libusb/Xcode/libusb.xcconfig +21 -0
  29. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +1 -0
  30. package/libusb/Xcode/libusb_debug.xcconfig +21 -0
  31. package/libusb/Xcode/libusb_release.xcconfig +21 -0
  32. package/libusb/Xcode/release.xcconfig +30 -0
  33. package/libusb/android/README +114 -0
  34. package/libusb/android/jni/Android.mk +23 -0
  35. package/libusb/android/jni/Application.mk +24 -0
  36. package/libusb/android/jni/examples.mk +134 -0
  37. package/libusb/android/jni/libusb.mk +54 -0
  38. package/libusb/android/jni/tests.mk +56 -0
  39. package/libusb/autogen.sh +8 -0
  40. package/libusb/bootstrap.sh +19 -0
  41. package/libusb/configure.ac +304 -0
  42. package/libusb/doc/Makefile.am +9 -0
  43. package/libusb/doc/doxygen.cfg.in +1288 -0
  44. package/libusb/doc/libusb.png +0 -0
  45. package/libusb/examples/Makefile.am +19 -0
  46. package/libusb/examples/dpfp.c +506 -0
  47. package/libusb/examples/dpfp_threaded.c +544 -0
  48. package/libusb/examples/ezusb.c +831 -0
  49. package/libusb/examples/ezusb.h +120 -0
  50. package/libusb/examples/fxload.c +287 -0
  51. package/libusb/examples/getopt/getopt.c +1060 -0
  52. package/libusb/examples/getopt/getopt.h +180 -0
  53. package/libusb/examples/getopt/getopt1.c +188 -0
  54. package/libusb/examples/hotplugtest.c +104 -0
  55. package/libusb/examples/listdevs.c +71 -0
  56. package/libusb/examples/sam3u_benchmark.c +193 -0
  57. package/libusb/examples/xusb.c +1129 -0
  58. package/libusb/libusb/Makefile.am +75 -0
  59. package/libusb/libusb/core.c +2342 -0
  60. package/libusb/libusb/descriptor.c +1199 -0
  61. package/libusb/libusb/hotplug.c +327 -0
  62. package/libusb/libusb/hotplug.h +82 -0
  63. package/libusb/libusb/io.c +2631 -0
  64. package/libusb/libusb/libusb-1.0.def +166 -0
  65. package/libusb/libusb/libusb-1.0.rc +61 -0
  66. package/libusb/libusb/libusb.h +1998 -0
  67. package/libusb/libusb/libusbi.h +1040 -0
  68. package/libusb/libusb/os/darwin_usb.c +2009 -0
  69. package/libusb/libusb/os/darwin_usb.h +162 -0
  70. package/libusb/libusb/os/linux_netlink.c +369 -0
  71. package/libusb/libusb/os/linux_udev.c +307 -0
  72. package/libusb/libusb/os/linux_usbfs.c +2695 -0
  73. package/libusb/libusb/os/linux_usbfs.h +192 -0
  74. package/libusb/libusb/os/netbsd_usb.c +738 -0
  75. package/libusb/libusb/os/openbsd_usb.c +832 -0
  76. package/libusb/libusb/os/poll_posix.c +51 -0
  77. package/libusb/libusb/os/poll_posix.h +11 -0
  78. package/libusb/libusb/os/poll_windows.c +796 -0
  79. package/libusb/libusb/os/poll_windows.h +131 -0
  80. package/libusb/libusb/os/threads_posix.c +82 -0
  81. package/libusb/libusb/os/threads_posix.h +50 -0
  82. package/libusb/libusb/os/threads_windows.c +212 -0
  83. package/libusb/libusb/os/threads_windows.h +87 -0
  84. package/libusb/libusb/os/wince_usb.c +1032 -0
  85. package/libusb/libusb/os/wince_usb.h +131 -0
  86. package/libusb/libusb/os/windows_common.h +108 -0
  87. package/libusb/libusb/os/windows_usb.c +5347 -0
  88. package/libusb/libusb/os/windows_usb.h +971 -0
  89. package/libusb/libusb/strerror.c +199 -0
  90. package/libusb/libusb/sync.c +307 -0
  91. package/libusb/libusb/version.h +18 -0
  92. package/libusb/libusb/version_nano.h +1 -0
  93. package/libusb/libusb-1.0.pc.in +11 -0
  94. package/libusb/msvc/config.h +50 -0
  95. package/libusb/msvc/ddk_build.cmd +175 -0
  96. package/libusb/msvc/errno.h +102 -0
  97. package/libusb/msvc/fxload_2010.vcxproj +170 -0
  98. package/libusb/msvc/fxload_2010.vcxproj.filters +25 -0
  99. package/libusb/msvc/fxload_2012.vcxproj +174 -0
  100. package/libusb/msvc/fxload_2012.vcxproj.filters +25 -0
  101. package/libusb/msvc/fxload_2013.vcxproj +174 -0
  102. package/libusb/msvc/fxload_sources +23 -0
  103. package/libusb/msvc/getopt_2005.vcproj +288 -0
  104. package/libusb/msvc/getopt_2010.vcxproj +131 -0
  105. package/libusb/msvc/getopt_2010.vcxproj.filters +26 -0
  106. package/libusb/msvc/getopt_2012.vcxproj +136 -0
  107. package/libusb/msvc/getopt_2012.vcxproj.filters +26 -0
  108. package/libusb/msvc/getopt_2013.vcxproj +136 -0
  109. package/libusb/msvc/getopt_sources +20 -0
  110. package/libusb/msvc/hotplugtest_2010.vcxproj +163 -0
  111. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +14 -0
  112. package/libusb/msvc/hotplugtest_2012.vcxproj +167 -0
  113. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +14 -0
  114. package/libusb/msvc/hotplugtest_2013.vcxproj +167 -0
  115. package/libusb/msvc/hotplugtest_sources +20 -0
  116. package/libusb/msvc/inttypes.h +295 -0
  117. package/libusb/msvc/libusb.dsw +71 -0
  118. package/libusb/msvc/libusb_2005.sln +95 -0
  119. package/libusb/msvc/libusb_2010.sln +94 -0
  120. package/libusb/msvc/libusb_2012.sln +94 -0
  121. package/libusb/msvc/libusb_2013.sln +100 -0
  122. package/libusb/msvc/libusb_2015.sln +100 -0
  123. package/libusb/msvc/libusb_dll.dsp +194 -0
  124. package/libusb/msvc/libusb_dll_2005.vcproj +436 -0
  125. package/libusb/msvc/libusb_dll_2010.vcxproj +170 -0
  126. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +81 -0
  127. package/libusb/msvc/libusb_dll_2012.vcxproj +175 -0
  128. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +84 -0
  129. package/libusb/msvc/libusb_dll_2013.vcxproj +175 -0
  130. package/libusb/msvc/libusb_dll_wince.vcproj +1243 -0
  131. package/libusb/msvc/libusb_sources +38 -0
  132. package/libusb/msvc/libusb_static.dsp +174 -0
  133. package/libusb/msvc/libusb_static_2005.vcproj +362 -0
  134. package/libusb/msvc/libusb_static_2010.vcxproj +156 -0
  135. package/libusb/msvc/libusb_static_2010.vcxproj.filters +74 -0
  136. package/libusb/msvc/libusb_static_2012.vcxproj +160 -0
  137. package/libusb/msvc/libusb_static_2012.vcxproj.filters +74 -0
  138. package/libusb/msvc/libusb_static_2013.vcxproj +160 -0
  139. package/libusb/msvc/libusb_static_wince.vcproj +1185 -0
  140. package/libusb/msvc/libusb_wince.sln +246 -0
  141. package/libusb/msvc/listdevs.dsp +103 -0
  142. package/libusb/msvc/listdevs_2005.vcproj +360 -0
  143. package/libusb/msvc/listdevs_2010.vcxproj +165 -0
  144. package/libusb/msvc/listdevs_2010.vcxproj.filters +14 -0
  145. package/libusb/msvc/listdevs_2012.vcxproj +169 -0
  146. package/libusb/msvc/listdevs_2012.vcxproj.filters +14 -0
  147. package/libusb/msvc/listdevs_2013.vcxproj +169 -0
  148. package/libusb/msvc/listdevs_sources +19 -0
  149. package/libusb/msvc/listdevs_wince.vcproj +1120 -0
  150. package/libusb/msvc/missing.c +80 -0
  151. package/libusb/msvc/missing.h +32 -0
  152. package/libusb/msvc/stdint.h +256 -0
  153. package/libusb/msvc/stress_2005.vcproj +390 -0
  154. package/libusb/msvc/stress_2010.vcxproj +167 -0
  155. package/libusb/msvc/stress_2010.vcxproj.filters +25 -0
  156. package/libusb/msvc/stress_2012.vcxproj +171 -0
  157. package/libusb/msvc/stress_2012.vcxproj.filters +25 -0
  158. package/libusb/msvc/stress_2013.vcxproj +171 -0
  159. package/libusb/msvc/stress_wince.vcproj +1128 -0
  160. package/libusb/msvc/xusb.dsp +102 -0
  161. package/libusb/msvc/xusb_2005.vcproj +344 -0
  162. package/libusb/msvc/xusb_2010.vcxproj +163 -0
  163. package/libusb/msvc/xusb_2010.vcxproj.filters +14 -0
  164. package/libusb/msvc/xusb_2012.vcxproj +167 -0
  165. package/libusb/msvc/xusb_2012.vcxproj.filters +14 -0
  166. package/libusb/msvc/xusb_2013.vcxproj +167 -0
  167. package/libusb/msvc/xusb_sources +20 -0
  168. package/libusb/msvc/xusb_wince.vcproj +1120 -0
  169. package/libusb/tests/Makefile.am +6 -0
  170. package/libusb/tests/libusb_testlib.h +107 -0
  171. package/libusb/tests/stress.c +160 -0
  172. package/libusb/tests/testlib.c +281 -0
  173. package/libusb.gypi +136 -0
  174. package/libusb_config/config.h +1 -0
  175. package/package.json +69 -0
  176. package/src/device.cc +412 -0
  177. package/src/helpers.h +64 -0
  178. package/src/node_usb.cc +319 -0
  179. package/src/node_usb.h +120 -0
  180. package/src/transfer.cc +148 -0
  181. package/src/uv_async_queue.h +33 -0
  182. package/test/usb.coffee +191 -0
  183. package/usb.js +524 -0
@@ -0,0 +1,120 @@
1
+ #ifndef __ezusb_H
2
+ #define __ezusb_H
3
+ /*
4
+ * Copyright © 2001 Stephen Williams (steve@icarus.com)
5
+ * Copyright © 2002 David Brownell (dbrownell@users.sourceforge.net)
6
+ * Copyright © 2013 Federico Manzan (f.manzan@gmail.com)
7
+ *
8
+ * This source code is free software; you can redistribute it
9
+ * and/or modify it in source code form under the terms of the GNU
10
+ * General Public License as published by the Free Software
11
+ * Foundation; either version 2 of the License, or (at your option)
12
+ * any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
+ */
23
+ #if !defined(_MSC_VER)
24
+ #include <stdbool.h>
25
+ #else
26
+ #define __attribute__(x)
27
+ #if !defined(bool)
28
+ #define bool int
29
+ #endif
30
+ #if !defined(true)
31
+ #define true (1 == 1)
32
+ #endif
33
+ #if !defined(false)
34
+ #define false (!true)
35
+ #endif
36
+ #if defined(_PREFAST_)
37
+ #pragma warning(disable:28193)
38
+ #endif
39
+ #endif
40
+
41
+ #define FX_TYPE_UNDEFINED -1
42
+ #define FX_TYPE_AN21 0 /* Original AnchorChips parts */
43
+ #define FX_TYPE_FX1 1 /* Updated Cypress versions */
44
+ #define FX_TYPE_FX2 2 /* USB 2.0 versions */
45
+ #define FX_TYPE_FX2LP 3 /* Updated FX2 */
46
+ #define FX_TYPE_FX3 4 /* USB 3.0 versions */
47
+ #define FX_TYPE_MAX 5
48
+ #define FX_TYPE_NAMES { "an21", "fx", "fx2", "fx2lp", "fx3" }
49
+
50
+ #define IMG_TYPE_UNDEFINED -1
51
+ #define IMG_TYPE_HEX 0 /* Intel HEX */
52
+ #define IMG_TYPE_IIC 1 /* Cypress 8051 IIC */
53
+ #define IMG_TYPE_BIX 2 /* Cypress 8051 BIX */
54
+ #define IMG_TYPE_IMG 3 /* Cypress IMG format */
55
+ #define IMG_TYPE_MAX 4
56
+ #define IMG_TYPE_NAMES { "Intel HEX", "Cypress 8051 IIC", "Cypress 8051 BIX", "Cypress IMG format" }
57
+
58
+ #ifdef __cplusplus
59
+ extern "C" {
60
+ #endif
61
+
62
+ /*
63
+ * Automatically identified devices (VID, PID, type, designation).
64
+ * TODO: Could use some validation. Also where's the FX2?
65
+ */
66
+ typedef struct {
67
+ uint16_t vid;
68
+ uint16_t pid;
69
+ int type;
70
+ const char* designation;
71
+ } fx_known_device;
72
+
73
+ #define FX_KNOWN_DEVICES { \
74
+ { 0x0547, 0x2122, FX_TYPE_AN21, "Cypress EZ-USB (2122S)" },\
75
+ { 0x0547, 0x2125, FX_TYPE_AN21, "Cypress EZ-USB (2121S/2125S)" },\
76
+ { 0x0547, 0x2126, FX_TYPE_AN21, "Cypress EZ-USB (2126S)" },\
77
+ { 0x0547, 0x2131, FX_TYPE_AN21, "Cypress EZ-USB (2131Q/2131S/2135S)" },\
78
+ { 0x0547, 0x2136, FX_TYPE_AN21, "Cypress EZ-USB (2136S)" },\
79
+ { 0x0547, 0x2225, FX_TYPE_AN21, "Cypress EZ-USB (2225)" },\
80
+ { 0x0547, 0x2226, FX_TYPE_AN21, "Cypress EZ-USB (2226)" },\
81
+ { 0x0547, 0x2235, FX_TYPE_AN21, "Cypress EZ-USB (2235)" },\
82
+ { 0x0547, 0x2236, FX_TYPE_AN21, "Cypress EZ-USB (2236)" },\
83
+ { 0x04b4, 0x6473, FX_TYPE_FX1, "Cypress EZ-USB FX1" },\
84
+ { 0x04b4, 0x8613, FX_TYPE_FX2LP, "Cypress EZ-USB FX2LP (68013A/68014A/68015A/68016A)" }, \
85
+ { 0x04b4, 0x00f3, FX_TYPE_FX3, "Cypress FX3" },\
86
+ }
87
+
88
+ /*
89
+ * This function uploads the firmware from the given file into RAM.
90
+ * Stage == 0 means this is a single stage load (or the first of
91
+ * two stages). Otherwise it's the second of two stages; the
92
+ * caller having preloaded the second stage loader.
93
+ *
94
+ * The target processor is reset at the end of this upload.
95
+ */
96
+ extern int ezusb_load_ram(libusb_device_handle *device,
97
+ const char *path, int fx_type, int img_type, int stage);
98
+
99
+ /*
100
+ * This function uploads the firmware from the given file into EEPROM.
101
+ * This uses the right CPUCS address to terminate the EEPROM load with
102
+ * a reset command where FX parts behave differently than FX2 ones.
103
+ * The configuration byte is as provided here (zero for an21xx parts)
104
+ * and the EEPROM type is set so that the microcontroller will boot
105
+ * from it.
106
+ *
107
+ * The caller must have preloaded a second stage loader that knows
108
+ * how to respond to the EEPROM write request.
109
+ */
110
+ extern int ezusb_load_eeprom(libusb_device_handle *device,
111
+ const char *path, int fx_type, int img_type, int config);
112
+
113
+ /* Verbosity level (default 1). Can be increased or decreased with options v/q */
114
+ extern int verbose;
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
119
+
120
+ #endif
@@ -0,0 +1,287 @@
1
+ /*
2
+ * Copyright © 2001 Stephen Williams (steve@icarus.com)
3
+ * Copyright © 2001-2002 David Brownell (dbrownell@users.sourceforge.net)
4
+ * Copyright © 2008 Roger Williams (rawqux@users.sourceforge.net)
5
+ * Copyright © 2012 Pete Batard (pete@akeo.ie)
6
+ * Copyright © 2013 Federico Manzan (f.manzan@gmail.com)
7
+ *
8
+ * This source code is free software; you can redistribute it
9
+ * and/or modify it in source code form under the terms of the GNU
10
+ * General Public License as published by the Free Software
11
+ * Foundation; either version 2 of the License, or (at your option)
12
+ * any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
+ */
23
+
24
+ #include <stdlib.h>
25
+ #include <stdio.h>
26
+ #include <string.h>
27
+ #include <stdint.h>
28
+ #include <stdarg.h>
29
+ #include <sys/types.h>
30
+ #include <getopt.h>
31
+
32
+ #include "libusb.h"
33
+ #include "ezusb.h"
34
+
35
+ #if !defined(_WIN32) || defined(__CYGWIN__ )
36
+ #include <syslog.h>
37
+ static bool dosyslog = false;
38
+ #include <strings.h>
39
+ #define _stricmp strcasecmp
40
+ #endif
41
+
42
+ #ifndef FXLOAD_VERSION
43
+ #define FXLOAD_VERSION (__DATE__ " (libusb)")
44
+ #endif
45
+
46
+ #ifndef ARRAYSIZE
47
+ #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
48
+ #endif
49
+
50
+ void logerror(const char *format, ...)
51
+ __attribute__ ((format (__printf__, 1, 2)));
52
+
53
+ void logerror(const char *format, ...)
54
+ {
55
+ va_list ap;
56
+ va_start(ap, format);
57
+
58
+ #if !defined(_WIN32) || defined(__CYGWIN__ )
59
+ if (dosyslog)
60
+ vsyslog(LOG_ERR, format, ap);
61
+ else
62
+ #endif
63
+ vfprintf(stderr, format, ap);
64
+ va_end(ap);
65
+ }
66
+
67
+ static int print_usage(int error_code) {
68
+ fprintf(stderr, "\nUsage: fxload [-v] [-V] [-t type] [-d vid:pid] [-p bus,addr] -i firmware\n");
69
+ fprintf(stderr, " -i <path> -- Firmware to upload\n");
70
+ fprintf(stderr, " -t <type> -- Target type: an21, fx, fx2, fx2lp, fx3\n");
71
+ fprintf(stderr, " -d <vid:pid> -- Target device, as an USB VID:PID\n");
72
+ fprintf(stderr, " -p <bus,addr> -- Target device, as a libusb bus number and device address path\n");
73
+ fprintf(stderr, " -v -- Increase verbosity\n");
74
+ fprintf(stderr, " -q -- Decrease verbosity (silent mode)\n");
75
+ fprintf(stderr, " -V -- Print program version\n");
76
+ return error_code;
77
+ }
78
+
79
+ #define FIRMWARE 0
80
+ #define LOADER 1
81
+ int main(int argc, char*argv[])
82
+ {
83
+ fx_known_device known_device[] = FX_KNOWN_DEVICES;
84
+ const char *path[] = { NULL, NULL };
85
+ const char *device_id = NULL;
86
+ const char *device_path = getenv("DEVICE");
87
+ const char *type = NULL;
88
+ const char *fx_name[FX_TYPE_MAX] = FX_TYPE_NAMES;
89
+ const char *ext, *img_name[] = IMG_TYPE_NAMES;
90
+ int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)];
91
+ int i, j, opt, status;
92
+ unsigned vid = 0, pid = 0;
93
+ unsigned busnum = 0, devaddr = 0, _busnum, _devaddr;
94
+ libusb_device *dev, **devs;
95
+ libusb_device_handle *device = NULL;
96
+ struct libusb_device_descriptor desc;
97
+
98
+ while ((opt = getopt(argc, argv, "qvV?hd:p:i:I:t:")) != EOF)
99
+ switch (opt) {
100
+
101
+ case 'd':
102
+ device_id = optarg;
103
+ if (sscanf(device_id, "%x:%x" , &vid, &pid) != 2 ) {
104
+ fputs ("please specify VID & PID as \"vid:pid\" in hexadecimal format\n", stderr);
105
+ return -1;
106
+ }
107
+ break;
108
+
109
+ case 'p':
110
+ device_path = optarg;
111
+ if (sscanf(device_path, "%u,%u", &busnum, &devaddr) != 2 ) {
112
+ fputs ("please specify bus number & device number as \"bus,dev\" in decimal format\n", stderr);
113
+ return -1;
114
+ }
115
+ break;
116
+
117
+ case 'i':
118
+ case 'I':
119
+ path[FIRMWARE] = optarg;
120
+ break;
121
+
122
+ case 'V':
123
+ puts(FXLOAD_VERSION);
124
+ return 0;
125
+
126
+ case 't':
127
+ type = optarg;
128
+ break;
129
+
130
+ case 'v':
131
+ verbose++;
132
+ break;
133
+
134
+ case 'q':
135
+ verbose--;
136
+ break;
137
+
138
+ case '?':
139
+ case 'h':
140
+ default:
141
+ return print_usage(-1);
142
+
143
+ }
144
+
145
+ if (path[FIRMWARE] == NULL) {
146
+ logerror("no firmware specified!\n");
147
+ return print_usage(-1);
148
+ }
149
+ if ((device_id != NULL) && (device_path != NULL)) {
150
+ logerror("only one of -d or -p can be specified\n");
151
+ return print_usage(-1);
152
+ }
153
+
154
+ /* determine the target type */
155
+ if (type != NULL) {
156
+ for (i=0; i<FX_TYPE_MAX; i++) {
157
+ if (strcmp(type, fx_name[i]) == 0) {
158
+ fx_type = i;
159
+ break;
160
+ }
161
+ }
162
+ if (i >= FX_TYPE_MAX) {
163
+ logerror("illegal microcontroller type: %s\n", type);
164
+ return print_usage(-1);
165
+ }
166
+ }
167
+
168
+ /* open the device using libusb */
169
+ status = libusb_init(NULL);
170
+ if (status < 0) {
171
+ logerror("libusb_init() failed: %s\n", libusb_error_name(status));
172
+ return -1;
173
+ }
174
+ libusb_set_debug(NULL, verbose);
175
+
176
+ /* try to pick up missing parameters from known devices */
177
+ if ((type == NULL) || (device_id == NULL) || (device_path != NULL)) {
178
+ if (libusb_get_device_list(NULL, &devs) < 0) {
179
+ logerror("libusb_get_device_list() failed: %s\n", libusb_error_name(status));
180
+ goto err;
181
+ }
182
+ for (i=0; (dev=devs[i]) != NULL; i++) {
183
+ _busnum = libusb_get_bus_number(dev);
184
+ _devaddr = libusb_get_device_address(dev);
185
+ if ((type != NULL) && (device_path != NULL)) {
186
+ // if both a type and bus,addr were specified, we just need to find our match
187
+ if ((libusb_get_bus_number(dev) == busnum) && (libusb_get_device_address(dev) == devaddr))
188
+ break;
189
+ } else {
190
+ status = libusb_get_device_descriptor(dev, &desc);
191
+ if (status >= 0) {
192
+ if (verbose >= 3) {
193
+ logerror("examining %04x:%04x (%d,%d)\n",
194
+ desc.idVendor, desc.idProduct, _busnum, _devaddr);
195
+ }
196
+ for (j=0; j<ARRAYSIZE(known_device); j++) {
197
+ if ((desc.idVendor == known_device[j].vid)
198
+ && (desc.idProduct == known_device[j].pid)) {
199
+ if (// nothing was specified
200
+ ((type == NULL) && (device_id == NULL) && (device_path == NULL)) ||
201
+ // vid:pid was specified and we have a match
202
+ ((type == NULL) && (device_id != NULL) && (vid == desc.idVendor) && (pid == desc.idProduct)) ||
203
+ // bus,addr was specified and we have a match
204
+ ((type == NULL) && (device_path != NULL) && (busnum == _busnum) && (devaddr == _devaddr)) ||
205
+ // type was specified and we have a match
206
+ ((type != NULL) && (device_id == NULL) && (device_path == NULL) && (fx_type == known_device[j].type)) ) {
207
+ fx_type = known_device[j].type;
208
+ vid = desc.idVendor;
209
+ pid = desc.idProduct;
210
+ busnum = _busnum;
211
+ devaddr = _devaddr;
212
+ break;
213
+ }
214
+ }
215
+ }
216
+ if (j < ARRAYSIZE(known_device)) {
217
+ if (verbose)
218
+ logerror("found device '%s' [%04x:%04x] (%d,%d)\n",
219
+ known_device[j].designation, vid, pid, busnum, devaddr);
220
+ break;
221
+ }
222
+ }
223
+ }
224
+ }
225
+ if (dev == NULL) {
226
+ libusb_free_device_list(devs, 1);
227
+ logerror("could not find a known device - please specify type and/or vid:pid and/or bus,dev\n");
228
+ return print_usage(-1);
229
+ }
230
+ status = libusb_open(dev, &device);
231
+ if (status < 0) {
232
+ logerror("libusb_open() failed: %s\n", libusb_error_name(status));
233
+ goto err;
234
+ }
235
+ libusb_free_device_list(devs, 1);
236
+ } else if (device_id != NULL) {
237
+ device = libusb_open_device_with_vid_pid(NULL, (uint16_t)vid, (uint16_t)pid);
238
+ if (device == NULL) {
239
+ logerror("libusb_open() failed\n");
240
+ goto err;
241
+ }
242
+ }
243
+
244
+ /* We need to claim the first interface */
245
+ libusb_set_auto_detach_kernel_driver(device, 1);
246
+ status = libusb_claim_interface(device, 0);
247
+ if (status != LIBUSB_SUCCESS) {
248
+ logerror("libusb_claim_interface failed: %s\n", libusb_error_name(status));
249
+ goto err;
250
+ }
251
+
252
+ if (verbose)
253
+ logerror("microcontroller type: %s\n", fx_name[fx_type]);
254
+
255
+ for (i=0; i<ARRAYSIZE(path); i++) {
256
+ if (path[i] != NULL) {
257
+ ext = path[i] + strlen(path[i]) - 4;
258
+ if ((_stricmp(ext, ".hex") == 0) || (strcmp(ext, ".ihx") == 0))
259
+ img_type[i] = IMG_TYPE_HEX;
260
+ else if (_stricmp(ext, ".iic") == 0)
261
+ img_type[i] = IMG_TYPE_IIC;
262
+ else if (_stricmp(ext, ".bix") == 0)
263
+ img_type[i] = IMG_TYPE_BIX;
264
+ else if (_stricmp(ext, ".img") == 0)
265
+ img_type[i] = IMG_TYPE_IMG;
266
+ else {
267
+ logerror("%s is not a recognized image type\n", path[i]);
268
+ goto err;
269
+ }
270
+ }
271
+ if (verbose && path[i] != NULL)
272
+ logerror("%s: type %s\n", path[i], img_name[img_type[i]]);
273
+ }
274
+
275
+ /* single stage, put into internal memory */
276
+ if (verbose > 1)
277
+ logerror("single stage: load on-chip memory\n");
278
+ status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 0);
279
+
280
+ libusb_release_interface(device, 0);
281
+ libusb_close(device);
282
+ libusb_exit(NULL);
283
+ return status;
284
+ err:
285
+ libusb_exit(NULL);
286
+ return -1;
287
+ }