Merge tag 'tpm-master-28012025' of https://source.denx.de/u-boot/custodians/u-boot-tpm
[u-boot.git] / cmd / dfu.c
blob46f0190588e05b160c2eb3071ab8e229e512c77d
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * cmd_dfu.c -- dfu command
5 * Copyright (C) 2015
6 * Lukasz Majewski <l.majewski@majess.pl>
8 * Copyright (C) 2012 Samsung Electronics
9 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
10 * Lukasz Majewski <l.majewski@samsung.com>
13 #include <command.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>
21 static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
24 if (argc < 2)
25 return CMD_RET_USAGE;
27 #ifdef CONFIG_DFU_OVER_USB
28 char *usb_controller = argv[1];
29 #endif
30 char *interface = NULL;
31 char *devstring = NULL;
32 #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
33 unsigned long value = 0;
34 #endif
35 if (argc >= 4) {
36 interface = argv[2];
37 devstring = argv[3];
40 #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
41 if (argc == 5 || argc == 3)
42 value = simple_strtoul(argv[argc - 1], NULL, 0);
43 #endif
45 int ret = 0;
46 #ifdef CONFIG_DFU_OVER_TFTP
47 if (!strcmp(argv[1], "tftp"))
48 return update_tftp(value, interface, devstring);
49 #endif
50 ret = dfu_init_env_entities(interface, devstring);
51 if (ret)
52 goto done;
54 #ifdef CONFIG_DFU_TIMEOUT
55 dfu_set_timeout(value * 1000);
56 #endif
58 ret = CMD_RET_SUCCESS;
59 if (strcmp(argv[argc - 1], "list") == 0) {
60 dfu_show_entities();
61 goto done;
64 #ifdef CONFIG_DFU_OVER_USB
65 int controller_index = simple_strtoul(usb_controller, NULL, 0);
66 bool retry = false;
67 do {
68 ret = run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
70 if (dfu_reinit_needed) {
71 dfu_free_entities();
72 ret = dfu_init_env_entities(interface, devstring);
73 if (ret)
74 goto done;
75 retry = true;
77 } while (retry);
79 #endif
80 done:
81 dfu_free_entities();
82 return ret;
85 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
86 "Device Firmware Upgrade",
88 #ifdef CONFIG_DFU_OVER_USB
89 #ifdef CONFIG_DFU_TIMEOUT
90 "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
91 #else
92 "<USB_controller> [<interface> <dev>] [list]\n"
93 #endif
94 " - device firmware upgrade via <USB_controller>\n"
95 " on device <dev>, attached to interface\n"
96 " <interface>\n"
97 #ifdef CONFIG_DFU_TIMEOUT
98 " [<timeout>] - specify inactivity timeout in seconds\n"
99 #endif
100 #endif
101 " [list] - list available alt settings\n"
102 #ifdef CONFIG_DFU_OVER_TFTP
103 #ifdef CONFIG_DFU_OVER_USB
104 "dfu "
105 #endif
106 "tftp [<interface> <dev>] [<addr>]\n"
107 " - device firmware upgrade via TFTP\n"
108 " on device <dev>, attached to interface\n"
109 " <interface>\n"
110 " [<addr>] - address where FIT image has been stored\n"
111 #endif