thordown.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * cmd_thordown.c -- USB TIZEN "THOR" Downloader gadget
  4. *
  5. * Copyright (C) 2013 Lukasz Majewski <l.majewski@samsung.com>
  6. * All rights reserved.
  7. */
  8. #include <common.h>
  9. #include <thor.h>
  10. #include <dfu.h>
  11. #include <g_dnl.h>
  12. #include <usb.h>
  13. int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  14. {
  15. if (argc < 4)
  16. return CMD_RET_USAGE;
  17. char *usb_controller = argv[1];
  18. char *interface = argv[2];
  19. char *devstring = argv[3];
  20. int ret;
  21. puts("TIZEN \"THOR\" Downloader\n");
  22. ret = dfu_init_env_entities(interface, devstring);
  23. if (ret)
  24. goto done;
  25. int controller_index = simple_strtoul(usb_controller, NULL, 0);
  26. ret = usb_gadget_initialize(controller_index);
  27. if (ret) {
  28. pr_err("USB init failed: %d\n", ret);
  29. ret = CMD_RET_FAILURE;
  30. goto exit;
  31. }
  32. ret = g_dnl_register("usb_dnl_thor");
  33. if (ret) {
  34. pr_err("g_dnl_register failed %d\n", ret);
  35. return ret;
  36. }
  37. ret = thor_init();
  38. if (ret) {
  39. pr_err("THOR DOWNLOAD failed: %d\n", ret);
  40. ret = CMD_RET_FAILURE;
  41. goto exit;
  42. }
  43. ret = thor_handle();
  44. if (ret) {
  45. pr_err("THOR failed: %d\n", ret);
  46. ret = CMD_RET_FAILURE;
  47. goto exit;
  48. }
  49. exit:
  50. g_dnl_unregister();
  51. usb_gadget_release(controller_index);
  52. done:
  53. dfu_free_entities();
  54. return ret;
  55. }
  56. U_BOOT_CMD(thordown, CONFIG_SYS_MAXARGS, 1, do_thor_down,
  57. "TIZEN \"THOR\" downloader",
  58. "<USB_controller> <interface> <dev>\n"
  59. " - device software upgrade via LTHOR TIZEN download\n"
  60. " program via <USB_controller> on device <dev>,\n"
  61. " attached to interface <interface>\n"
  62. );