blob: 04291f6c0805fc5de2dea644bbceb19ba39b84a5 [file] [log] [blame]
Lukasz Majewskia006a5d2012-08-06 14:41:09 +02001/*
2 * cmd_dfu.c -- dfu command
3 *
Lukasz Majewskic2c146f2015-08-24 00:21:48 +02004 * Copyright (C) 2015
5 * Lukasz Majewski <l.majewski@majess.pl>
6 *
Lukasz Majewskia006a5d2012-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 Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020012 */
13
14#include <common.h>
Heiko Schocher0a9ac5c2015-04-14 09:53:13 +020015#include <watchdog.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020016#include <dfu.h>
Simon Glass24b852a2015-11-08 23:47:45 -070017#include <console.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020018#include <g_dnl.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020019#include <usb.h>
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020020#include <net.h>
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020021
22static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23{
Lukasz Majewski1cc03c52014-08-25 11:07:28 +020024
Mateusz Zalega16297cf2013-10-04 19:22:26 +020025 if (argc < 4)
26 return CMD_RET_USAGE;
27
28 char *usb_controller = argv[1];
29 char *interface = argv[2];
30 char *devstring = argv[3];
31
B, Ravi05341a82016-07-28 17:39:15 +053032 int ret;
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020033#ifdef CONFIG_DFU_TFTP
34 unsigned long addr = 0;
35 if (!strcmp(argv[1], "tftp")) {
36 if (argc == 5)
37 addr = simple_strtoul(argv[4], NULL, 0);
38
39 return update_tftp(addr, interface, devstring);
40 }
41#endif
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020042
Stephen Warrendd648272014-06-11 16:03:33 -060043 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020044 if (ret)
Stephen Warrenafb8e712014-06-10 10:06:41 -060045 goto done;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020046
Stephen Warrenafb8e712014-06-10 10:06:41 -060047 ret = CMD_RET_SUCCESS;
Mateusz Zalega16297cf2013-10-04 19:22:26 +020048 if (argc > 4 && strcmp(argv[4], "list") == 0) {
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020049 dfu_show_entities();
50 goto done;
51 }
52
Mateusz Zalega16297cf2013-10-04 19:22:26 +020053 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Lukasz Majewski1cc03c52014-08-25 11:07:28 +020054
B, Ravi05341a82016-07-28 17:39:15 +053055 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +020056
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020057done:
58 dfu_free_entities();
Stephen Warrenafb8e712014-06-10 10:06:41 -060059 return ret;
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020060}
61
62U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
63 "Device Firmware Upgrade",
Mateusz Zalega16297cf2013-10-04 19:22:26 +020064 "<USB_controller> <interface> <dev> [list]\n"
65 " - device firmware upgrade via <USB_controller>\n"
66 " on device <dev>, attached to interface\n"
67 " <interface>\n"
68 " [list] - list available alt settings\n"
Lukasz Majewskic2c146f2015-08-24 00:21:48 +020069#ifdef CONFIG_DFU_TFTP
70 "dfu tftp <interface> <dev> [<addr>]\n"
71 " - device firmware upgrade via TFTP\n"
72 " on device <dev>, attached to interface\n"
73 " <interface>\n"
74 " [<addr>] - address where FIT image has been stored\n"
75#endif
Lukasz Majewskia006a5d2012-08-06 14:41:09 +020076);