• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
do_dfu(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])21 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
22 {
23 
24 	if (argc < 2)
25 		return CMD_RET_USAGE;
26 
27 #ifdef CONFIG_DFU_OVER_USB
28 	char *usb_controller = argv[1];
29 #endif
30 #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
31 	char *interface = NULL;
32 	char *devstring = NULL;
33 
34 	if (argc >= 4) {
35 		interface = argv[2];
36 		devstring = argv[3];
37 	}
38 #endif
39 
40 	int ret = 0;
41 #ifdef CONFIG_DFU_OVER_TFTP
42 	unsigned long addr = 0;
43 	if (!strcmp(argv[1], "tftp")) {
44 		if (argc == 5 || argc == 3)
45 			addr = simple_strtoul(argv[argc - 1], NULL, 0);
46 
47 		return update_tftp(addr, interface, devstring);
48 	}
49 #endif
50 #ifdef CONFIG_DFU_OVER_USB
51 	ret = dfu_init_env_entities(interface, devstring);
52 	if (ret)
53 		goto done;
54 
55 	ret = CMD_RET_SUCCESS;
56 	if (strcmp(argv[argc - 1], "list") == 0) {
57 		dfu_show_entities();
58 		goto done;
59 	}
60 
61 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
62 
63 	run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
64 
65 done:
66 	dfu_free_entities();
67 #endif
68 	return ret;
69 }
70 
71 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
72 	"Device Firmware Upgrade",
73 	""
74 #ifdef CONFIG_DFU_OVER_USB
75 	"<USB_controller> [<interface> <dev>] [list]\n"
76 	"  - device firmware upgrade via <USB_controller>\n"
77 	"    on device <dev>, attached to interface\n"
78 	"    <interface>\n"
79 	"    [list] - list available alt settings\n"
80 #endif
81 #ifdef CONFIG_DFU_OVER_TFTP
82 #ifdef CONFIG_DFU_OVER_USB
83 	"dfu "
84 #endif
85 	"tftp [<interface> <dev>] [<addr>]\n"
86 	"  - device firmware upgrade via TFTP\n"
87 	"    on device <dev>, attached to interface\n"
88 	"    <interface>\n"
89 	"    [<addr>] - address where FIT image has been stored\n"
90 #endif
91 );
92