rockchip: Remove ARCH= references from documentation
[oweals/u-boot.git] / cmd / dfu.c
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 <command.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(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
23 {
24
25         if (argc < 2)
26                 return CMD_RET_USAGE;
27
28 #ifdef CONFIG_DFU_OVER_USB
29         char *usb_controller = argv[1];
30 #endif
31 #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
32         char *interface = NULL;
33         char *devstring = NULL;
34 #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
35         unsigned long value = 0;
36 #endif
37
38         if (argc >= 4) {
39                 interface = argv[2];
40                 devstring = argv[3];
41         }
42
43 #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
44         if (argc == 5 || argc == 3)
45                 value = simple_strtoul(argv[argc - 1], NULL, 0);
46 #endif
47 #endif
48
49         int ret = 0;
50 #ifdef CONFIG_DFU_OVER_TFTP
51         if (!strcmp(argv[1], "tftp"))
52                 return update_tftp(value, interface, devstring);
53 #endif
54 #ifdef CONFIG_DFU_OVER_USB
55         ret = dfu_init_env_entities(interface, devstring);
56         if (ret)
57                 goto done;
58
59 #ifdef CONFIG_DFU_TIMEOUT
60         dfu_set_timeout(value * 1000);
61 #endif
62
63         ret = CMD_RET_SUCCESS;
64         if (strcmp(argv[argc - 1], "list") == 0) {
65                 dfu_show_entities();
66                 goto done;
67         }
68
69         int controller_index = simple_strtoul(usb_controller, NULL, 0);
70
71         run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
72
73 done:
74         dfu_free_entities();
75 #endif
76         return ret;
77 }
78
79 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
80         "Device Firmware Upgrade",
81         ""
82 #ifdef CONFIG_DFU_OVER_USB
83 #ifdef CONFIG_DFU_TIMEOUT
84         "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
85 #else
86         "<USB_controller> [<interface> <dev>] [list]\n"
87 #endif
88         "  - device firmware upgrade via <USB_controller>\n"
89         "    on device <dev>, attached to interface\n"
90         "    <interface>\n"
91 #ifdef CONFIG_DFU_TIMEOUT
92         "    [<timeout>] - specify inactivity timeout in seconds\n"
93 #endif
94         "    [list] - list available alt settings\n"
95 #endif
96 #ifdef CONFIG_DFU_OVER_TFTP
97 #ifdef CONFIG_DFU_OVER_USB
98         "dfu "
99 #endif
100         "tftp [<interface> <dev>] [<addr>]\n"
101         "  - device firmware upgrade via TFTP\n"
102         "    on device <dev>, attached to interface\n"
103         "    <interface>\n"
104         "    [<addr>] - address where FIT image has been stored\n"
105 #endif
106 );