cmd_fastboot.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <g_dnl.h>
  13. #include <usb.h>
  14. static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  15. {
  16. int controller_index;
  17. char *usb_controller;
  18. int ret;
  19. if (argc < 2)
  20. return CMD_RET_USAGE;
  21. usb_controller = argv[1];
  22. controller_index = simple_strtoul(usb_controller, NULL, 0);
  23. ret = board_usb_init(controller_index, USB_INIT_DEVICE);
  24. if (ret) {
  25. error("USB init failed: %d", ret);
  26. return CMD_RET_FAILURE;
  27. }
  28. g_dnl_clear_detach();
  29. ret = g_dnl_register("usb_dnl_fastboot");
  30. if (ret)
  31. return ret;
  32. if (!g_dnl_board_usb_cable_connected()) {
  33. puts("\rUSB cable not detected.\n" \
  34. "Command exit.\n");
  35. ret = CMD_RET_FAILURE;
  36. goto exit;
  37. }
  38. while (1) {
  39. if (g_dnl_detach())
  40. break;
  41. if (ctrlc())
  42. break;
  43. usb_gadget_handle_interrupts(controller_index);
  44. }
  45. ret = CMD_RET_SUCCESS;
  46. exit:
  47. g_dnl_unregister();
  48. g_dnl_clear_detach();
  49. board_usb_cleanup(controller_index, USB_INIT_DEVICE);
  50. return ret;
  51. }
  52. U_BOOT_CMD(
  53. fastboot, 2, 1, do_fastboot,
  54. "use USB Fastboot protocol",
  55. "<USB_controller>\n"
  56. " - run as a fastboot usb device"
  57. );