blob: d3658cf7ee93cc39e3d64951ab586f6b64a81f53 [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>
12#include <command.h>
13#include <malloc.h>
14#include <dfu.h>
15#include <asm/errno.h>
16#include <g_dnl.h>
17
18static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
19{
Albert ARIBAUDb823fd92012-10-09 09:28:15 +000020 char *s = "dfu";
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020021 int ret, i = 0;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020022
23 if (argc < 3)
24 return CMD_RET_USAGE;
25
Lukasz Majewski765c5ae2013-09-11 14:53:35 +020026 ret = dfu_init_env_entities(argv[1], simple_strtoul(argv[2], NULL, 10));
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020027 if (ret)
Lukasz Majewski765c5ae2013-09-11 14:53:35 +020028 return ret;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020029
Pantelis Antonioudf93cd92012-11-30 08:01:08 +000030 if (argc > 3 && strcmp(argv[3], "list") == 0) {
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020031 dfu_show_entities();
32 goto done;
33 }
34
Pantelis Antoniouea3e2122012-11-30 08:01:07 +000035#ifdef CONFIG_TRATS
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020036 board_usb_init();
Pantelis Antoniouea3e2122012-11-30 08:01:07 +000037#endif
38
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020039 g_dnl_register(s);
40 while (1) {
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020041 if (dfu_reset())
42 /*
43 * This extra number of usb_gadget_handle_interrupts()
44 * calls is necessary to assure correct transmission
45 * completion with dfu-util
46 */
47 if (++i == 10)
48 goto exit;
49
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020050 if (ctrlc())
51 goto exit;
52
53 usb_gadget_handle_interrupts();
54 }
55exit:
56 g_dnl_unregister();
57done:
58 dfu_free_entities();
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020059
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020060 if (dfu_reset())
61 run_command("reset", 0);
62
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020063 return CMD_RET_SUCCESS;
64}
65
66U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
67 "Device Firmware Upgrade",
68 "<interface> <dev> [list]\n"
69 " - device firmware upgrade on a device <dev>\n"
70 " attached to interface <interface>\n"
71 " [list] - list available alt settings"
72);