libztex: Start download sequence only after reading in the new firmware The download sequence starts with a reset command, which tells the board that a new firmware is about to be downloaded. The board gets unhappy if no new firmware is actually sent, so only send the reset command AFTER the new firmware has actually been successfully read.
diff --git a/libztex.c b/libztex.c
index ca81b41..de00bae 100644
--- a/libztex.c
+++ b/libztex.c
@@ -124,15 +124,6 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
applog(LOG_ERR, "Found dummy firmware, trying to send mining firmware: %s", firmware);
- // reset 1
- buf[0] = 1;
- cnt = libusb_control_transfer(hndl, 0x40, 0xA0, 0xE600, 0, buf, 1,1000);
- if (cnt < 0)
- {
- applog(LOG_ERR, "Ztex reset 1 failed: %s", libusb_error_name(cnt));
- goto done;
- }
-
fp = open_bitstream("ztex", firmware);
if (!fp) {
applog(LOG_ERR, "failed to open firmware file '%s'", firmware);
@@ -161,6 +152,15 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
goto done;
}
+ // reset 1
+ buf[0] = 1;
+ cnt = libusb_control_transfer(hndl, 0x40, 0xA0, 0xE600, 0, buf, 1,1000);
+ if (cnt < 0)
+ {
+ applog(LOG_ERR, "Ztex reset 1 failed: %s", libusb_error_name(cnt));
+ goto done;
+ }
+
for (i = 0; i < length; i+= 256) {
// firmware wants data in small chunks like 256 bytes
int numbytes = (length - i) < 256 ? (length - i) : 256;