blob: 33491d0bc9c3ce0d1aa7d468c7d97a82c97e2f83 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskia006a5d2012-08-06 14:41:09 +02002/*
3 * cmd_dfu.c -- dfu command
4 *
Lukasz Majewskic2c146f2015-08-24 00:21:48 +02005 * Copyright (C) 2015
6 * Lukasz Majewski <l.majewski@majess.pl>
7 *
Lukasz Majewskia006a5d2012-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 Majewskia006a5d2012-08-06 14:41:09 +020011 */
12
13#include <common.h>
Heiko Schocher0a9ac5c2015-04-14 09:53:13 +020014#include <watchdog.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020015#include <dfu.h>
Simon Glass24b852a2015-11-08 23:47:45 -070016#include <console.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020017#include <g_dnl.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020018#include <usb.h>
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020019#include <net.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020020
21static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
22{
Lukasz Majewski1cc03c52014-08-25 11:07:28 +020023
Patrick Delaunayfebabe32019-10-14 09:28:02 +020024 if (argc < 2)
Mateusz Zalega16297cf2013-10-04 19:22:26 +020025 return CMD_RET_USAGE;
26
Marek Vasutbb4059a2018-02-16 16:41:18 +010027#ifdef CONFIG_DFU_OVER_USB
Mateusz Zalega16297cf2013-10-04 19:22:26 +020028 char *usb_controller = argv[1];
Marek Vasut0f44d332018-02-16 16:41:17 +010029#endif
Andy Shevchenkocbc10812019-03-04 16:04:44 +020030#if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
Patrick Delaunayfebabe32019-10-14 09:28:02 +020031 char *interface = NULL;
32 char *devstring = NULL;
33
34 if (argc >= 4) {
35 interface = argv[2];
36 devstring = argv[3];
37 }
Andy Shevchenkocbc10812019-03-04 16:04:44 +020038#endif
Mateusz Zalega16297cf2013-10-04 19:22:26 +020039
Marek Vasut0f44d332018-02-16 16:41:17 +010040 int ret = 0;
Marek Vasutbb4059a2018-02-16 16:41:18 +010041#ifdef CONFIG_DFU_OVER_TFTP
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020042 unsigned long addr = 0;
43 if (!strcmp(argv[1], "tftp")) {
Patrick Delaunayfebabe32019-10-14 09:28:02 +020044 if (argc == 5 || argc == 3)
45 addr = simple_strtoul(argv[argc - 1], NULL, 0);
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020046
47 return update_tftp(addr, interface, devstring);
48 }
49#endif
Marek Vasutbb4059a2018-02-16 16:41:18 +010050#ifdef CONFIG_DFU_OVER_USB
Stephen Warrendd648272014-06-11 16:03:33 -060051 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020052 if (ret)
Stephen Warrenafb8e712014-06-10 10:06:41 -060053 goto done;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020054
Stephen Warrenafb8e712014-06-10 10:06:41 -060055 ret = CMD_RET_SUCCESS;
Patrick Delaunayfebabe32019-10-14 09:28:02 +020056 if (strcmp(argv[argc - 1], "list") == 0) {
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020057 dfu_show_entities();
58 goto done;
59 }
60
Mateusz Zalega16297cf2013-10-04 19:22:26 +020061 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Lukasz Majewski1cc03c52014-08-25 11:07:28 +020062
B, Ravi05341a82016-07-28 17:39:15 +053063 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020064
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020065done:
66 dfu_free_entities();
Marek Vasut0f44d332018-02-16 16:41:17 +010067#endif
Stephen Warrenafb8e712014-06-10 10:06:41 -060068 return ret;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020069}
70
71U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
72 "Device Firmware Upgrade",
Andy Shevchenkocbc10812019-03-04 16:04:44 +020073 ""
Marek Vasutbb4059a2018-02-16 16:41:18 +010074#ifdef CONFIG_DFU_OVER_USB
Patrick Delaunayfebabe32019-10-14 09:28:02 +020075 "<USB_controller> [<interface> <dev>] [list]\n"
Mateusz Zalega16297cf2013-10-04 19:22:26 +020076 " - device firmware upgrade via <USB_controller>\n"
77 " on device <dev>, attached to interface\n"
78 " <interface>\n"
79 " [list] - list available alt settings\n"
Marek Vasut0f44d332018-02-16 16:41:17 +010080#endif
Marek Vasutbb4059a2018-02-16 16:41:18 +010081#ifdef CONFIG_DFU_OVER_TFTP
82#ifdef CONFIG_DFU_OVER_USB
Marek Vasut0f44d332018-02-16 16:41:17 +010083 "dfu "
84#endif
Patrick Delaunayfebabe32019-10-14 09:28:02 +020085 "tftp [<interface> <dev>] [<addr>]\n"
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020086 " - device firmware upgrade via TFTP\n"
87 " on device <dev>, attached to interface\n"
88 " <interface>\n"
89 " [<addr>] - address where FIT image has been stored\n"
90#endif
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020091);