blob: 838764ccef79b98ae9f9b029b90090c1cbe53695 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski3402b052013-10-08 14:30:44 +02002/*
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 Majewski3402b052013-10-08 14:30:44 +02007 */
8
9#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -060010#include <command.h>
Lukasz Majewski3402b052013-10-08 14:30:44 +020011#include <thor.h>
12#include <dfu.h>
13#include <g_dnl.h>
14#include <usb.h>
15
Simon Glass09140112020-05-10 11:40:03 -060016int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Lukasz Majewski3402b052013-10-08 14:30:44 +020017{
18 if (argc < 4)
19 return CMD_RET_USAGE;
20
21 char *usb_controller = argv[1];
22 char *interface = argv[2];
23 char *devstring = argv[3];
24
Lukasz Majewski3402b052013-10-08 14:30:44 +020025 int ret;
26
27 puts("TIZEN \"THOR\" Downloader\n");
28
Lukasz Majewski90fadb52014-06-23 09:39:16 +020029 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewski3402b052013-10-08 14:30:44 +020030 if (ret)
Lukasz Majewski90fadb52014-06-23 09:39:16 +020031 goto done;
Lukasz Majewski3402b052013-10-08 14:30:44 +020032
33 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Jean-Jacques Hiblota06955a2018-11-29 10:52:41 +010034 ret = usb_gadget_initialize(controller_index);
Lukasz Majewski3402b052013-10-08 14:30:44 +020035 if (ret) {
Seung-Woo Kim71002b52018-06-04 16:04:51 +090036 pr_err("USB init failed: %d\n", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020037 ret = CMD_RET_FAILURE;
38 goto exit;
39 }
40
Marek Szyprowskied3a37a2019-06-21 15:39:29 +020041 ret = g_dnl_register("usb_dnl_thor");
42 if (ret) {
43 pr_err("g_dnl_register failed %d\n", ret);
Marek Szyprowski0896d2c2019-10-02 14:29:21 +020044 ret = CMD_RET_FAILURE;
45 goto exit;
Marek Szyprowskied3a37a2019-06-21 15:39:29 +020046 }
Lukasz Majewski3402b052013-10-08 14:30:44 +020047
48 ret = thor_init();
49 if (ret) {
Seung-Woo Kim71002b52018-06-04 16:04:51 +090050 pr_err("THOR DOWNLOAD failed: %d\n", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020051 ret = CMD_RET_FAILURE;
52 goto exit;
53 }
54
Marek Szyprowskie47431a2020-12-22 11:32:24 +010055 do {
56 ret = thor_handle();
57 if (ret == THOR_DFU_REINIT_NEEDED) {
58 dfu_free_entities();
59 ret = dfu_init_env_entities(interface, devstring);
60 }
61 if (ret) {
62 pr_err("THOR failed: %d\n", ret);
63 ret = CMD_RET_FAILURE;
64 goto exit;
65 }
66 } while (ret == 0);
Lukasz Majewski3402b052013-10-08 14:30:44 +020067exit:
68 g_dnl_unregister();
Jean-Jacques Hiblota06955a2018-11-29 10:52:41 +010069 usb_gadget_release(controller_index);
Lukasz Majewski90fadb52014-06-23 09:39:16 +020070done:
Lukasz Majewski3402b052013-10-08 14:30:44 +020071 dfu_free_entities();
72
73 return ret;
74}
75
76U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
77 "TIZEN \"THOR\" downloader",
78 "<USB_controller> <interface> <dev>\n"
Vagrant Cascadianc8087f62019-03-05 22:52:14 -080079 " - device software upgrade via LTHOR TIZEN download\n"
Lukasz Majewski3402b052013-10-08 14:30:44 +020080 " program via <USB_controller> on device <dev>,\n"
81 " attached to interface <interface>\n"
82);