blob: 68b1a7fec9a8fb2530e8e6e4749e5616d01d515f [file] [log] [blame]
Lukasz Majewski9273f4f2012-08-06 14:41:09 +02001/*
2 * cmd_dfu.c -- dfu command
3 *
Lukasz Majewski1747a542015-08-24 00:21:48 +02004 * Copyright (C) 2015
5 * Lukasz Majewski <l.majewski@majess.pl>
6 *
Lukasz Majewski9273f4f2012-08-06 14:41:09 +02007 * Copyright (C) 2012 Samsung Electronics
8 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
9 * Lukasz Majewski <l.majewski@samsung.com>
10 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020012 */
13
14#include <common.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
22static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23{
Lukasz Majewskid9eae702014-08-25 11:07:28 +020024
Mateusz Zalegad862f892013-10-04 19:22:26 +020025 if (argc < 4)
26 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
Mateusz Zalegad862f892013-10-04 19:22:26 +020031 char *interface = argv[2];
32 char *devstring = argv[3];
33
Marek Vasutea84f802018-02-16 16:41:17 +010034 int ret = 0;
Marek Vasut7f8d4362018-02-16 16:41:18 +010035#ifdef CONFIG_DFU_OVER_TFTP
Lukasz Majewski1747a542015-08-24 00:21:48 +020036 unsigned long addr = 0;
37 if (!strcmp(argv[1], "tftp")) {
38 if (argc == 5)
39 addr = simple_strtoul(argv[4], NULL, 0);
40
41 return update_tftp(addr, interface, devstring);
42 }
43#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010044#ifdef CONFIG_DFU_OVER_USB
Stephen Warren4afe50f2014-06-11 16:03:33 -060045 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020046 if (ret)
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060047 goto done;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020048
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060049 ret = CMD_RET_SUCCESS;
Mateusz Zalegad862f892013-10-04 19:22:26 +020050 if (argc > 4 && strcmp(argv[4], "list") == 0) {
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020051 dfu_show_entities();
52 goto done;
53 }
54
Mateusz Zalegad862f892013-10-04 19:22:26 +020055 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Lukasz Majewskid9eae702014-08-25 11:07:28 +020056
B, Ravi603a4c12016-07-28 17:39:15 +053057 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
Lukasz Majewski2968aa22013-07-18 13:19:14 +020058
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020059done:
60 dfu_free_entities();
Marek Vasutea84f802018-02-16 16:41:17 +010061#endif
Stephen Warrenf9d47dd2014-06-10 10:06:41 -060062 return ret;
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020063}
64
65U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
66 "Device Firmware Upgrade",
Marek Vasut7f8d4362018-02-16 16:41:18 +010067#ifdef CONFIG_DFU_OVER_USB
Mateusz Zalegad862f892013-10-04 19:22:26 +020068 "<USB_controller> <interface> <dev> [list]\n"
69 " - device firmware upgrade via <USB_controller>\n"
70 " on device <dev>, attached to interface\n"
71 " <interface>\n"
72 " [list] - list available alt settings\n"
Marek Vasutea84f802018-02-16 16:41:17 +010073#endif
Marek Vasut7f8d4362018-02-16 16:41:18 +010074#ifdef CONFIG_DFU_OVER_TFTP
75#ifdef CONFIG_DFU_OVER_USB
Marek Vasutea84f802018-02-16 16:41:17 +010076 "dfu "
77#endif
78 "tftp <interface> <dev> [<addr>]\n"
Lukasz Majewski1747a542015-08-24 00:21:48 +020079 " - device firmware upgrade via TFTP\n"
80 " on device <dev>, attached to interface\n"
81 " <interface>\n"
82 " [<addr>] - address where FIT image has been stored\n"
83#endif
Lukasz Majewski9273f4f2012-08-06 14:41:09 +020084);