2012-08-06 12:41:09 +00:00
|
|
|
/*
|
|
|
|
* cmd_dfu.c -- dfu command
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <g_dnl.h>
|
2013-10-04 17:22:26 +00:00
|
|
|
#include <usb.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
|
|
|
bool dfu_reset = false;
|
|
|
|
|
2013-10-04 17:22:26 +00:00
|
|
|
if (argc < 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
char *usb_controller = argv[1];
|
|
|
|
char *interface = argv[2];
|
|
|
|
char *devstring = argv[3];
|
|
|
|
|
2013-07-18 11:19:14 +00:00
|
|
|
int ret, i = 0;
|
2012-08-06 12:41:09 +00:00
|
|
|
|
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);
|
|
|
|
board_usb_init(controller_index, USB_INIT_DEVICE);
|
2014-12-10 20:43:03 +00:00
|
|
|
g_dnl_clear_detach();
|
2014-04-28 19:13:28 +00:00
|
|
|
g_dnl_register("usb_dnl_dfu");
|
2012-08-06 12:41:09 +00:00
|
|
|
while (1) {
|
2014-12-10 20:43:03 +00:00
|
|
|
if (g_dnl_detach()) {
|
2014-08-25 09:07:28 +00: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 11:19:14 +00:00
|
|
|
/*
|
|
|
|
* This extra number of usb_gadget_handle_interrupts()
|
|
|
|
* calls is necessary to assure correct transmission
|
|
|
|
* completion with dfu-util
|
|
|
|
*/
|
2014-08-25 09:07:28 +00:00
|
|
|
if (++i == 10000)
|
2013-07-18 11:19:14 +00:00
|
|
|
goto exit;
|
2014-08-25 09:07:28 +00:00
|
|
|
}
|
2013-07-18 11:19:14 +00:00
|
|
|
|
2012-08-06 12:41:09 +00:00
|
|
|
if (ctrlc())
|
|
|
|
goto exit;
|
|
|
|
|
2015-04-14 07:53:13 +00:00
|
|
|
WATCHDOG_RESET();
|
2015-02-23 13:10:23 +00:00
|
|
|
usb_gadget_handle_interrupts(controller_index);
|
2012-08-06 12:41:09 +00:00
|
|
|
}
|
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
2015-02-23 13:10:18 +00:00
|
|
|
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
2012-08-06 12:41:09 +00:00
|
|
|
done:
|
|
|
|
dfu_free_entities();
|
|
|
|
|
2014-08-25 09:07:28 +00:00
|
|
|
if (dfu_reset)
|
2013-07-18 11:19:14 +00:00
|
|
|
run_command("reset", 0);
|
|
|
|
|
2014-12-10 20:43:03 +00:00
|
|
|
g_dnl_clear_detach();
|
2014-08-25 09:07:28 +00:00
|
|
|
|
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",
|
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"
|
2012-08-06 12:41:09 +00:00
|
|
|
);
|