blob: c9ba0621970d4386a529403084ba96e37f7d9b6f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski9273f4f2012-08-06 14:41:09 +02002/*
3 * cmd_dfu.c -- dfu command
4 *
Lukasz Majewski1747a542015-08-24 00:21:48 +02005 * Copyright (C) 2015
6 * Lukasz Majewski <l.majewski@majess.pl>
7 *
Lukasz Majewski9273f4f2012-08-06 14:41:09 +02008 * Copyright (C) 2012 Samsung Electronics
9 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
10 * Lukasz Majewski <l.majewski@samsung.com>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020011 */
12
13#include <common.h>
Heiko Schocherc8848842015-04-14 09:53:13 +020014#include <watchdog.h>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020015#include <dfu.h>
Simon Glassa73bda42015-11-08 23:47:45 -070016#include <console.h>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020017#include <g_dnl.h>
Mateusz Zalegad862f892013-10-04 19:22:26 +020018#include <usb.h>
Lukasz Majewski1747a542015-08-24 00:21:48 +020019#include <net.h>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020020
21static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
22{
Lukasz Majewskid9eae702014-08-25 11:07:28 +020023
Mateusz Zalegad862f892013-10-04 19:22:26 +020024 if (argc < 4)
25 return CMD_RET_USAGE;
26
Marek Vasut7f8d4362018-02-16 16:41:18 +010027#ifdef CONFIG_DFU_OVER_USB
Mateusz Zalegad862f892013-10-04 19:22:26 +020028 char *usb_controller = argv[1];
Marek Vasutea84f802018-02-16 16:41:17 +010029#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020030 char *interface = argv[2];
31 char *devstring = argv[3];
32
Marek Vasutea84f802018-02-16 16:41:17 +010033 int ret = 0;
Marek Vasut7f8d4362018-02-16 16:41:18 +010034#ifdef CONFIG_DFU_OVER_TFTP
Lukasz Majewski1747a542015-08-24 00:21:48 +020035 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
Marek Vasut7f8d4362018-02-16 16:41:18 +010043#ifdef CONFIG_DFU_OVER_USB
Stephen Warren4afe50f2014-06-11 16:03:33 -060044 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020045 if (ret)
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060046 goto done;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020047
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060048 ret = CMD_RET_SUCCESS;
Mateusz Zalegad862f892013-10-04 19:22:26 +020049 if (argc > 4 && strcmp(argv[4], "list") == 0) {
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020050 dfu_show_entities();
51 goto done;
52 }
53
Mateusz Zalegad862f892013-10-04 19:22:26 +020054 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Lukasz Majewskid9eae702014-08-25 11:07:28 +020055
B, Ravi603a4c12016-07-28 17:39:15 +053056 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
Lukasz Majewski2968aa22013-07-18 13:19:14 +020057
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020058done:
59 dfu_free_entities();
Marek Vasutea84f802018-02-16 16:41:17 +010060#endif
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060061 return ret;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020062}
63
64U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
65 "Device Firmware Upgrade",
Marek Vasut7f8d4362018-02-16 16:41:18 +010066#ifdef CONFIG_DFU_OVER_USB
Mateusz Zalegad862f892013-10-04 19:22:26 +020067 "<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"
Marek Vasutea84f802018-02-16 16:41:17 +010072#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010073#ifdef CONFIG_DFU_OVER_TFTP
74#ifdef CONFIG_DFU_OVER_USB
Marek Vasutea84f802018-02-16 16:41:17 +010075 "dfu "
76#endif
77 "tftp <interface> <dev> [<addr>]\n"
Lukasz Majewski1747a542015-08-24 00:21:48 +020078 " - 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
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020083);