Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
B, Ravi | 52f2acc | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 |
| 4 | * Texas Instruments, <www.ti.com> |
| 5 | * |
| 6 | * Ravi B <ravibabu@ti.com> |
B, Ravi | 52f2acc | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 7 | */ |
| 8 | #include <common.h> |
| 9 | #include <spl.h> |
| 10 | #include <linux/compiler.h> |
| 11 | #include <errno.h> |
| 12 | #include <watchdog.h> |
| 13 | #include <console.h> |
| 14 | #include <g_dnl.h> |
| 15 | #include <usb.h> |
| 16 | #include <dfu.h> |
| 17 | #include <environment.h> |
| 18 | |
| 19 | static int run_dfu(int usb_index, char *interface, char *devstring) |
| 20 | { |
| 21 | int ret; |
| 22 | |
| 23 | ret = dfu_init_env_entities(interface, devstring); |
| 24 | if (ret) { |
| 25 | dfu_free_entities(); |
| 26 | goto exit; |
| 27 | } |
| 28 | |
| 29 | run_usb_dnl_gadget(usb_index, "usb_dnl_dfu"); |
| 30 | exit: |
| 31 | dfu_free_entities(); |
| 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr) |
| 36 | { |
| 37 | char *str_env; |
| 38 | int ret; |
| 39 | |
| 40 | /* set default environment */ |
Yaniv Levinsky | c5d548a | 2018-06-24 19:16:57 +0300 | [diff] [blame] | 41 | set_default_env(NULL, 0); |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 42 | str_env = env_get(dfu_alt_info); |
B, Ravi | 52f2acc | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 43 | if (!str_env) { |
Marek Vasut | 634931f | 2019-05-25 22:50:35 +0200 | [diff] [blame] | 44 | pr_err("\"%s\" env variable not defined!\n", dfu_alt_info); |
B, Ravi | 52f2acc | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 45 | return -EINVAL; |
| 46 | } |
| 47 | |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 48 | ret = env_set("dfu_alt_info", str_env); |
B, Ravi | 52f2acc | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 49 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 50 | pr_err("unable to set env variable \"dfu_alt_info\"!\n"); |
B, Ravi | 52f2acc | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 51 | return -EINVAL; |
| 52 | } |
| 53 | |
| 54 | /* invoke dfu command */ |
| 55 | return run_dfu(usbctrl, interface, devstr); |
| 56 | } |