]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
3402b053 ŁM |
2 | /* |
3 | * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget | |
4 | * | |
5 | * Copyright (C) 2013 Lukasz Majewski <[email protected]> | |
6 | * All rights reserved. | |
3402b053 ŁM |
7 | */ |
8 | ||
d678a59d | 9 | #include <common.h> |
09140113 | 10 | #include <command.h> |
3402b053 ŁM |
11 | #include <thor.h> |
12 | #include <dfu.h> | |
13 | #include <g_dnl.h> | |
14 | #include <usb.h> | |
1e94b46f | 15 | #include <linux/printk.h> |
3402b053 | 16 | |
09140113 | 17 | int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
3402b053 | 18 | { |
76dd4594 MV |
19 | char *interface, *devstring; |
20 | int controller_index; | |
5b8c9d1b | 21 | struct udevice *udc; |
76dd4594 MV |
22 | int ret; |
23 | ||
3402b053 ŁM |
24 | if (argc < 4) |
25 | return CMD_RET_USAGE; | |
26 | ||
3402b053 ŁM |
27 | puts("TIZEN \"THOR\" Downloader\n"); |
28 | ||
76dd4594 MV |
29 | interface = argv[2]; |
30 | devstring = argv[3]; | |
31 | ||
90fadb57 | 32 | ret = dfu_init_env_entities(interface, devstring); |
3402b053 | 33 | if (ret) |
90fadb57 | 34 | goto done; |
3402b053 | 35 | |
76dd4594 | 36 | controller_index = simple_strtoul(argv[1], NULL, 0); |
5b8c9d1b | 37 | ret = udc_device_get_by_index(controller_index, &udc); |
3402b053 | 38 | if (ret) { |
71002b50 | 39 | pr_err("USB init failed: %d\n", ret); |
3402b053 ŁM |
40 | ret = CMD_RET_FAILURE; |
41 | goto exit; | |
42 | } | |
43 | ||
ed3a37a2 MS |
44 | ret = g_dnl_register("usb_dnl_thor"); |
45 | if (ret) { | |
46 | pr_err("g_dnl_register failed %d\n", ret); | |
0896d2ca MS |
47 | ret = CMD_RET_FAILURE; |
48 | goto exit; | |
ed3a37a2 | 49 | } |
3402b053 | 50 | |
5b8c9d1b | 51 | ret = thor_init(udc); |
3402b053 | 52 | if (ret) { |
71002b50 | 53 | pr_err("THOR DOWNLOAD failed: %d\n", ret); |
3402b053 ŁM |
54 | ret = CMD_RET_FAILURE; |
55 | goto exit; | |
56 | } | |
57 | ||
e47431aa | 58 | do { |
5b8c9d1b | 59 | ret = thor_handle(udc); |
e47431aa MS |
60 | if (ret == THOR_DFU_REINIT_NEEDED) { |
61 | dfu_free_entities(); | |
62 | ret = dfu_init_env_entities(interface, devstring); | |
63 | } | |
64 | if (ret) { | |
65 | pr_err("THOR failed: %d\n", ret); | |
66 | ret = CMD_RET_FAILURE; | |
67 | goto exit; | |
68 | } | |
69 | } while (ret == 0); | |
3402b053 ŁM |
70 | exit: |
71 | g_dnl_unregister(); | |
5b8c9d1b | 72 | udc_device_put(udc); |
90fadb57 | 73 | done: |
3402b053 ŁM |
74 | dfu_free_entities(); |
75 | ||
76 | return ret; | |
77 | } | |
78 | ||
79 | U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down, | |
80 | "TIZEN \"THOR\" downloader", | |
81 | "<USB_controller> <interface> <dev>\n" | |
c8087f67 | 82 | " - device software upgrade via LTHOR TIZEN download\n" |
3402b053 ŁM |
83 | " program via <USB_controller> on device <dev>,\n" |
84 | " attached to interface <interface>\n" | |
85 | ); |