]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_dfu.c
boards.cfg: re-claim ownership for TQM8xx boards
[people/ms/u-boot.git] / common / cmd_dfu.c
CommitLineData
a006a5de
ŁM
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 *
1a459660 8 * SPDX-License-Identifier: GPL-2.0+
a006a5de
ŁM
9 */
10
11#include <common.h>
a006a5de 12#include <dfu.h>
a006a5de 13#include <g_dnl.h>
16297cfb 14#include <usb.h>
a006a5de
ŁM
15
16static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17{
16297cfb
MZ
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
6bed7ce5 25 int ret, i = 0;
a006a5de 26
16297cfb
MZ
27 ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
28 NULL, 10));
a006a5de 29 if (ret)
afb8e71c 30 goto done;
a006a5de 31
afb8e71c 32 ret = CMD_RET_SUCCESS;
16297cfb 33 if (argc > 4 && strcmp(argv[4], "list") == 0) {
a006a5de
ŁM
34 dfu_show_entities();
35 goto done;
36 }
37
16297cfb
MZ
38 int controller_index = simple_strtoul(usb_controller, NULL, 0);
39 board_usb_init(controller_index, USB_INIT_DEVICE);
ea3e2122 40
c4d0e856 41 g_dnl_register("usb_dnl_dfu");
a006a5de 42 while (1) {
6bed7ce5
ŁM
43 if (dfu_reset())
44 /*
45 * This extra number of usb_gadget_handle_interrupts()
46 * calls is necessary to assure correct transmission
47 * completion with dfu-util
48 */
49 if (++i == 10)
50 goto exit;
51
a006a5de
ŁM
52 if (ctrlc())
53 goto exit;
54
55 usb_gadget_handle_interrupts();
56 }
57exit:
58 g_dnl_unregister();
59done:
60 dfu_free_entities();
a006a5de 61
6bed7ce5
ŁM
62 if (dfu_reset())
63 run_command("reset", 0);
64
afb8e71c 65 return ret;
a006a5de
ŁM
66}
67
68U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
69 "Device Firmware Upgrade",
16297cfb
MZ
70 "<USB_controller> <interface> <dev> [list]\n"
71 " - device firmware upgrade via <USB_controller>\n"
72 " on device <dev>, attached to interface\n"
73 " <interface>\n"
74 " [list] - list available alt settings\n"
a006a5de 75);