2012-08-06 20:41:09 +08:00
|
|
|
/*
|
|
|
|
* cmd_dfu.c -- dfu command
|
|
|
|
*
|
2015-08-24 06:21:48 +08:00
|
|
|
* Copyright (C) 2015
|
|
|
|
* Lukasz Majewski <l.majewski@majess.pl>
|
|
|
|
*
|
2012-08-06 20:41:09 +08:00
|
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
|
|
* authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-08-06 20:41:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-04-14 15:53:13 +08:00
|
|
|
#include <watchdog.h>
|
2012-08-06 20:41:09 +08:00
|
|
|
#include <dfu.h>
|
|
|
|
#include <g_dnl.h>
|
2013-10-05 01:22:26 +08:00
|
|
|
#include <usb.h>
|
2015-08-24 06:21:48 +08:00
|
|
|
#include <net.h>
|
2012-08-06 20:41:09 +08:00
|
|
|
|
|
|
|
static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
2014-08-25 17:07:28 +08:00
|
|
|
bool dfu_reset = false;
|
|
|
|
|
2013-10-05 01:22:26 +08:00
|
|
|
if (argc < 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
char *usb_controller = argv[1];
|
|
|
|
char *interface = argv[2];
|
|
|
|
char *devstring = argv[3];
|
|
|
|
|
2013-07-18 19:19:14 +08:00
|
|
|
int ret, i = 0;
|
2015-08-24 06:21:48 +08:00
|
|
|
#ifdef CONFIG_DFU_TFTP
|
|
|
|
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
|
2012-08-06 20:41:09 +08:00
|
|
|
|
2014-06-12 06:03:33 +08:00
|
|
|
ret = dfu_init_env_entities(interface, devstring);
|
2012-08-06 20:41:09 +08:00
|
|
|
if (ret)
|
2014-06-11 00:06:41 +08:00
|
|
|
goto done;
|
2012-08-06 20:41:09 +08:00
|
|
|
|
2014-06-11 00:06:41 +08:00
|
|
|
ret = CMD_RET_SUCCESS;
|
2013-10-05 01:22:26 +08:00
|
|
|
if (argc > 4 && strcmp(argv[4], "list") == 0) {
|
2012-08-06 20:41:09 +08:00
|
|
|
dfu_show_entities();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-10-05 01:22:26 +08:00
|
|
|
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
|
|
|
board_usb_init(controller_index, USB_INIT_DEVICE);
|
2014-12-11 04:43:03 +08:00
|
|
|
g_dnl_clear_detach();
|
2014-04-29 03:13:28 +08:00
|
|
|
g_dnl_register("usb_dnl_dfu");
|
2012-08-06 20:41:09 +08:00
|
|
|
while (1) {
|
2014-12-11 04:43:03 +08:00
|
|
|
if (g_dnl_detach()) {
|
2014-08-25 17:07:28 +08:00
|
|
|
/*
|
|
|
|
* Check if USB bus reset is performed after detach,
|
|
|
|
* which indicates that -R switch has been passed to
|
|
|
|
* dfu-util. In this case reboot the device
|
|
|
|
*/
|
|
|
|
if (dfu_usb_get_reset()) {
|
|
|
|
dfu_reset = true;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-07-18 19:19:14 +08:00
|
|
|
/*
|
|
|
|
* This extra number of usb_gadget_handle_interrupts()
|
|
|
|
* calls is necessary to assure correct transmission
|
|
|
|
* completion with dfu-util
|
|
|
|
*/
|
2014-08-25 17:07:28 +08:00
|
|
|
if (++i == 10000)
|
2013-07-18 19:19:14 +08:00
|
|
|
goto exit;
|
2014-08-25 17:07:28 +08:00
|
|
|
}
|
2013-07-18 19:19:14 +08:00
|
|
|
|
2012-08-06 20:41:09 +08:00
|
|
|
if (ctrlc())
|
|
|
|
goto exit;
|
|
|
|
|
2015-04-14 15:53:13 +08:00
|
|
|
WATCHDOG_RESET();
|
2015-02-23 21:10:23 +08:00
|
|
|
usb_gadget_handle_interrupts(controller_index);
|
2012-08-06 20:41:09 +08:00
|
|
|
}
|
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
2015-02-23 21:10:18 +08:00
|
|
|
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
2012-08-06 20:41:09 +08:00
|
|
|
done:
|
|
|
|
dfu_free_entities();
|
|
|
|
|
2014-08-25 17:07:28 +08:00
|
|
|
if (dfu_reset)
|
2013-07-18 19:19:14 +08:00
|
|
|
run_command("reset", 0);
|
|
|
|
|
2014-12-11 04:43:03 +08:00
|
|
|
g_dnl_clear_detach();
|
2014-08-25 17:07:28 +08:00
|
|
|
|
2014-06-11 00:06:41 +08:00
|
|
|
return ret;
|
2012-08-06 20:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
|
|
|
|
"Device Firmware Upgrade",
|
2013-10-05 01:22:26 +08: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"
|
2015-08-24 06:21:48 +08:00
|
|
|
#ifdef CONFIG_DFU_TFTP
|
|
|
|
"dfu tftp <interface> <dev> [<addr>]\n"
|
|
|
|
" - 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 20:41:09 +08:00
|
|
|
);
|