Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 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. |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 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 | |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 24 | int ret; |
| 25 | |
| 26 | puts("TIZEN \"THOR\" Downloader\n"); |
| 27 | |
Lukasz Majewski | 301f38a | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 28 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 29 | if (ret) |
Lukasz Majewski | 301f38a | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 30 | goto done; |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 31 | |
| 32 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
Jean-Jacques Hiblot | 585e199 | 2018-11-29 10:52:41 +0100 | [diff] [blame] | 33 | ret = usb_gadget_initialize(controller_index); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 34 | if (ret) { |
Seung-Woo Kim | 591188e | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 35 | pr_err("USB init failed: %d\n", ret); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 36 | ret = CMD_RET_FAILURE; |
| 37 | goto exit; |
| 38 | } |
| 39 | |
Mateusz Zalega | 69cb0bb | 2014-04-28 21:13:28 +0200 | [diff] [blame] | 40 | g_dnl_register("usb_dnl_thor"); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 41 | |
| 42 | ret = thor_init(); |
| 43 | if (ret) { |
Seung-Woo Kim | 591188e | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 44 | pr_err("THOR DOWNLOAD failed: %d\n", ret); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 45 | ret = CMD_RET_FAILURE; |
| 46 | goto exit; |
| 47 | } |
| 48 | |
| 49 | ret = thor_handle(); |
| 50 | if (ret) { |
Seung-Woo Kim | 591188e | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 51 | pr_err("THOR failed: %d\n", ret); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 52 | ret = CMD_RET_FAILURE; |
| 53 | goto exit; |
| 54 | } |
| 55 | |
| 56 | exit: |
| 57 | g_dnl_unregister(); |
Jean-Jacques Hiblot | 585e199 | 2018-11-29 10:52:41 +0100 | [diff] [blame] | 58 | usb_gadget_release(controller_index); |
Lukasz Majewski | 301f38a | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 59 | done: |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 60 | dfu_free_entities(); |
| 61 | |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down, |
| 66 | "TIZEN \"THOR\" downloader", |
| 67 | "<USB_controller> <interface> <dev>\n" |
Vagrant Cascadian | ab7797e | 2019-03-05 22:52:14 -0800 | [diff] [blame] | 68 | " - device software upgrade via LTHOR TIZEN download\n" |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 69 | " program via <USB_controller> on device <dev>,\n" |
| 70 | " attached to interface <interface>\n" |
| 71 | ); |