2012-08-06 20:41:09 +08: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 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-08-06 20:41:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dfu.h>
|
|
|
|
#include <g_dnl.h>
|
2013-10-05 01:22:26 +08:00
|
|
|
#include <usb.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;
|
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-08-25 17:07:28 +08:00
|
|
|
dfu_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-08-25 17:07:28 +08:00
|
|
|
if (dfu_detach()) {
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
usb_gadget_handle_interrupts();
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
|
|
|
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-08-25 17:07:28 +08:00
|
|
|
dfu_clear_detach();
|
|
|
|
|
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"
|
2012-08-06 20:41:09 +08:00
|
|
|
);
|