Browse Source

libztex: Add firmware download support for ZTEX 1.15d and 1.15x

The correct firmware file is automatically determined based on the ZTEX
descriptor in the dummy firmware.
Denis Ahrens 13 years ago
parent
commit
1203f1f621
1 changed files with 38 additions and 6 deletions
  1. 38 6
      libztex.c

+ 38 - 6
libztex.c

@@ -1,5 +1,5 @@
 /**
- *   libztex.c - Ztex 1.15x fpga board support library
+ *   libztex.c - Ztex 1.15x/1.15y fpga board support library
  *
  *   Copyright (c) 2012 nelisky.btc@gmail.com
  *   Copyright (c) 2012 Denis Ahrens <denis@h3q.com>
@@ -105,7 +105,6 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
 	int i, ret = CHECK_ERROR, err, cnt;
 	size_t got_bytes, length;
 	unsigned char buf[64], *fw_buf;
-	char *firmware = "ztex_ufm1_15y1.bin";
 
 	err = libusb_get_device_descriptor(dev, &desc);
 	if (unlikely(err != 0)) {
@@ -145,9 +144,8 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
 	switch(buf[7])
 	{
 		case 13:
-			applog(LOG_ERR, "Found ztex board 1.15d or 1.15x but currently unsupported!");
-			ret = CHECK_IS_NOT_ZTEX;
-			goto done;
+			applog(LOG_ERR, "Found ztex board 1.15d or 1.15x");
+			break;
 		case 15:
 			applog(LOG_ERR, "Found ztex board 1.15y");
 			break;
@@ -163,7 +161,41 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
 		goto done;
 	}
 
-	applog(LOG_ERR, "Found dummy firmware, trying to send mining firmware: %s", firmware);
+	applog(LOG_ERR, "Found dummy firmware, trying to send mining firmware");
+
+	char productString[32];
+
+	cnt = libztex_get_string_descriptor_ascii(hndl, desc.iProduct, productString, sizeof(productString));
+	if (unlikely(cnt < 0)) {
+		applog(LOG_ERR, "Ztex check device: Failed to read device productString with err %d", cnt);
+		return cnt;
+	}
+
+	applog(LOG_ERR, "productString: %s", productString);
+
+	unsigned char productID2 = buf[7];
+	char *firmware = NULL;
+
+	if (strcmp("USB-FPGA Module 1.15d (default)", productString) == 0 && productID2 == 13)
+	{
+		firmware = "ztex_ufm1_15d4.bin";
+	}
+	else if (strcmp("USB-FPGA Module 1.15x (default)", productString) == 0 && productID2 == 13)
+	{
+		firmware = "ztex_ufm1_15d4.bin";
+	}
+	else if (strcmp("USB-FPGA Module 1.15y (default)", productString) == 0 && productID2 == 15)
+	{
+		firmware = "ztex_ufm1_15y1.bin";
+	}
+
+	if (firmware == NULL)
+	{
+		applog(LOG_ERR, "could not figure out which firmware to use");
+		goto done;
+	}
+
+	applog(LOG_ERR, "Mining firmware filename: %s", firmware);
 
 	fp = open_bitstream("ztex", firmware);
 	if (!fp) {