]> git.sur5r.net Git - u-boot/blob - common/cmd_dfu.c
dm: Sort the uclass IDs after the tegra/PMIC addition
[u-boot] / common / cmd_dfu.c
1 /*
2  * cmd_dfu.c -- dfu command
3  *
4  * Copyright (C) 2012 Samsung Electronics
5  * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
6  *          Lukasz Majewski <l.majewski@samsung.com>
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <watchdog.h>
13 #include <dfu.h>
14 #include <g_dnl.h>
15 #include <usb.h>
16
17 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
18 {
19         bool dfu_reset = false;
20
21         if (argc < 4)
22                 return CMD_RET_USAGE;
23
24         char *usb_controller = argv[1];
25         char *interface = argv[2];
26         char *devstring = argv[3];
27
28         int ret, i = 0;
29
30         ret = dfu_init_env_entities(interface, devstring);
31         if (ret)
32                 goto done;
33
34         ret = CMD_RET_SUCCESS;
35         if (argc > 4 && strcmp(argv[4], "list") == 0) {
36                 dfu_show_entities();
37                 goto done;
38         }
39
40         int controller_index = simple_strtoul(usb_controller, NULL, 0);
41         board_usb_init(controller_index, USB_INIT_DEVICE);
42         g_dnl_clear_detach();
43         g_dnl_register("usb_dnl_dfu");
44         while (1) {
45                 if (g_dnl_detach()) {
46                         /*
47                          * Check if USB bus reset is performed after detach,
48                          * which indicates that -R switch has been passed to
49                          * dfu-util. In this case reboot the device
50                          */
51                         if (dfu_usb_get_reset()) {
52                                 dfu_reset = true;
53                                 goto exit;
54                         }
55
56                         /*
57                          * This extra number of usb_gadget_handle_interrupts()
58                          * calls is necessary to assure correct transmission
59                          * completion with dfu-util
60                          */
61                         if (++i == 10000)
62                                 goto exit;
63                 }
64
65                 if (ctrlc())
66                         goto exit;
67
68                 WATCHDOG_RESET();
69                 usb_gadget_handle_interrupts(controller_index);
70         }
71 exit:
72         g_dnl_unregister();
73         board_usb_cleanup(controller_index, USB_INIT_DEVICE);
74 done:
75         dfu_free_entities();
76
77         if (dfu_reset)
78                 run_command("reset", 0);
79
80         g_dnl_clear_detach();
81
82         return ret;
83 }
84
85 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
86         "Device Firmware Upgrade",
87         "<USB_controller> <interface> <dev> [list]\n"
88         "  - device firmware upgrade via <USB_controller>\n"
89         "    on device <dev>, attached to interface\n"
90         "    <interface>\n"
91         "    [list] - list available alt settings\n"
92 );