Merge tag 'xilinx-for-v2025.01-rc3-v2' of https://source.denx.de/u-boot/custodians...
[u-boot.git] / cmd / thordown.c
blob70061bf8d4cccb4013b1b83310806f2ae197f576
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
5 * Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
6 * All rights reserved.
7 */
9 #include <command.h>
10 #include <thor.h>
11 #include <dfu.h>
12 #include <g_dnl.h>
13 #include <usb.h>
14 #include <linux/printk.h>
16 int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
18 char *interface, *devstring;
19 int controller_index;
20 struct udevice *udc;
21 int ret;
23 if (argc < 4)
24 return CMD_RET_USAGE;
26 puts("TIZEN \"THOR\" Downloader\n");
28 interface = argv[2];
29 devstring = argv[3];
31 ret = dfu_init_env_entities(interface, devstring);
32 if (ret)
33 goto done;
35 controller_index = simple_strtoul(argv[1], NULL, 0);
36 ret = udc_device_get_by_index(controller_index, &udc);
37 if (ret) {
38 pr_err("USB init failed: %d\n", ret);
39 ret = CMD_RET_FAILURE;
40 goto exit;
43 ret = g_dnl_register("usb_dnl_thor");
44 if (ret) {
45 pr_err("g_dnl_register failed %d\n", ret);
46 ret = CMD_RET_FAILURE;
47 goto exit;
50 ret = thor_init(udc);
51 if (ret) {
52 pr_err("THOR DOWNLOAD failed: %d\n", ret);
53 ret = CMD_RET_FAILURE;
54 goto exit;
57 do {
58 ret = thor_handle(udc);
59 if (ret == THOR_DFU_REINIT_NEEDED) {
60 dfu_free_entities();
61 ret = dfu_init_env_entities(interface, devstring);
63 if (ret) {
64 pr_err("THOR failed: %d\n", ret);
65 ret = CMD_RET_FAILURE;
66 goto exit;
68 } while (ret == 0);
69 exit:
70 g_dnl_unregister();
71 udc_device_put(udc);
72 done:
73 dfu_free_entities();
75 return ret;
78 U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
79 "TIZEN \"THOR\" downloader",
80 "<USB_controller> <interface> <dev>\n"
81 " - device software upgrade via LTHOR TIZEN download\n"
82 " program via <USB_controller> on device <dev>,\n"
83 " attached to interface <interface>\n"