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