summaryrefslogtreecommitdiff
path: root/fx2load.c
diff options
context:
space:
mode:
Diffstat (limited to 'fx2load.c')
-rw-r--r--fx2load.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/fx2load.c b/fx2load.c
new file mode 100644
index 0000000..ebda258
--- /dev/null
+++ b/fx2load.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libusb.h>
+
+int main(int argc, char **argv)
+{
+ libusb_context *c; libusb_device_handle *h;
+ FILE *f = fopen(argv[1], "rb");
+ static unsigned char fw[0x4000];
+ size_t len = fread(fw, 1, sizeof fw, f), off;
+ unsigned char one = 1, zero = 0;
+ int r;
+
+ libusb_init(&c);
+ h = libusb_open_device_with_vid_pid(c, 0x04b4, 0x8613);
+ if (!h) { puts("device not found"); return 1; }
+
+ r = libusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0, &one, 1, 1000);
+ printf("reset assert: %d\n", r);
+ for (off = 0; off < len; off += 0x800) {
+ size_t n = len - off < 0x800 ? len - off : 0x800;
+ r = libusb_control_transfer(h, 0x40, 0xA0, off, 0, fw + off, n, 1000);
+ printf("0x%04zx: %d\n", off, r);
+ if (r < 0) return 1;
+ }
+ r = libusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0, &zero, 1, 1000);
+ printf("reset release: %d\n", r);
+ return 0;
+}