fastboot.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2008 - 2009 Windriver, <www.windriver.com>
  3. * Author: Tom Rix <Tom.Rix@windriver.com>
  4. *
  5. * (C) Copyright 2014 Linaro, Ltd.
  6. * Rob Herring <robh@kernel.org>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <command.h>
  12. #include <console.h>
  13. #include <g_dnl.h>
  14. #include <usb.h>
  15. static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  16. {
  17. int controller_index;
  18. char *usb_controller;
  19. int ret;
  20. if (argc < 2)
  21. return CMD_RET_USAGE;
  22. usb_controller = argv[1];
  23. controller_index = simple_strtoul(usb_controller, NULL, 0);
  24. ret = board_usb_init(controller_index, USB_INIT_DEVICE);
  25. if (ret) {
  26. error("USB init failed: %d", ret);
  27. return CMD_RET_FAILURE;
  28. }
  29. g_dnl_clear_detach();
  30. ret = g_dnl_register("usb_dnl_fastboot");
  31. if (ret)
  32. return ret;
  33. if (!g_dnl_board_usb_cable_connected()) {
  34. puts("\rUSB cable not detected.\n" \
  35. "Command exit.\n");
  36. ret = CMD_RET_FAILURE;
  37. goto exit;
  38. }
  39. while (1) {
  40. if (g_dnl_detach())
  41. break;
  42. if (ctrlc())
  43. break;
  44. usb_gadget_handle_interrupts(controller_index);
  45. }
  46. ret = CMD_RET_SUCCESS;
  47. exit:
  48. g_dnl_unregister();
  49. g_dnl_clear_detach();
  50. board_usb_cleanup(controller_index, USB_INIT_DEVICE);
  51. return ret;
  52. }
  53. U_BOOT_CMD(
  54. fastboot, 2, 1, do_fastboot,
  55. "use USB Fastboot protocol",
  56. "<USB_controller>\n"
  57. " - run as a fastboot usb device"
  58. );