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