Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | 3402b05 | 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 | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <command.h> |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 11 | #include <thor.h> |
| 12 | #include <dfu.h> |
| 13 | #include <g_dnl.h> |
| 14 | #include <usb.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 15 | #include <linux/printk.h> |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 16 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 17 | int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 18 | { |
Marek Vasut | 76dd459 | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 19 | char *interface, *devstring; |
| 20 | int controller_index; |
Marek Vasut | 5b8c9d1 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 21 | struct udevice *udc; |
Marek Vasut | 76dd459 | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 22 | int ret; |
| 23 | |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 24 | if (argc < 4) |
| 25 | return CMD_RET_USAGE; |
| 26 | |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 27 | puts("TIZEN \"THOR\" Downloader\n"); |
| 28 | |
Marek Vasut | 76dd459 | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 29 | interface = argv[2]; |
| 30 | devstring = argv[3]; |
| 31 | |
Lukasz Majewski | 90fadb5 | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 32 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 33 | if (ret) |
Lukasz Majewski | 90fadb5 | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 34 | goto done; |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 35 | |
Marek Vasut | 76dd459 | 2023-09-01 11:49:53 +0200 | [diff] [blame] | 36 | controller_index = simple_strtoul(argv[1], NULL, 0); |
Marek Vasut | 5b8c9d1 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 37 | ret = udc_device_get_by_index(controller_index, &udc); |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 38 | if (ret) { |
Seung-Woo Kim | 71002b5 | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 39 | pr_err("USB init failed: %d\n", ret); |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 40 | ret = CMD_RET_FAILURE; |
| 41 | goto exit; |
| 42 | } |
| 43 | |
Marek Szyprowski | ed3a37a | 2019-06-21 15:39:29 +0200 | [diff] [blame] | 44 | ret = g_dnl_register("usb_dnl_thor"); |
| 45 | if (ret) { |
| 46 | pr_err("g_dnl_register failed %d\n", ret); |
Marek Szyprowski | 0896d2c | 2019-10-02 14:29:21 +0200 | [diff] [blame] | 47 | ret = CMD_RET_FAILURE; |
| 48 | goto exit; |
Marek Szyprowski | ed3a37a | 2019-06-21 15:39:29 +0200 | [diff] [blame] | 49 | } |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 50 | |
Marek Vasut | 5b8c9d1 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 51 | ret = thor_init(udc); |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 52 | if (ret) { |
Seung-Woo Kim | 71002b5 | 2018-06-04 16:04:51 +0900 | [diff] [blame] | 53 | pr_err("THOR DOWNLOAD failed: %d\n", ret); |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 54 | ret = CMD_RET_FAILURE; |
| 55 | goto exit; |
| 56 | } |
| 57 | |
Marek Szyprowski | e47431a | 2020-12-22 11:32:24 +0100 | [diff] [blame] | 58 | do { |
Marek Vasut | 5b8c9d1 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 59 | ret = thor_handle(udc); |
Marek Szyprowski | e47431a | 2020-12-22 11:32:24 +0100 | [diff] [blame] | 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); |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 70 | exit: |
| 71 | g_dnl_unregister(); |
Marek Vasut | 5b8c9d1 | 2023-09-01 11:49:59 +0200 | [diff] [blame] | 72 | udc_device_put(udc); |
Lukasz Majewski | 90fadb5 | 2014-06-23 09:39:16 +0200 | [diff] [blame] | 73 | done: |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 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" |
Vagrant Cascadian | c8087f6 | 2019-03-05 22:52:14 -0800 | [diff] [blame] | 82 | " - device software upgrade via LTHOR TIZEN download\n" |
Lukasz Majewski | 3402b05 | 2013-10-08 14:30:44 +0200 | [diff] [blame] | 83 | " program via <USB_controller> on device <dev>,\n" |
| 84 | " attached to interface <interface>\n" |
| 85 | ); |