jtag_libusb_bulk_read|write: return error code instead of size
[fw/openocd] / src / jtag / drivers / usb_blaster / ublast2_access_libusb.c
index 437150d752d3b6814ec399329aad6fd5c42435b1..fb1e4440a5a4aa89ba23daa05e38d6f18b8fad23 100644 (file)
@@ -13,6 +13,9 @@
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
  */
 
 #ifdef HAVE_CONFIG_H
 static int ublast2_libusb_read(struct ublast_lowlevel *low, uint8_t *buf,
                              unsigned size, uint32_t *bytes_read)
 {
-       *bytes_read = jtag_libusb_bulk_read(low->libusb_dev,
+       int ret, tmp = 0;
+
+       ret = jtag_libusb_bulk_read(low->libusb_dev,
                                            USBBLASTER_EPIN | \
                                            LIBUSB_ENDPOINT_IN,
                                            (char *)buf,
                                            size,
-                                           100);
-       return ERROR_OK;
+                                           100, &tmp);
+       *bytes_read = tmp;
+
+       return ret;
 }
 
 static int ublast2_libusb_write(struct ublast_lowlevel *low, uint8_t *buf,
                               int size, uint32_t *bytes_written)
 {
-       *bytes_written = jtag_libusb_bulk_write(low->libusb_dev,
+       int ret, tmp = 0;
+
+       ret = jtag_libusb_bulk_write(low->libusb_dev,
                                                USBBLASTER_EPOUT | \
                                                LIBUSB_ENDPOINT_OUT,
                                                (char *)buf,
                                                size,
-                                               100);
-       return ERROR_OK;
+                                               100, &tmp);
+       *bytes_written = tmp;
+
+       return ret;
+
 }
 
 static int ublast2_write_firmware_section(struct jtag_libusb_device_handle *libusb_dev,
@@ -74,9 +86,6 @@ static int ublast2_write_firmware_section(struct jtag_libusb_device_handle *libu
        LOG_DEBUG("section %02i at addr 0x%04x (size 0x%04x)", section_index, addr,
                size);
 
-       if (data == NULL)
-               return ERROR_FAIL;
-
        /* Copy section contents to local buffer */
        int ret = image_read_section(firmware_image, section_index, 0, size, data,
                        &size_read);
@@ -186,7 +195,7 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
        bool renumeration = false;
        int ret;
 
-       if (jtag_libusb_open(vids, pids, &temp) == ERROR_OK) {
+       if (jtag_libusb_open(vids, pids, NULL, &temp) == ERROR_OK) {
                LOG_INFO("Altera USB-Blaster II (uninitialized) found");
                LOG_INFO("Loading firmware...");
                ret = load_usb_blaster_firmware(temp, low);
@@ -200,13 +209,13 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
        const uint16_t pids_renum[] = { low->ublast_pid, 0 };
 
        if (renumeration == false) {
-               if (jtag_libusb_open(vids_renum, pids_renum, &low->libusb_dev) != ERROR_OK) {
+               if (jtag_libusb_open(vids_renum, pids_renum, NULL, &low->libusb_dev) != ERROR_OK) {
                        LOG_ERROR("Altera USB-Blaster II not found");
                        return ERROR_FAIL;
                }
        } else {
                int retry = 10;
-               while (jtag_libusb_open(vids_renum, pids_renum, &low->libusb_dev) != ERROR_OK && retry--) {
+               while (jtag_libusb_open(vids_renum, pids_renum, NULL, &low->libusb_dev) != ERROR_OK && retry--) {
                        usleep(1000000);
                        LOG_INFO("Waiting for renumerate...");
                }