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 #include <linux/stringify.h>
19 static int do_fastboot_udp(int argc, char *const argv[],
20 uintptr_t buf_addr, size_t buf_size)
22 #if CONFIG_IS_ENABLED(UDP_FUNCTION_FASTBOOT)
23 int err = net_loop(FASTBOOT);
26 printf("fastboot udp error: %d\n", err);
27 return CMD_RET_FAILURE;
30 return CMD_RET_SUCCESS;
32 pr_err("Fastboot UDP not enabled\n");
33 return CMD_RET_FAILURE;
37 static int do_fastboot_usb(int argc, char *const argv[],
38 uintptr_t buf_addr, size_t buf_size)
40 #if CONFIG_IS_ENABLED(USB_FUNCTION_FASTBOOT)
49 usb_controller = argv[1];
50 controller_index = simple_strtoul(usb_controller, &endp, 0);
52 pr_err("Error: Wrong USB controller index format\n");
53 return CMD_RET_FAILURE;
56 ret = usb_gadget_initialize(controller_index);
58 pr_err("USB init failed: %d\n", ret);
59 return CMD_RET_FAILURE;
63 ret = g_dnl_register("usb_dnl_fastboot");
67 if (!g_dnl_board_usb_cable_connected()) {
68 puts("\rUSB cable not detected.\n" \
70 ret = CMD_RET_FAILURE;
80 usb_gadget_handle_interrupts(controller_index);
83 ret = CMD_RET_SUCCESS;
88 usb_gadget_release(controller_index);
92 pr_err("Fastboot USB not enabled\n");
93 return CMD_RET_FAILURE;
97 static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
100 uintptr_t buf_addr = (uintptr_t)NULL;
104 return CMD_RET_USAGE;
106 while (argc > 1 && **(argv + 1) == '-') {
114 return CMD_RET_USAGE;
115 buf_addr = simple_strtoul(*++argv, NULL, 16);
120 return CMD_RET_USAGE;
121 buf_size = simple_strtoul(*++argv, NULL, 16);
125 return CMD_RET_USAGE;
132 /* Handle case when USB controller param is just '-' */
134 pr_err("Error: Incorrect USB controller index\n");
135 return CMD_RET_USAGE;
138 fastboot_init((void *)buf_addr, buf_size);
140 if (!strcmp(argv[1], "udp"))
141 return do_fastboot_udp(argc, argv, buf_addr, buf_size);
143 if (!strcmp(argv[1], "usb")) {
148 return do_fastboot_usb(argc, argv, buf_addr, buf_size);
151 #ifdef CONFIG_SYS_LONGHELP
152 static char fastboot_help_text[] =
153 "[-l addr] [-s size] usb <controller> | udp\n"
154 "\taddr - address of buffer used during data transfers ("
155 __stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
156 "\tsize - size of buffer used during data transfers ("
157 __stringify(CONFIG_FASTBOOT_BUF_SIZE) ")"
162 fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
163 "run as a fastboot usb or udp device", fastboot_help_text