1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2008 - 2009 Windriver, <www.windriver.com>
4 * Author: Tom Rix <Tom.Rix@windriver.com>
6 * (C) Copyright 2014 Linaro, Ltd.
7 * Rob Herring <robh@kernel.org>
17 static int do_fastboot_udp(int argc, char *const argv[],
18 uintptr_t buf_addr, size_t buf_size)
20 #if CONFIG_IS_ENABLED(UDP_FUNCTION_FASTBOOT)
21 int err = net_loop(FASTBOOT);
24 printf("fastboot udp error: %d\n", err);
25 return CMD_RET_FAILURE;
28 return CMD_RET_SUCCESS;
30 pr_err("Fastboot UDP not enabled\n");
31 return CMD_RET_FAILURE;
35 static int do_fastboot_usb(int argc, char *const argv[],
36 uintptr_t buf_addr, size_t buf_size)
38 #if CONFIG_IS_ENABLED(USB_FUNCTION_FASTBOOT)
47 usb_controller = argv[1];
48 controller_index = simple_strtoul(usb_controller, &endp, 0);
50 pr_err("Error: Wrong USB controller index format\n");
51 return CMD_RET_FAILURE;
54 ret = board_usb_init(controller_index, USB_INIT_DEVICE);
56 pr_err("USB init failed: %d\n", ret);
57 return CMD_RET_FAILURE;
61 ret = g_dnl_register("usb_dnl_fastboot");
65 if (!g_dnl_board_usb_cable_connected()) {
66 puts("\rUSB cable not detected.\n" \
68 ret = CMD_RET_FAILURE;
77 usb_gadget_handle_interrupts(controller_index);
80 ret = CMD_RET_SUCCESS;
85 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
89 pr_err("Fastboot USB not enabled\n");
90 return CMD_RET_FAILURE;
94 static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
96 uintptr_t buf_addr = (uintptr_t)NULL;
100 return CMD_RET_USAGE;
102 while (argc > 1 && **(argv + 1) == '-') {
110 return CMD_RET_USAGE;
111 buf_addr = simple_strtoul(*++argv, NULL, 16);
116 return CMD_RET_USAGE;
117 buf_size = simple_strtoul(*++argv, NULL, 16);
121 return CMD_RET_USAGE;
128 /* Handle case when USB controller param is just '-' */
130 pr_err("Error: Incorrect USB controller index\n");
131 return CMD_RET_USAGE;
134 fastboot_init((void *)buf_addr, buf_size);
136 if (!strcmp(argv[1], "udp"))
137 return do_fastboot_udp(argc, argv, buf_addr, buf_size);
139 if (!strcmp(argv[1], "usb")) {
144 return do_fastboot_usb(argc, argv, buf_addr, buf_size);
147 #ifdef CONFIG_SYS_LONGHELP
148 static char fastboot_help_text[] =
149 "[-l addr] [-s size] usb <controller> | udp\n"
150 "\taddr - address of buffer used during data transfers ("
151 __stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
152 "\tsize - size of buffer used during data transfers ("
153 __stringify(CONFIG_FASTBOOT_BUF_SIZE) ")"
158 fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
159 "run as a fastboot usb or udp device", fastboot_help_text