blob: 7310595a02786f5dda6987190ee40941fde2a06c [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>
Simon Glassed38aef2020-05-10 11:40:03 -060014#include <command.h>
Heiko Schocherc8848842015-04-14 09:53:13 +020015#include <watchdog.h>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020016#include <dfu.h>
Simon Glassa73bda42015-11-08 23:47:45 -070017#include <console.h>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020018#include <g_dnl.h>
Mateusz Zalegad862f892013-10-04 19:22:26 +020019#include <usb.h>
Lukasz Majewski1747a542015-08-24 00:21:48 +020020#include <net.h>
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020021
Simon Glassed38aef2020-05-10 11:40:03 -060022static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020023{
Lukasz Majewskid9eae702014-08-25 11:07:28 +020024
Patrick Delaunay06164032019-10-14 09:28:02 +020025 if (argc < 2)
Mateusz Zalegad862f892013-10-04 19:22:26 +020026 return CMD_RET_USAGE;
27
Marek Vasut7f8d4362018-02-16 16:41:18 +010028#ifdef CONFIG_DFU_OVER_USB
Mateusz Zalegad862f892013-10-04 19:22:26 +020029 char *usb_controller = argv[1];
Marek Vasutea84f802018-02-16 16:41:17 +010030#endif
Andy Shevchenko1cfb9562019-03-04 16:04:44 +020031#if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
Patrick Delaunay06164032019-10-14 09:28:02 +020032 char *interface = NULL;
33 char *devstring = NULL;
Andy Shevchenko1e414012019-11-27 18:12:15 +020034#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020035 unsigned long value = 0;
36#endif
Patrick Delaunay06164032019-10-14 09:28:02 +020037
38 if (argc >= 4) {
39 interface = argv[2];
40 devstring = argv[3];
41 }
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020042
Andy Shevchenko1e414012019-11-27 18:12:15 +020043#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020044 if (argc == 5 || argc == 3)
45 value = simple_strtoul(argv[argc - 1], NULL, 0);
46#endif
Andy Shevchenko1cfb9562019-03-04 16:04:44 +020047#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020048
Marek Vasutea84f802018-02-16 16:41:17 +010049 int ret = 0;
Marek Vasut7f8d4362018-02-16 16:41:18 +010050#ifdef CONFIG_DFU_OVER_TFTP
Andy Shevchenko9bb63ec2019-11-27 18:12:14 +020051 if (!strcmp(argv[1], "tftp"))
52 return update_tftp(value, interface, devstring);
Lukasz Majewski1747a542015-08-24 00:21:48 +020053#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010054#ifdef CONFIG_DFU_OVER_USB
Stephen Warren4afe50f2014-06-11 16:03:33 -060055 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020056 if (ret)
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060057 goto done;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020058
Andy Shevchenko1e414012019-11-27 18:12:15 +020059#ifdef CONFIG_DFU_TIMEOUT
60 dfu_set_timeout(value * 1000);
61#endif
62
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060063 ret = CMD_RET_SUCCESS;
Patrick Delaunay06164032019-10-14 09:28:02 +020064 if (strcmp(argv[argc - 1], "list") == 0) {
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020065 dfu_show_entities();
66 goto done;
67 }
68
Mateusz Zalegad862f892013-10-04 19:22:26 +020069 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Lukasz Majewskid9eae702014-08-25 11:07:28 +020070
B, Ravi603a4c12016-07-28 17:39:15 +053071 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
Lukasz Majewski2968aa22013-07-18 13:19:14 +020072
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020073done:
74 dfu_free_entities();
Marek Vasutea84f802018-02-16 16:41:17 +010075#endif
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060076 return ret;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020077}
78
79U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
80 "Device Firmware Upgrade",
Andy Shevchenko1cfb9562019-03-04 16:04:44 +020081 ""
Marek Vasut7f8d4362018-02-16 16:41:18 +010082#ifdef CONFIG_DFU_OVER_USB
Andy Shevchenko1e414012019-11-27 18:12:15 +020083#ifdef CONFIG_DFU_TIMEOUT
84 "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
85#else
Patrick Delaunay06164032019-10-14 09:28:02 +020086 "<USB_controller> [<interface> <dev>] [list]\n"
Andy Shevchenko1e414012019-11-27 18:12:15 +020087#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020088 " - device firmware upgrade via <USB_controller>\n"
89 " on device <dev>, attached to interface\n"
90 " <interface>\n"
Andy Shevchenko1e414012019-11-27 18:12:15 +020091#ifdef CONFIG_DFU_TIMEOUT
92 " [<timeout>] - specify inactivity timeout in seconds\n"
93#endif
Mateusz Zalegad862f892013-10-04 19:22:26 +020094 " [list] - list available alt settings\n"
Marek Vasutea84f802018-02-16 16:41:17 +010095#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010096#ifdef CONFIG_DFU_OVER_TFTP
97#ifdef CONFIG_DFU_OVER_USB
Marek Vasutea84f802018-02-16 16:41:17 +010098 "dfu "
99#endif
Patrick Delaunay06164032019-10-14 09:28:02 +0200100 "tftp [<interface> <dev>] [<addr>]\n"
Lukasz Majewski1747a542015-08-24 00:21:48 +0200101 " - 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
Lukasz Majewski9273f4f2012-08-06 14:41:09 +0200106);