blob: 433bddd5d2bdc83d9cf06fa943a44c08d9bba701 [file] [log] [blame]
Lukasz Majewskia006a5d2012-08-06 14:41:09 +02001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskia006a5d2012-08-06 14:41:09 +02009 */
10
11#include <common.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020012#include <dfu.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020013#include <g_dnl.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020014#include <usb.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020015
16static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17{
Mateusz Zalega16297cf2013-10-04 19:22:26 +020018 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
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020025 int ret, i = 0;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020026
Mateusz Zalega16297cf2013-10-04 19:22:26 +020027 ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
28 NULL, 10));
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020029 if (ret)
Stephen Warrenafb8e712014-06-10 10:06:41 -060030 goto done;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020031
Stephen Warrenafb8e712014-06-10 10:06:41 -060032 ret = CMD_RET_SUCCESS;
Mateusz Zalega16297cf2013-10-04 19:22:26 +020033 if (argc > 4 && strcmp(argv[4], "list") == 0) {
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020034 dfu_show_entities();
35 goto done;
36 }
37
Mateusz Zalega16297cf2013-10-04 19:22:26 +020038 int controller_index = simple_strtoul(usb_controller, NULL, 0);
39 board_usb_init(controller_index, USB_INIT_DEVICE);
Pantelis Antoniouea3e2122012-11-30 08:01:07 +000040
Mateusz Zalegac4d0e852014-04-28 21:13:28 +020041 g_dnl_register("usb_dnl_dfu");
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020042 while (1) {
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020043 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
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020052 if (ctrlc())
53 goto exit;
54
55 usb_gadget_handle_interrupts();
56 }
57exit:
58 g_dnl_unregister();
59done:
60 dfu_free_entities();
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020061
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020062 if (dfu_reset())
63 run_command("reset", 0);
64
Stephen Warrenafb8e712014-06-10 10:06:41 -060065 return ret;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020066}
67
68U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
69 "Device Firmware Upgrade",
Mateusz Zalega16297cf2013-10-04 19:22:26 +020070 "<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"
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020075);