2012-08-06 12:41:09 +00:00
|
|
|
/*
|
|
|
|
* cmd_dfu.c -- dfu command
|
|
|
|
*
|
2015-08-23 22:21:48 +00:00
|
|
|
* Copyright (C) 2015
|
|
|
|
* Lukasz Majewski <l.majewski@majess.pl>
|
|
|
|
*
|
2012-08-06 12:41:09 +00:00
|
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
|
|
* authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-08-06 12:41:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-04-14 07:53:13 +00:00
|
|
|
#include <watchdog.h>
|
2012-08-06 12:41:09 +00:00
|
|
|
#include <dfu.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2012-08-06 12:41:09 +00:00
|
|
|
#include <g_dnl.h>
|
2013-10-04 17:22:26 +00:00
|
|
|
#include <usb.h>
|
2015-08-23 22:21:48 +00:00
|
|
|
#include <net.h>
|
2012-08-06 12:41:09 +00:00
|
|
|
|
|
|
|
static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
2014-08-25 09:07:28 +00:00
|
|
|
|
2013-10-04 17:22:26 +00:00
|
|
|
if (argc < 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2018-02-16 15:41:17 +00:00
|
|
|
#ifdef CONFIG_USB_FUNCTION_DFU
|
2013-10-04 17:22:26 +00:00
|
|
|
char *usb_controller = argv[1];
|
2018-02-16 15:41:17 +00:00
|
|
|
#endif
|
2013-10-04 17:22:26 +00:00
|
|
|
char *interface = argv[2];
|
|
|
|
char *devstring = argv[3];
|
|
|
|
|
2018-02-16 15:41:17 +00:00
|
|
|
int ret = 0;
|
|
|
|
#ifdef CONFIG_TFTP_FUNCTION_DFU
|
2015-08-23 22:21:48 +00:00
|
|
|
unsigned long addr = 0;
|
|
|
|
if (!strcmp(argv[1], "tftp")) {
|
|
|
|
if (argc == 5)
|
|
|
|
addr = simple_strtoul(argv[4], NULL, 0);
|
|
|
|
|
|
|
|
return update_tftp(addr, interface, devstring);
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-16 15:41:17 +00:00
|
|
|
#ifdef CONFIG_USB_FUNCTION_DFU
|
2014-06-11 22:03:33 +00:00
|
|
|
ret = dfu_init_env_entities(interface, devstring);
|
2012-08-06 12:41:09 +00:00
|
|
|
if (ret)
|
2014-06-10 16:06:41 +00:00
|
|
|
goto done;
|
2012-08-06 12:41:09 +00:00
|
|
|
|
2014-06-10 16:06:41 +00:00
|
|
|
ret = CMD_RET_SUCCESS;
|
2013-10-04 17:22:26 +00:00
|
|
|
if (argc > 4 && strcmp(argv[4], "list") == 0) {
|
2012-08-06 12:41:09 +00:00
|
|
|
dfu_show_entities();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-10-04 17:22:26 +00:00
|
|
|
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
2014-08-25 09:07:28 +00:00
|
|
|
|
2016-07-28 12:09:15 +00:00
|
|
|
run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
|
2013-07-18 11:19:14 +00:00
|
|
|
|
2012-08-06 12:41:09 +00:00
|
|
|
done:
|
|
|
|
dfu_free_entities();
|
2018-02-16 15:41:17 +00:00
|
|
|
#endif
|
2014-06-10 16:06:41 +00:00
|
|
|
return ret;
|
2012-08-06 12:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
|
|
|
|
"Device Firmware Upgrade",
|
2018-02-16 15:41:17 +00:00
|
|
|
#ifdef CONFIG_USB_FUNCTION_DFU
|
2013-10-04 17:22:26 +00:00
|
|
|
"<USB_controller> <interface> <dev> [list]\n"
|
|
|
|
" - device firmware upgrade via <USB_controller>\n"
|
|
|
|
" on device <dev>, attached to interface\n"
|
|
|
|
" <interface>\n"
|
|
|
|
" [list] - list available alt settings\n"
|
2018-02-16 15:41:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TFTP_FUNCTION_DFU
|
|
|
|
#ifdef CONFIG_USB_FUNCTION_DFU
|
|
|
|
"dfu "
|
|
|
|
#endif
|
|
|
|
"tftp <interface> <dev> [<addr>]\n"
|
2015-08-23 22:21:48 +00:00
|
|
|
" - device firmware upgrade via TFTP\n"
|
|
|
|
" on device <dev>, attached to interface\n"
|
|
|
|
" <interface>\n"
|
|
|
|
" [<addr>] - address where FIT image has been stored\n"
|
|
|
|
#endif
|
2012-08-06 12:41:09 +00:00
|
|
|
);
|