2 * cmd_dfu.c -- dfu command
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+
21 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23 bool dfu_reset = false;
28 char *usb_controller = argv[1];
29 char *interface = argv[2];
30 char *devstring = argv[3];
33 #ifdef CONFIG_DFU_TFTP
34 unsigned long addr = 0;
35 if (!strcmp(argv[1], "tftp")) {
37 addr = simple_strtoul(argv[4], NULL, 0);
39 return update_tftp(addr, interface, devstring);
43 ret = dfu_init_env_entities(interface, devstring);
47 ret = CMD_RET_SUCCESS;
48 if (argc > 4 && strcmp(argv[4], "list") == 0) {
53 int controller_index = simple_strtoul(usb_controller, NULL, 0);
54 board_usb_init(controller_index, USB_INIT_DEVICE);
56 g_dnl_register("usb_dnl_dfu");
60 * Check if USB bus reset is performed after detach,
61 * which indicates that -R switch has been passed to
62 * dfu-util. In this case reboot the device
64 if (dfu_usb_get_reset()) {
70 * This extra number of usb_gadget_handle_interrupts()
71 * calls is necessary to assure correct transmission
72 * completion with dfu-util
82 usb_gadget_handle_interrupts(controller_index);
86 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
91 run_command("reset", 0);
98 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
99 "Device Firmware Upgrade",
100 "<USB_controller> <interface> <dev> [list]\n"
101 " - device firmware upgrade via <USB_controller>\n"
102 " on device <dev>, attached to interface\n"
104 " [list] - list available alt settings\n"
105 #ifdef CONFIG_DFU_TFTP
106 "dfu tftp <interface> <dev> [<addr>]\n"
107 " - device firmware upgrade via TFTP\n"
108 " on device <dev>, attached to interface\n"
110 " [<addr>] - address where FIT image has been stored\n"