]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dfu: Implementation of target reset after communication with dfu-util's -R switch
authorLukasz Majewski <l.majewski@samsung.com>
Thu, 18 Jul 2013 11:19:14 +0000 (13:19 +0200)
committerMarek Vasut <marex@denx.de>
Mon, 29 Jul 2013 21:01:33 +0000 (23:01 +0200)
This patch extends dfu code to support transmission with -R switch
specified at dfu-util.

When -R is specified, the extra USB_REQ_DFU_DETACH request is sent after
successful data transmission. Then dfu resources are released and reset
command is issued.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
common/cmd_dfu.c
drivers/dfu/dfu.c
drivers/usb/gadget/f_dfu.c
include/dfu.h

index db066acc364b5989b1e7333dbac1c26106f5d32e..793c42212369a85d11047d7315e0f386e77c0e05 100644 (file)
@@ -19,8 +19,8 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        const char *str_env;
        char *s = "dfu";
+       int ret, i = 0;
        char *env_bkp;
-       int ret;
 
        if (argc < 3)
                return CMD_RET_USAGE;
@@ -49,6 +49,15 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        g_dnl_register(s);
        while (1) {
+               if (dfu_reset())
+                       /*
+                        * This extra number of usb_gadget_handle_interrupts()
+                        * calls is necessary to assure correct transmission
+                        * completion with dfu-util
+                        */
+                       if (++i == 10)
+                               goto exit;
+
                if (ctrlc())
                        goto exit;
 
@@ -60,6 +69,9 @@ done:
        dfu_free_entities();
        free(env_bkp);
 
+       if (dfu_reset())
+               run_command("reset", 0);
+
        return CMD_RET_SUCCESS;
 }
 
index b8870ecf7309bba6215bb0ecff0e2e8b79a8f17b..d73d5103919662e8a8c044be35922e4bed33dec4 100644 (file)
 #include <linux/list.h>
 #include <linux/compiler.h>
 
+static bool dfu_reset_request;
 static LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 
+bool dfu_reset(void)
+{
+       return dfu_reset_request;
+}
+
+void dfu_trigger_reset()
+{
+       dfu_reset_request = true;
+}
+
 static int dfu_find_alt_num(const char *s)
 {
        int i = 0;
index 5321a689d4dc3905651fade571dd27fcb8b5dc2a..37d04a19285e605a6d4e34ae9b54b989eca28891 100644 (file)
@@ -312,6 +312,8 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
                        DFU_STATE_dfuMANIFEST_WAIT_RST;
                to_runtime_mode(f_dfu);
                f_dfu->dfu_state = DFU_STATE_appIDLE;
+
+               dfu_trigger_reset();
                break;
        default:
                f_dfu->dfu_state = DFU_STATE_dfuERROR;
index 6c7d2271371ebfb4f8c2dd52dab8f904e769d920..1d4006de8bab3f31bb119fe45b477c7d432d6bcc 100644 (file)
@@ -109,6 +109,8 @@ const char *dfu_get_dev_type(enum dfu_device_type t);
 const char *dfu_get_layout(enum dfu_layout l);
 struct dfu_entity *dfu_get_entity(int alt);
 char *dfu_extract_token(char** e, int *n);
+void dfu_trigger_reset(void);
+bool dfu_reset(void);
 
 int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
 int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);