X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fdfu.c;h=d23cf67f1942447b9f7f0842ca40623cbfb5db69;hb=2fa581ba910368d0f7f995fb906d6c5e4218b594;hp=07dff317a6c2708bb7f0deff133bae7f3bd8e11c;hpb=9b643e312d528f291966c1f30b0d90bf3b1d43dc;p=oweals%2Fu-boot.git diff --git a/common/dfu.c b/common/dfu.c index 07dff317a6..d23cf67f19 100644 --- a/common/dfu.c +++ b/common/dfu.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * dfu.c -- dfu command * @@ -7,11 +8,11 @@ * Copyright (C) 2012 Samsung Electronics * authors: Andrzej Pietrasiewicz * Lukasz Majewski - * - * SPDX-License-Identifier: GPL-2.0+ */ #include +#include +#include #include #include #include @@ -24,9 +25,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget) bool dfu_reset = false; int ret, i = 0; - ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE); + ret = usb_gadget_initialize(usbctrl_index); if (ret) { - pr_err("board usb init failed\n"); + pr_err("usb_gadget_initialize failed\n"); return CMD_RET_FAILURE; } g_dnl_clear_detach(); @@ -36,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()) { /* @@ -80,12 +85,25 @@ 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); } exit: g_dnl_unregister(); - board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE); + usb_gadget_release(usbctrl_index); if (dfu_reset) do_reset(NULL, 0, 0, NULL);