Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
B, Ravi | d207b7e | 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 | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 7 | */ |
| 8 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 9 | #include <env.h> |
B, Ravi | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 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> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 18 | #include <linux/printk.h> |
B, Ravi | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 19 | |
| 20 | static 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"); |
| 31 | exit: |
| 32 | dfu_free_entities(); |
| 33 | return ret; |
| 34 | } |
| 35 | |
| 36 | int 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 */ |
Simon Glass | 9738586 | 2019-08-01 09:47:00 -0600 | [diff] [blame] | 42 | env_set_default(NULL, 0); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 43 | str_env = env_get(dfu_alt_info); |
B, Ravi | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 44 | if (!str_env) { |
Marek Vasut | c1abd50 | 2019-05-25 22:50:35 +0200 | [diff] [blame] | 45 | pr_err("\"%s\" env variable not defined!\n", dfu_alt_info); |
B, Ravi | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 46 | return -EINVAL; |
| 47 | } |
| 48 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 49 | ret = env_set("dfu_alt_info", str_env); |
B, Ravi | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 50 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 51 | pr_err("unable to set env variable \"dfu_alt_info\"!\n"); |
B, Ravi | d207b7e | 2016-07-28 17:39:16 +0530 | [diff] [blame] | 52 | return -EINVAL; |
| 53 | } |
| 54 | |
| 55 | /* invoke dfu command */ |
| 56 | return run_dfu(usbctrl, interface, devstr); |
| 57 | } |