spl_dfu.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  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. static int run_dfu(int usb_index, char *interface, char *devstring)
  20. {
  21. int ret;
  22. ret = dfu_init_env_entities(interface, devstring);
  23. if (ret) {
  24. dfu_free_entities();
  25. goto exit;
  26. }
  27. run_usb_dnl_gadget(usb_index, "usb_dnl_dfu");
  28. exit:
  29. dfu_free_entities();
  30. return ret;
  31. }
  32. int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr)
  33. {
  34. char *str_env;
  35. int ret;
  36. /* set default environment */
  37. set_default_env(0);
  38. str_env = getenv(dfu_alt_info);
  39. if (!str_env) {
  40. error("\"dfu_alt_info\" env variable not defined!\n");
  41. return -EINVAL;
  42. }
  43. ret = setenv("dfu_alt_info", str_env);
  44. if (ret) {
  45. error("unable to set env variable \"dfu_alt_info\"!\n");
  46. return -EINVAL;
  47. }
  48. /* invoke dfu command */
  49. return run_dfu(usbctrl, interface, devstr);
  50. }