common/xyzModem.c: move empty statements to newline
[platform/kernel/u-boot.git] / 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 <dfu.h>
13 #include <g_dnl.h>
14 #include <usb.h>
15
16 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17 {
18         if (argc < 4)
19                 return CMD_RET_USAGE;
20
21         char *usb_controller = argv[1];
22         char *interface = argv[2];
23         char *devstring = argv[3];
24
25         int ret, i = 0;
26
27         ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
28                                                               NULL, 10));
29         if (ret)
30                 return ret;
31
32         if (argc > 4 && strcmp(argv[4], "list") == 0) {
33                 dfu_show_entities();
34                 goto done;
35         }
36
37         int controller_index = simple_strtoul(usb_controller, NULL, 0);
38         board_usb_init(controller_index, USB_INIT_DEVICE);
39
40         g_dnl_register("usb_dnl_dfu");
41         while (1) {
42                 if (dfu_reset())
43                         /*
44                          * This extra number of usb_gadget_handle_interrupts()
45                          * calls is necessary to assure correct transmission
46                          * completion with dfu-util
47                          */
48                         if (++i == 10)
49                                 goto exit;
50
51                 if (ctrlc())
52                         goto exit;
53
54                 usb_gadget_handle_interrupts();
55         }
56 exit:
57         g_dnl_unregister();
58 done:
59         dfu_free_entities();
60
61         if (dfu_reset())
62                 run_command("reset", 0);
63
64         return CMD_RET_SUCCESS;
65 }
66
67 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
68         "Device Firmware Upgrade",
69         "<USB_controller> <interface> <dev> [list]\n"
70         "  - device firmware upgrade via <USB_controller>\n"
71         "    on device <dev>, attached to interface\n"
72         "    <interface>\n"
73         "    [list] - list available alt settings\n"
74 );