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 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <command.h> |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 10 | #include <thor.h> |
| 11 | #include <dfu.h> |
| 12 | #include <g_dnl.h> |
| 13 | #include <usb.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 14 | #include <linux/printk.h> |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 15 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 16 | int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 17 | { |
Marek Vasut | 01336ab | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 18 | char *interface, *devstring; |
| 19 | int controller_index; |
Marek Vasut | 8bfcb34 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 20 | struct udevice *udc; |
Marek Vasut | 01336ab | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 21 | int ret; |
| 22 | |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 23 | if (argc < 4) |
| 24 | return CMD_RET_USAGE; |
| 25 | |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 26 | puts("TIZEN \"THOR\" Downloader\n"); |
| 27 | |
Marek Vasut | 01336ab | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 28 | interface = argv[2]; |
| 29 | devstring = argv[3]; |
| 30 | |
Lukasz Majewski | 301f38a | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 31 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 32 | if (ret) |
Lukasz Majewski | 301f38a | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 33 | goto done; |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 34 | |
Marek Vasut | 01336ab | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 35 | controller_index = simple_strtoul(argv[1], NULL, 0); |
Marek Vasut | 8bfcb34 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 36 | ret = udc_device_get_by_index(controller_index, &udc); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 37 | if (ret) { |
Seung-Woo Kim | 591188e | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 38 | pr_err("USB init failed: %d\n", ret); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 39 | ret = CMD_RET_FAILURE; |
| 40 | goto exit; |
| 41 | } |
| 42 | |
Marek Szyprowski | c7eaa8b | 2019-06-21 15:39:29 +0200 | [diff] [blame] | 43 | ret = g_dnl_register("usb_dnl_thor"); |
| 44 | if (ret) { |
| 45 | pr_err("g_dnl_register failed %d\n", ret); |
Marek Szyprowski | af23348 | 2019-10-02 14:29:21 +0200 | [diff] [blame] | 46 | ret = CMD_RET_FAILURE; |
| 47 | goto exit; |
Marek Szyprowski | c7eaa8b | 2019-06-21 15:39:29 +0200 | [diff] [blame] | 48 | } |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 49 | |
Marek Vasut | 8bfcb34 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 50 | ret = thor_init(udc); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 51 | if (ret) { |
Seung-Woo Kim | 591188e | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 52 | pr_err("THOR DOWNLOAD failed: %d\n", ret); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 53 | ret = CMD_RET_FAILURE; |
| 54 | goto exit; |
| 55 | } |
| 56 | |
Marek Szyprowski | ee9b855 | 2020-12-22 11:32:24 +0100 | [diff] [blame] | 57 | do { |
Marek Vasut | 8bfcb34 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 58 | ret = thor_handle(udc); |
Marek Szyprowski | ee9b855 | 2020-12-22 11:32:24 +0100 | [diff] [blame] | 59 | if (ret == THOR_DFU_REINIT_NEEDED) { |
| 60 | dfu_free_entities(); |
| 61 | ret = dfu_init_env_entities(interface, devstring); |
| 62 | } |
| 63 | if (ret) { |
| 64 | pr_err("THOR failed: %d\n", ret); |
| 65 | ret = CMD_RET_FAILURE; |
| 66 | goto exit; |
| 67 | } |
| 68 | } while (ret == 0); |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 69 | exit: |
| 70 | g_dnl_unregister(); |
Marek Vasut | 8bfcb34 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 71 | udc_device_put(udc); |
Lukasz Majewski | 301f38a | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 72 | done: |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 73 | dfu_free_entities(); |
| 74 | |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down, |
| 79 | "TIZEN \"THOR\" downloader", |
| 80 | "<USB_controller> <interface> <dev>\n" |
Vagrant Cascadian | ab7797e | 2019-03-05 22:52:14 -0800 | [diff] [blame] | 81 | " - device software upgrade via LTHOR TIZEN download\n" |
Lukasz Majewski | 32dc389 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 82 | " program via <USB_controller> on device <dev>,\n" |
| 83 | " attached to interface <interface>\n" |
| 84 | ); |