blob: 1bb5fc2ec23b91d152098f5cfd54a65ab2a6856c [file] [log] [blame]
Lukasz Majewski3402b052013-10-08 14:30:44 +02001/*
2 * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
3 *
4 * Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <thor.h>
12#include <dfu.h>
13#include <g_dnl.h>
14#include <usb.h>
15
16int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17{
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);
34 ret = board_usb_init(controller_index, USB_INIT_DEVICE);
35 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090036 pr_err("USB init failed: %d", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020037 ret = CMD_RET_FAILURE;
38 goto exit;
39 }
40
Mateusz Zalegac4d0e852014-04-28 21:13:28 +020041 g_dnl_register("usb_dnl_thor");
Lukasz Majewski3402b052013-10-08 14:30:44 +020042
43 ret = thor_init();
44 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090045 pr_err("THOR DOWNLOAD failed: %d", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020046 ret = CMD_RET_FAILURE;
47 goto exit;
48 }
49
50 ret = thor_handle();
51 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090052 pr_err("THOR failed: %d", ret);
Lukasz Majewski3402b052013-10-08 14:30:44 +020053 ret = CMD_RET_FAILURE;
54 goto exit;
55 }
56
57exit:
58 g_dnl_unregister();
Inha Songd2817302015-03-03 17:32:06 +010059 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
Lukasz Majewski90fadb52014-06-23 09:39:16 +020060done:
Lukasz Majewski3402b052013-10-08 14:30:44 +020061 dfu_free_entities();
62
63 return ret;
64}
65
66U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
67 "TIZEN \"THOR\" downloader",
68 "<USB_controller> <interface> <dev>\n"
69 " - device software upgrade via LTHOR TIZEN dowload\n"
70 " program via <USB_controller> on device <dev>,\n"
71 " attached to interface <interface>\n"
72);