]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_dfu.c
Merge 'u-boot-microblaze/zynq' into (u-boot-arm/master'
[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>
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{
20 const char *str_env;
b823fd9b 21 char *s = "dfu";
6bed7ce5 22 int ret, i = 0;
a006a5de 23 char *env_bkp;
a006a5de
ŁM
24
25 if (argc < 3)
26 return CMD_RET_USAGE;
27
28 str_env = getenv("dfu_alt_info");
29 if (str_env == NULL) {
30 printf("%s: \"dfu_alt_info\" env variable not defined!\n",
31 __func__);
32 return CMD_RET_FAILURE;
33 }
34
35 env_bkp = strdup(str_env);
36 ret = dfu_config_entities(env_bkp, argv[1],
37 (int)simple_strtoul(argv[2], NULL, 10));
38 if (ret)
39 return CMD_RET_FAILURE;
40
df93cd9c 41 if (argc > 3 && strcmp(argv[3], "list") == 0) {
a006a5de
ŁM
42 dfu_show_entities();
43 goto done;
44 }
45
ea3e2122 46#ifdef CONFIG_TRATS
a006a5de 47 board_usb_init();
ea3e2122
PA
48#endif
49
a006a5de
ŁM
50 g_dnl_register(s);
51 while (1) {
6bed7ce5
ŁM
52 if (dfu_reset())
53 /*
54 * This extra number of usb_gadget_handle_interrupts()
55 * calls is necessary to assure correct transmission
56 * completion with dfu-util
57 */
58 if (++i == 10)
59 goto exit;
60
a006a5de
ŁM
61 if (ctrlc())
62 goto exit;
63
64 usb_gadget_handle_interrupts();
65 }
66exit:
67 g_dnl_unregister();
68done:
69 dfu_free_entities();
70 free(env_bkp);
71
6bed7ce5
ŁM
72 if (dfu_reset())
73 run_command("reset", 0);
74
a006a5de
ŁM
75 return CMD_RET_SUCCESS;
76}
77
78U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
79 "Device Firmware Upgrade",
80 "<interface> <dev> [list]\n"
81 " - device firmware upgrade on a device <dev>\n"
82 " attached to interface <interface>\n"
83 " [list] - list available alt settings"
84);