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 <net.h> 15 #include <usb.h> 16 17 static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 18 { 19 #ifdef CONFIG_USB_FUNCTION_FASTBOOT 20 int controller_index; 21 char *usb_controller; 22 int ret; 23 #endif 24 25 if (argc < 2) 26 return CMD_RET_USAGE; 27 28 if (!strcmp(argv[1], "udp")) { 29 #ifndef CONFIG_UDP_FUNCTION_FASTBOOT 30 error("Fastboot UDP not enabled\n"); 31 return -1; 32 #else 33 return do_fastboot_udp(cmdtp, flag, argc, argv); 34 #endif 35 } 36 37 if (strcmp(argv[1], "usb") || argc < 3) 38 return CMD_RET_USAGE; 39 40 #ifndef CONFIG_USB_FUNCTION_FASTBOOT 41 error("Fastboot USB not enabled\n"); 42 return -1; 43 #else 44 usb_controller = argv[2]; 45 controller_index = simple_strtoul(usb_controller, NULL, 0); 46 47 ret = board_usb_init(controller_index, USB_INIT_DEVICE); 48 if (ret) { 49 error("USB init failed: %d", ret); 50 return CMD_RET_FAILURE; 51 } 52 53 g_dnl_clear_detach(); 54 ret = g_dnl_register("usb_dnl_fastboot"); 55 if (ret) 56 return ret; 57 58 if (!g_dnl_board_usb_cable_connected()) { 59 puts("\rUSB cable not detected.\n" \ 60 "Command exit.\n"); 61 ret = CMD_RET_FAILURE; 62 goto exit; 63 } 64 65 while (1) { 66 if (g_dnl_detach()) 67 break; 68 if (ctrlc()) 69 break; 70 usb_gadget_handle_interrupts(controller_index); 71 } 72 73 ret = CMD_RET_SUCCESS; 74 75 exit: 76 g_dnl_unregister(); 77 g_dnl_clear_detach(); 78 board_usb_cleanup(controller_index, USB_INIT_DEVICE); 79 80 return ret; 81 #endif 82 } 83 84 U_BOOT_CMD( 85 fastboot, 3, 1, do_fastboot, 86 "use USB or UDP Fastboot protocol", 87 "[usb,udp] <USB_controller>\n" 88 " - run as a fastboot usb or udp device\n" 89 " usb: specify <USB_controller>\n" 90 " udp: requires ip_addr set and ethernet initialized\n" 91 ); 92