Merge branch '2019-10-28-azure-ci-support'
[oweals/u-boot.git] / cmd / thordown.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
4  *
5  * Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
6  * All rights reserved.
7  */
8
9 #include <common.h>
10 #include <thor.h>
11 #include <dfu.h>
12 #include <g_dnl.h>
13 #include <usb.h>
14
15 int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
16 {
17         if (argc < 4)
18                 return CMD_RET_USAGE;
19
20         char *usb_controller = argv[1];
21         char *interface = argv[2];
22         char *devstring = argv[3];
23
24         int ret;
25
26         puts("TIZEN \"THOR\" Downloader\n");
27
28         ret = dfu_init_env_entities(interface, devstring);
29         if (ret)
30                 goto done;
31
32         int controller_index = simple_strtoul(usb_controller, NULL, 0);
33         ret = usb_gadget_initialize(controller_index);
34         if (ret) {
35                 pr_err("USB init failed: %d\n", ret);
36                 ret = CMD_RET_FAILURE;
37                 goto exit;
38         }
39
40         ret = g_dnl_register("usb_dnl_thor");
41         if (ret) {
42                 pr_err("g_dnl_register failed %d\n", ret);
43                 return ret;
44         }
45
46         ret = thor_init();
47         if (ret) {
48                 pr_err("THOR DOWNLOAD failed: %d\n", ret);
49                 ret = CMD_RET_FAILURE;
50                 goto exit;
51         }
52
53         ret = thor_handle();
54         if (ret) {
55                 pr_err("THOR failed: %d\n", ret);
56                 ret = CMD_RET_FAILURE;
57                 goto exit;
58         }
59
60 exit:
61         g_dnl_unregister();
62         usb_gadget_release(controller_index);
63 done:
64         dfu_free_entities();
65
66         return ret;
67 }
68
69 U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
70            "TIZEN \"THOR\" downloader",
71            "<USB_controller> <interface> <dev>\n"
72            "  - device software upgrade via LTHOR TIZEN download\n"
73            "    program via <USB_controller> on device <dev>,\n"
74            "    attached to interface <interface>\n"
75 );