5 * Lukasz Majewski <l.majewski@majess.pl>
7 * Copyright (C) 2012 Samsung Electronics
8 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
9 * Lukasz Majewski <l.majewski@samsung.com>
11 * SPDX-License-Identifier: GPL-2.0+
22 int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
24 bool dfu_reset = false;
27 board_usb_init(usbctrl_index, USB_INIT_DEVICE);
29 ret = g_dnl_register(usb_dnl_gadget);
31 error("g_dnl_register failed");
32 return CMD_RET_FAILURE;
38 * Check if USB bus reset is performed after detach,
39 * which indicates that -R switch has been passed to
40 * dfu-util. In this case reboot the device
42 if (dfu_usb_get_reset()) {
48 * This extra number of usb_gadget_handle_interrupts()
49 * calls is necessary to assure correct transmission
50 * completion with dfu-util
59 if (dfu_get_defer_flush()) {
61 * Call to usb_gadget_handle_interrupts() is necessary
62 * to act on ZLP OUT transaction from HOST PC after
63 * transmitting the whole file.
65 * If this ZLP OUT packet is NAK'ed, the HOST libusb
66 * function fails after timeout (by default it is set to
67 * 5 seconds). In such situation the dfu-util program
68 * exits with error message.
70 usb_gadget_handle_interrupts(usbctrl_index);
71 ret = dfu_flush(dfu_get_defer_flush(), NULL, 0, 0);
72 dfu_set_defer_flush(NULL);
74 error("Deferred dfu_flush() failed!");
80 usb_gadget_handle_interrupts(usbctrl_index);
84 board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE);
87 run_command("reset", 0);