xref: /openbmc/u-boot/cmd/dfu.c (revision aa5e3e22)
1 /*
2  * cmd_dfu.c -- dfu command
3  *
4  * Copyright (C) 2015
5  * Lukasz Majewski <l.majewski@majess.pl>
6  *
7  * Copyright (C) 2012 Samsung Electronics
8  * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
9  *	    Lukasz Majewski <l.majewski@samsung.com>
10  *
11  * SPDX-License-Identifier:	GPL-2.0+
12  */
13 
14 #include <common.h>
15 #include <watchdog.h>
16 #include <dfu.h>
17 #include <console.h>
18 #include <g_dnl.h>
19 #include <usb.h>
20 #include <net.h>
21 
22 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23 {
24 
25 	if (argc < 4)
26 		return CMD_RET_USAGE;
27 
28 #ifdef CONFIG_DFU_OVER_USB
29 	char *usb_controller = argv[1];
30 #endif
31 	char *interface = argv[2];
32 	char *devstring = argv[3];
33 
34 	int ret = 0;
35 #ifdef CONFIG_DFU_OVER_TFTP
36 	unsigned long addr = 0;
37 	if (!strcmp(argv[1], "tftp")) {
38 		if (argc == 5)
39 			addr = simple_strtoul(argv[4], NULL, 0);
40 
41 		return update_tftp(addr, interface, devstring);
42 	}
43 #endif
44 #ifdef CONFIG_DFU_OVER_USB
45 	ret = dfu_init_env_entities(interface, devstring);
46 	if (ret)
47 		goto done;
48 
49 	ret = CMD_RET_SUCCESS;
50 	if (argc > 4 && strcmp(argv[4], "list") == 0) {
51 		dfu_show_entities();
52 		goto done;
53 	}
54 
55 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
56 
57 	run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
58 
59 done:
60 	dfu_free_entities();
61 #endif
62 	return ret;
63 }
64 
65 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
66 	"Device Firmware Upgrade",
67 #ifdef CONFIG_DFU_OVER_USB
68 	"<USB_controller> <interface> <dev> [list]\n"
69 	"  - device firmware upgrade via <USB_controller>\n"
70 	"    on device <dev>, attached to interface\n"
71 	"    <interface>\n"
72 	"    [list] - list available alt settings\n"
73 #endif
74 #ifdef CONFIG_DFU_OVER_TFTP
75 #ifdef CONFIG_DFU_OVER_USB
76 	"dfu "
77 #endif
78 	"tftp <interface> <dev> [<addr>]\n"
79 	"  - device firmware upgrade via TFTP\n"
80 	"    on device <dev>, attached to interface\n"
81 	"    <interface>\n"
82 	"    [<addr>] - address where FIT image has been stored\n"
83 #endif
84 );
85