2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-10-08 12:30:44 +00:00
|
|
|
/*
|
|
|
|
* cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2013-10-08 12:30:44 +00:00
|
|
|
#include <thor.h>
|
|
|
|
#include <dfu.h>
|
|
|
|
#include <g_dnl.h>
|
|
|
|
#include <usb.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2013-10-08 12:30:44 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2013-10-08 12:30:44 +00:00
|
|
|
{
|
2023-09-01 09:49:53 +00:00
|
|
|
char *interface, *devstring;
|
|
|
|
int controller_index;
|
2023-09-01 09:49:59 +00:00
|
|
|
struct udevice *udc;
|
2023-09-01 09:49:53 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-10-08 12:30:44 +00:00
|
|
|
if (argc < 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
puts("TIZEN \"THOR\" Downloader\n");
|
|
|
|
|
2023-09-01 09:49:53 +00:00
|
|
|
interface = argv[2];
|
|
|
|
devstring = argv[3];
|
|
|
|
|
2014-06-23 07:39:16 +00:00
|
|
|
ret = dfu_init_env_entities(interface, devstring);
|
2013-10-08 12:30:44 +00:00
|
|
|
if (ret)
|
2014-06-23 07:39:16 +00:00
|
|
|
goto done;
|
2013-10-08 12:30:44 +00:00
|
|
|
|
2023-09-01 09:49:53 +00:00
|
|
|
controller_index = simple_strtoul(argv[1], NULL, 0);
|
2023-09-01 09:49:59 +00:00
|
|
|
ret = udc_device_get_by_index(controller_index, &udc);
|
2013-10-08 12:30:44 +00:00
|
|
|
if (ret) {
|
2018-06-04 07:04:51 +00:00
|
|
|
pr_err("USB init failed: %d\n", ret);
|
2013-10-08 12:30:44 +00:00
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2019-06-21 13:39:29 +00:00
|
|
|
ret = g_dnl_register("usb_dnl_thor");
|
|
|
|
if (ret) {
|
|
|
|
pr_err("g_dnl_register failed %d\n", ret);
|
2019-10-02 12:29:21 +00:00
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
goto exit;
|
2019-06-21 13:39:29 +00:00
|
|
|
}
|
2013-10-08 12:30:44 +00:00
|
|
|
|
2023-09-01 09:49:59 +00:00
|
|
|
ret = thor_init(udc);
|
2013-10-08 12:30:44 +00:00
|
|
|
if (ret) {
|
2018-06-04 07:04:51 +00:00
|
|
|
pr_err("THOR DOWNLOAD failed: %d\n", ret);
|
2013-10-08 12:30:44 +00:00
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2020-12-22 10:32:24 +00:00
|
|
|
do {
|
2023-09-01 09:49:59 +00:00
|
|
|
ret = thor_handle(udc);
|
2020-12-22 10:32:24 +00:00
|
|
|
if (ret == THOR_DFU_REINIT_NEEDED) {
|
|
|
|
dfu_free_entities();
|
|
|
|
ret = dfu_init_env_entities(interface, devstring);
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
pr_err("THOR failed: %d\n", ret);
|
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
} while (ret == 0);
|
2013-10-08 12:30:44 +00:00
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
2023-09-01 09:49:59 +00:00
|
|
|
udc_device_put(udc);
|
2014-06-23 07:39:16 +00:00
|
|
|
done:
|
2013-10-08 12:30:44 +00:00
|
|
|
dfu_free_entities();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
|
|
|
|
"TIZEN \"THOR\" downloader",
|
|
|
|
"<USB_controller> <interface> <dev>\n"
|
2019-03-06 06:52:14 +00:00
|
|
|
" - device software upgrade via LTHOR TIZEN download\n"
|
2013-10-08 12:30:44 +00:00
|
|
|
" program via <USB_controller> on device <dev>,\n"
|
|
|
|
" attached to interface <interface>\n"
|
|
|
|
);
|