Convert CONFIG_SYS_FSL_SEC_MON et al to Kconfig
[platform/kernel/u-boot.git] / common / dfu.c
index 44d1484..16bd1ba 100644 (file)
@@ -11,6 +11,8 @@
  */
 
 #include <common.h>
+#include <command.h>
+#include <log.h>
 #include <watchdog.h>
 #include <dfu.h>
 #include <console.h>
@@ -35,6 +37,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 +85,22 @@ 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
+
+               if (dfu_reinit_needed)
+                       goto exit;
+
                WATCHDOG_RESET();
                usb_gadget_handle_interrupts(usbctrl_index);
        }