blob: 7ce92cec87f4fcb156b2d84ff487cb319635f6a4 [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>
14
15static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
16{
Albert ARIBAUDb823fd92012-10-09 09:28:15 +000017 char *s = "dfu";
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020018 int ret, i = 0;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020019
20 if (argc < 3)
21 return CMD_RET_USAGE;
22
Lukasz Majewski765c5ae2013-09-11 14:53:35 +020023 ret = dfu_init_env_entities(argv[1], simple_strtoul(argv[2], NULL, 10));
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020024 if (ret)
Lukasz Majewski765c5ae2013-09-11 14:53:35 +020025 return ret;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020026
Pantelis Antonioudf93cd92012-11-30 08:01:08 +000027 if (argc > 3 && strcmp(argv[3], "list") == 0) {
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020028 dfu_show_entities();
29 goto done;
30 }
31
Pantelis Antoniouea3e2122012-11-30 08:01:07 +000032#ifdef CONFIG_TRATS
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020033 board_usb_init();
Pantelis Antoniouea3e2122012-11-30 08:01:07 +000034#endif
35
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020036 g_dnl_register(s);
37 while (1) {
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020038 if (dfu_reset())
39 /*
40 * This extra number of usb_gadget_handle_interrupts()
41 * calls is necessary to assure correct transmission
42 * completion with dfu-util
43 */
44 if (++i == 10)
45 goto exit;
46
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020047 if (ctrlc())
48 goto exit;
49
50 usb_gadget_handle_interrupts();
51 }
52exit:
53 g_dnl_unregister();
54done:
55 dfu_free_entities();
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020056
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020057 if (dfu_reset())
58 run_command("reset", 0);
59
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020060 return CMD_RET_SUCCESS;
61}
62
63U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
64 "Device Firmware Upgrade",
65 "<interface> <dev> [list]\n"
66 " - device firmware upgrade on a device <dev>\n"
67 " attached to interface <interface>\n"
68 " [list] - list available alt settings"
69);