diff --git a/firehose.c b/firehose.c index 9f433f5..c43eb4a 100644 --- a/firehose.c +++ b/firehose.c @@ -228,7 +228,7 @@ static int firehose_write(struct qdl_device *qdl, xmlDoc *doc) for (;;) { ux_debug("FIREHOSE WRITE: %s\n", s); vip_gen_chunk_update(qdl, s, len); - ret = qdl_write(qdl, s, len); + ret = qdl_write(qdl, s, len, 1000); saved_errno = errno; /* @@ -560,7 +560,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int vip_transfer_clear_status(qdl); } - n = qdl_write(qdl, buf, chunk_size * sector_size); + n = qdl_write(qdl, buf, chunk_size * sector_size, 10000); if (n < 0) { ux_err("USB write failed for data chunk\n"); ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL); diff --git a/io.c b/io.c index a4bb0f6..131c620 100644 --- a/io.c +++ b/io.c @@ -58,11 +58,12 @@ int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout * @qdl: device handle * @buf: buffer with data to be written * @len: length of data to be written + * @timeout: timeout for write, in milliseconds * * Returns: number of bytes read * negative errno on failure (notably -ETIMEDOUT) */ -int qdl_write(struct qdl_device *qdl, const void *buf, size_t len) +int qdl_write(struct qdl_device *qdl, const void *buf, size_t len, unsigned int timeout) { - return qdl->write(qdl, buf, len); + return qdl->write(qdl, buf, len, timeout); } diff --git a/ks.c b/ks.c index 5b000c1..03c6e8c 100644 --- a/ks.c +++ b/ks.c @@ -29,7 +29,7 @@ int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout return read(qdl->fd, buf, len); } -int qdl_write(struct qdl_device *qdl, const void *buf, size_t len) +int qdl_write(struct qdl_device *qdl, const void *buf, size_t len, unsigned int timeout) { return write(qdl->fd, buf, len); } diff --git a/qdl.h b/qdl.h index 9e112da..d1858bd 100644 --- a/qdl.h +++ b/qdl.h @@ -43,7 +43,7 @@ struct qdl_device { int (*open)(struct qdl_device *qdl, const char *serial); int (*read)(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout); - int (*write)(struct qdl_device *qdl, const void *buf, size_t nbytes); + int (*write)(struct qdl_device *qdl, const void *buf, size_t nbytes, unsigned int timeout); void (*close)(struct qdl_device *qdl); void (*set_out_chunk_size)(struct qdl_device *qdl, long size); void (*set_vip_transfer)(struct qdl_device *qdl, const char *signed_table, @@ -61,7 +61,7 @@ void qdl_deinit(struct qdl_device *qdl); int qdl_open(struct qdl_device *qdl, const char *serial); void qdl_close(struct qdl_device *qdl); int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout); -int qdl_write(struct qdl_device *qdl, const void *buf, size_t len); +int qdl_write(struct qdl_device *qdl, const void *buf, size_t len, unsigned int timeout); void qdl_set_out_chunk_size(struct qdl_device *qdl, long size); int qdl_vip_transfer_enable(struct qdl_device *qdl, const char *vip_table_path); diff --git a/sahara.c b/sahara.c index f14075c..d133471 100644 --- a/sahara.c +++ b/sahara.c @@ -60,6 +60,8 @@ #define DEBUG_BLOCK_SIZE (512 * 1024) +#define SAHARA_CMD_TIMEOUT_MS 1000 + struct sahara_pkt { uint32_t cmd; uint32_t length; @@ -120,7 +122,7 @@ static void sahara_send_reset(struct qdl_device *qdl) resp.cmd = SAHARA_RESET_CMD; resp.length = SAHARA_RESET_LENGTH; - qdl_write(qdl, &resp, resp.length); + qdl_write(qdl, &resp, resp.length, SAHARA_CMD_TIMEOUT_MS); } static void sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt) @@ -139,7 +141,7 @@ static void sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt) resp.hello_resp.status = SAHARA_SUCCESS; resp.hello_resp.mode = pkt->hello_req.mode; - qdl_write(qdl, &resp, resp.length); + qdl_write(qdl, &resp, resp.length, SAHARA_CMD_TIMEOUT_MS); } static int sahara_read_common(struct qdl_device *qdl, int progfd, off_t offset, size_t len) @@ -159,7 +161,7 @@ static int sahara_read_common(struct qdl_device *qdl, int progfd, off_t offset, goto out; } - n = qdl_write(qdl, buf, n); + n = qdl_write(qdl, buf, n, SAHARA_CMD_TIMEOUT_MS); if (n != len) err(1, "failed to write %zu bytes to sahara", len); @@ -259,7 +261,7 @@ static void sahara_eoi(struct qdl_device *qdl, struct sahara_pkt *pkt) done.cmd = SAHARA_DONE_CMD; done.length = SAHARA_DONE_LENGTH; - qdl_write(qdl, &done, done.length); + qdl_write(qdl, &done, done.length, SAHARA_CMD_TIMEOUT_MS); } static int sahara_done(struct qdl_device *qdl, struct sahara_pkt *pkt) @@ -309,7 +311,7 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl, read_req.length = SAHARA_MEM_READ64_LENGTH; read_req.debug64_req.addr = region.addr + chunk; read_req.debug64_req.length = remain; - n = qdl_write(qdl, &read_req, read_req.length); + n = qdl_write(qdl, &read_req, read_req.length, SAHARA_CMD_TIMEOUT_MS); if (n < 0) break; @@ -405,13 +407,13 @@ static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt, read_req.debug64_req.addr = pkt->debug64_req.addr; read_req.debug64_req.length = pkt->debug64_req.length; - n = qdl_write(qdl, &read_req, read_req.length); + n = qdl_write(qdl, &read_req, read_req.length, SAHARA_CMD_TIMEOUT_MS); if (n < 0) return; table = malloc(read_req.debug64_req.length); - n = qdl_read(qdl, table, pkt->debug64_req.length, 1000); + n = qdl_read(qdl, table, pkt->debug64_req.length, SAHARA_CMD_TIMEOUT_MS); if (n < 0) return; @@ -451,7 +453,7 @@ int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image, return 0; while (!done) { - n = qdl_read(qdl, buf, sizeof(buf), 1000); + n = qdl_read(qdl, buf, sizeof(buf), SAHARA_CMD_TIMEOUT_MS); if (n < 0) { ux_err("failed to read sahara request from device\n"); break; diff --git a/sim.c b/sim.c index ac117e2..8969f7d 100644 --- a/sim.c +++ b/sim.c @@ -27,7 +27,7 @@ static int sim_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int return len; } -static int sim_write(struct qdl_device *qdl, const void *buf, size_t len) +static int sim_write(struct qdl_device *qdl, const void *buf, size_t len, unsigned int timeout) { return len; } diff --git a/usb.c b/usb.c index 8e31253..83fbaad 100644 --- a/usb.c +++ b/usb.c @@ -247,7 +247,7 @@ static int usb_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int return actual; } -static int usb_write(struct qdl_device *qdl, const void *buf, size_t len) +static int usb_write(struct qdl_device *qdl, const void *buf, size_t len, unsigned int timeout) { unsigned char *data = (unsigned char *)buf; struct qdl_device_usb *qdl_usb = container_of(qdl, struct qdl_device_usb, base); @@ -261,7 +261,7 @@ static int usb_write(struct qdl_device *qdl, const void *buf, size_t len) xfer = (len > qdl_usb->out_chunk_size) ? qdl_usb->out_chunk_size : len; ret = libusb_bulk_transfer(qdl_usb->usb_handle, qdl_usb->out_ep, data, - xfer, &actual, 1000); + xfer, &actual, timeout); if (ret != 0 && ret != LIBUSB_ERROR_TIMEOUT) { warnx("bulk write failed: %s", libusb_strerror(ret)); return -EIO; @@ -276,7 +276,7 @@ static int usb_write(struct qdl_device *qdl, const void *buf, size_t len) if (len_orig % qdl_usb->out_maxpktsize == 0) { ret = libusb_bulk_transfer(qdl_usb->usb_handle, qdl_usb->out_ep, NULL, - 0, &actual, 1000); + 0, &actual, timeout); if (ret < 0) return -EIO; } diff --git a/vip.c b/vip.c index 29f6d9b..f911fb8 100644 --- a/vip.c +++ b/vip.c @@ -432,7 +432,7 @@ static int vip_transfer_send_raw(struct qdl_device *qdl, int table_fd) goto out; } - n = qdl_write(qdl, buf, sb.st_size); + n = qdl_write(qdl, buf, sb.st_size, 1000); if (n < 0) { ux_err("USB write failed for data chunk\n"); ret = -1;