diff options
author | Stephen Warren <swarren@nvidia.com> | 2014-06-11 12:48:08 -0600 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-08-09 11:16:58 -0400 |
commit | 3ee9593fce0b58124e667734d7bc8d44b11a7be2 (patch) | |
tree | f47521946be94b9ba599c30abdc85f88916d8ca4 /drivers/usb | |
parent | 0e285b503c41bb53f6ef962e6f9c942c1ca47cc6 (diff) |
dfu: add write error handling
Fix calls to dfu_write() and dfu_flush() to detect errors in the I/O
itself. This could happen due to problems with the storage medium, or
simply when trying to write a FAT/ext file that is larger than the buffer
dfu_mmc.c maintains for this purpose.
Signal the error by switching the DFU state/status. This will be picked
up by the DFU client when it sends the next DFU request. Note that errors
can't simply be returned from e.g. dnload_request_complete(), since that
function has no way to pass errors back to the DFU client; a call to
dnload_request_complete() simply means that a USB OUT completed.
This error state/status needs to be cleared when the next DFU client
connects. While there is a DFU_CLRSTATUS request, no DFU client seems to
send this. Hence, clear this when selecting the USB alternate setting on
the USB interface.
Finally, dfu.c relies on a call to dfu_flush() to clear up the internal
state of the write transaction. Now that errors in dfu_write() are
detected, dfu_flush() may no longer be called for every transaction.
Separate out the cleanup code into a new function, and call it whenever
dfu_write() fails, as well as from any call to dfu_flush().
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/f_dfu.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c index 859fe828de..9863dec44d 100644 --- a/drivers/usb/gadget/f_dfu.c +++ b/drivers/usb/gadget/f_dfu.c @@ -162,17 +162,27 @@ static void dfu_set_poll_timeout(struct dfu_status *dstat, unsigned int ms) static void dnload_request_complete(struct usb_ep *ep, struct usb_request *req) { struct f_dfu *f_dfu = req->context; + int ret; - dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf, - req->length, f_dfu->blk_seq_num); + ret = dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf, + req->length, f_dfu->blk_seq_num); + if (ret) { + f_dfu->dfu_status = DFU_STATUS_errUNKNOWN; + f_dfu->dfu_state = DFU_STATE_dfuERROR; + } } static void dnload_request_flush(struct usb_ep *ep, struct usb_request *req) { struct f_dfu *f_dfu = req->context; + int ret; - dfu_flush(dfu_get_entity(f_dfu->altsetting), req->buf, - req->length, f_dfu->blk_seq_num); + ret = dfu_flush(dfu_get_entity(f_dfu->altsetting), req->buf, + req->length, f_dfu->blk_seq_num); + if (ret) { + f_dfu->dfu_status = DFU_STATUS_errUNKNOWN; + f_dfu->dfu_state = DFU_STATE_dfuERROR; + } } static inline int dfu_get_manifest_timeout(struct dfu_entity *dfu) @@ -770,6 +780,8 @@ static int dfu_set_alt(struct usb_function *f, unsigned intf, unsigned alt) debug("%s: intf:%d alt:%d\n", __func__, intf, alt); f_dfu->altsetting = alt; + f_dfu->dfu_state = DFU_STATE_dfuIDLE; + f_dfu->dfu_status = DFU_STATUS_OK; return 0; } |