blob: 8dae024e31db2bc601c617c4a302932a66a5e4bf [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>
10#include <thor.h>
11#include <dfu.h>
12#include <g_dnl.h>
13#include <usb.h>
14
15int 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 Majewski3402b052013-10-08 14:30:44 +020024 int ret;
25
26 puts("TIZEN \"THOR\" Downloader\n");
27
Lukasz Majewski90fadb52014-06-23 09:39:16 +020028 ret = dfu_init_env_entities(interface, devstring);
Lukasz Majewski3402b052013-10-08 14:30:44 +020029 if (ret)
Lukasz Majewski90fadb52014-06-23 09:39:16 +020030 goto done;
Lukasz Majewski3402b052013-10-08 14:30:44 +020031
32 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Jean-Jacques Hiblota06955a2018-11-29 10:52:41 +010033 ret = usb_gadget_initialize(controller_index);
Lukasz Majewski3402b052013-10-08 14:30:44 +020034 if (ret) {
Seung-Woo Kim71002b52018-06-04 16:04:51 +090035 pr_err("USB init failed: %d\n", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020036 ret = CMD_RET_FAILURE;
37 goto exit;
38 }
39
Marek Szyprowskied3a37a2019-06-21 15:39:29 +020040 ret = g_dnl_register("usb_dnl_thor");
41 if (ret) {
42 pr_err("g_dnl_register failed %d\n", ret);
Marek Szyprowski0896d2c2019-10-02 14:29:21 +020043 ret = CMD_RET_FAILURE;
44 goto exit;
Marek Szyprowskied3a37a2019-06-21 15:39:29 +020045 }
Lukasz Majewski3402b052013-10-08 14:30:44 +020046
47 ret = thor_init();
48 if (ret) {
Seung-Woo Kim71002b52018-06-04 16:04:51 +090049 pr_err("THOR DOWNLOAD failed: %d\n", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020050 ret = CMD_RET_FAILURE;
51 goto exit;
52 }
53
54 ret = thor_handle();
55 if (ret) {
Seung-Woo Kim71002b52018-06-04 16:04:51 +090056 pr_err("THOR failed: %d\n", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020057 ret = CMD_RET_FAILURE;
58 goto exit;
59 }
60
61exit:
62 g_dnl_unregister();
Jean-Jacques Hiblota06955a2018-11-29 10:52:41 +010063 usb_gadget_release(controller_index);
Lukasz Majewski90fadb52014-06-23 09:39:16 +020064done:
Lukasz Majewski3402b052013-10-08 14:30:44 +020065 dfu_free_entities();
66
67 return ret;
68}
69
70U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
71 "TIZEN \"THOR\" downloader",
72 "<USB_controller> <interface> <dev>\n"
Vagrant Cascadianc8087f62019-03-05 22:52:14 -080073 " - device software upgrade via LTHOR TIZEN download\n"
Lukasz Majewski3402b052013-10-08 14:30:44 +020074 " program via <USB_controller> on device <dev>,\n"
75 " attached to interface <interface>\n"
76);