blob: b30f8a566733a0a99b659d8417150de0baa9960d [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
Patrick Delaunay06164032019-10-14 09:28:02 +020024 if (argc < 2)
Mateusz Zalegad862f892013-10-04 19:22:26 +020025 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
Andy Shevchenko1cfb9562019-03-04 16:04:44 +020030#if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
Patrick Delaunay06164032019-10-14 09:28:02 +020031 char *interface = NULL;
32 char *devstring = NULL;
Andy Shevchenko1e414012019-11-27 18:12:15 +020033#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020034 unsigned long value = 0;
35#endif
Patrick Delaunay06164032019-10-14 09:28:02 +020036
37 if (argc >= 4) {
38 interface = argv[2];
39 devstring = argv[3];
40 }
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020041
Andy Shevchenko1e414012019-11-27 18:12:15 +020042#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020043 if (argc == 5 || argc == 3)
44 value = simple_strtoul(argv[argc - 1], NULL, 0);
45#endif
Andy Shevchenko1cfb9562019-03-04 16:04:44 +020046#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020047
Marek Vasutea84f802018-02-16 16:41:17 +010048 int ret = 0;
Marek Vasut7f8d4362018-02-16 16:41:18 +010049#ifdef CONFIG_DFU_OVER_TFTP
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020050 if (!strcmp(argv[1], "tftp"))
51 return update_tftp(value, interface, devstring);
Lukasz Majewski1747a542015-08-24 00:21:48 +020052#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010053#ifdef CONFIG_DFU_OVER_USB
Stephen Warren4afe50f2014-06-11 16:03:33 -060054 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020055 if (ret)
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060056 goto done;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020057
Andy Shevchenko1e414012019-11-27 18:12:15 +020058#ifdef CONFIG_DFU_TIMEOUT
59 dfu_set_timeout(value * 1000);
60#endif
61
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060062 ret = CMD_RET_SUCCESS;
Patrick Delaunay06164032019-10-14 09:28:02 +020063 if (strcmp(argv[argc - 1], "list") == 0) {
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020064 dfu_show_entities();
65 goto done;
66 }
67
Mateusz Zalegad862f892013-10-04 19:22:26 +020068 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Lukasz Majewskid9eae702014-08-25 11:07:28 +020069
B, Ravi603a4c12016-07-28 17:39:15 +053070 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
Lukasz Majewski2968aa22013-07-18 13:19:14 +020071
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020072done:
73 dfu_free_entities();
Marek Vasutea84f802018-02-16 16:41:17 +010074#endif
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060075 return ret;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020076}
77
78U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
79 "Device Firmware Upgrade",
Andy Shevchenko1cfb9562019-03-04 16:04:44 +020080 ""
Marek Vasut7f8d4362018-02-16 16:41:18 +010081#ifdef CONFIG_DFU_OVER_USB
Andy Shevchenko1e414012019-11-27 18:12:15 +020082#ifdef CONFIG_DFU_TIMEOUT
83 "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
84#else
Patrick Delaunay06164032019-10-14 09:28:02 +020085 "<USB_controller> [<interface> <dev>] [list]\n"
Andy Shevchenko1e414012019-11-27 18:12:15 +020086#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020087 " - device firmware upgrade via <USB_controller>\n"
88 " on device <dev>, attached to interface\n"
89 " <interface>\n"
Andy Shevchenko1e414012019-11-27 18:12:15 +020090#ifdef CONFIG_DFU_TIMEOUT
91 " [<timeout>] - specify inactivity timeout in seconds\n"
92#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020093 " [list] - list available alt settings\n"
Marek Vasutea84f802018-02-16 16:41:17 +010094#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010095#ifdef CONFIG_DFU_OVER_TFTP
96#ifdef CONFIG_DFU_OVER_USB
Marek Vasutea84f802018-02-16 16:41:17 +010097 "dfu "
98#endif
Patrick Delaunay06164032019-10-14 09:28:02 +020099 "tftp [<interface> <dev>] [<addr>]\n"
Lukasz Majewski1747a542015-08-24 00:21:48 +0200100 " - device firmware upgrade via TFTP\n"
101 " on device <dev>, attached to interface\n"
102 " <interface>\n"
103 " [<addr>] - address where FIT image has been stored\n"
104#endif
Lukasz Majewski9273f4f2012-08-06 14:41:09 +0200105);