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[])
|
|
|
|
{
|
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];
|
|
|
|
|
2012-10-09 17:28:15 +08:00
|
|
|
char *s = "dfu";
|
2013-07-18 19:19:14 +08:00
|
|
|
int ret, i = 0;
|
2012-08-06 20:41:09 +08:00
|
|
|
|
2013-10-05 01:22:26 +08:00
|
|
|
ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
|
|
|
|
NULL, 10));
|
2012-08-06 20:41:09 +08:00
|
|
|
if (ret)
|
2013-09-11 20:53:35 +08:00
|
|
|
return ret;
|
2012-08-06 20:41:09 +08:00
|
|
|
|
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);
|
2012-11-30 16:01:07 +08:00
|
|
|
|
2012-08-06 20:41:09 +08:00
|
|
|
g_dnl_register(s);
|
|
|
|
while (1) {
|
2013-07-18 19:19:14 +08: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 20:41:09 +08:00
|
|
|
if (ctrlc())
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
usb_gadget_handle_interrupts();
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
|
|
|
done:
|
|
|
|
dfu_free_entities();
|
|
|
|
|
2013-07-18 19:19:14 +08:00
|
|
|
if (dfu_reset())
|
|
|
|
run_command("reset", 0);
|
|
|
|
|
2012-08-06 20:41:09 +08:00
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
);
|