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>
|
|
|
|
#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[])
|
|
|
|
{
|
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
|
|
|
|
2013-10-04 17:22:26 +00:00
|
|
|
ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
|
|
|
|
NULL, 10));
|
2012-08-06 12:41:09 +00:00
|
|
|
if (ret)
|
2013-09-11 12:53:35 +00:00
|
|
|
return ret;
|
2012-08-06 12:41:09 +00:00
|
|
|
|
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);
|
2012-11-30 08:01:07 +00:00
|
|
|
|
2014-04-28 19:13:28 +00:00
|
|
|
g_dnl_register("usb_dnl_dfu");
|
2012-08-06 12:41:09 +00:00
|
|
|
while (1) {
|
2013-07-18 11:19:14 +00:00
|
|
|
if (dfu_reset())
|
|
|
|
/*
|
|
|
|
* This extra number of usb_gadget_handle_interrupts()
|
|
|
|
* calls is necessary to assure correct transmission
|
|
|
|
* completion with dfu-util
|
|
|
|
*/
|
|
|
|
if (++i == 10)
|
|
|
|
goto exit;
|
|
|
|
|
2012-08-06 12:41:09 +00:00
|
|
|
if (ctrlc())
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
usb_gadget_handle_interrupts();
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
|
|
|
done:
|
|
|
|
dfu_free_entities();
|
|
|
|
|
2013-07-18 11:19:14 +00:00
|
|
|
if (dfu_reset())
|
|
|
|
run_command("reset", 0);
|
|
|
|
|
2012-08-06 12:41:09 +00:00
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
);
|