Merge tag 'for-v2020.07' of https://gitlab.denx.de/u-boot/custodians/u-boot-ubi
[oweals/u-boot.git] / common / dfu.c
index 44d1484d3d277f5b17c4dce7c36d90ce78de6c51..da6289b218dd2aa66e1c6d91ee4b5bf25eedc637 100644 (file)
@@ -35,6 +35,10 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
                return CMD_RET_FAILURE;
        }
 
+#ifdef CONFIG_DFU_TIMEOUT
+       unsigned long start_time = get_timer(0);
+#endif
+
        while (1) {
                if (g_dnl_detach()) {
                        /*
@@ -79,6 +83,19 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
                        }
                }
 
+#ifdef CONFIG_DFU_TIMEOUT
+               unsigned long wait_time = dfu_get_timeout();
+
+               if (wait_time) {
+                       unsigned long current_time = get_timer(start_time);
+
+                       if (current_time > wait_time) {
+                               debug("Inactivity timeout, abort DFU\n");
+                               goto exit;
+                       }
+               }
+#endif
+
                WATCHDOG_RESET();
                usb_gadget_handle_interrupts(usbctrl_index);
        }