blob: 05bb21035df2781fb975057515af9135dd55e89c [file] [log] [blame]
B, Ravi52f2acc2016-07-28 17:39:16 +05301/*
2 * (C) Copyright 2016
3 * Texas Instruments, <www.ti.com>
4 *
5 * Ravi B <ravibabu@ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9#include <common.h>
10#include <spl.h>
11#include <linux/compiler.h>
12#include <errno.h>
13#include <watchdog.h>
14#include <console.h>
15#include <g_dnl.h>
16#include <usb.h>
17#include <dfu.h>
18#include <environment.h>
19
20static int run_dfu(int usb_index, char *interface, char *devstring)
21{
22 int ret;
23
24 ret = dfu_init_env_entities(interface, devstring);
25 if (ret) {
26 dfu_free_entities();
27 goto exit;
28 }
29
30 run_usb_dnl_gadget(usb_index, "usb_dnl_dfu");
31exit:
32 dfu_free_entities();
33 return ret;
34}
35
36int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr)
37{
38 char *str_env;
39 int ret;
40
41 /* set default environment */
42 set_default_env(0);
Simon Glass00caae62017-08-03 12:22:12 -060043 str_env = env_get(dfu_alt_info);
B, Ravi52f2acc2016-07-28 17:39:16 +053044 if (!str_env) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090045 pr_err("\"dfu_alt_info\" env variable not defined!\n");
B, Ravi52f2acc2016-07-28 17:39:16 +053046 return -EINVAL;
47 }
48
Simon Glass382bee52017-08-03 12:22:09 -060049 ret = env_set("dfu_alt_info", str_env);
B, Ravi52f2acc2016-07-28 17:39:16 +053050 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090051 pr_err("unable to set env variable \"dfu_alt_info\"!\n");
B, Ravi52f2acc2016-07-28 17:39:16 +053052 return -EINVAL;
53 }
54
55 /* invoke dfu command */
56 return run_dfu(usbctrl, interface, devstr);
57}