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>
18 static int do_fastboot_udp(int argc, char *const argv[],
19 uintptr_t buf_addr, size_t buf_size)
21 #if CONFIG_IS_ENABLED(UDP_FUNCTION_FASTBOOT)
22 int err = net_loop(FASTBOOT);
25 printf("fastboot udp error: %d\n", err);
26 return CMD_RET_FAILURE;
29 return CMD_RET_SUCCESS;
31 pr_err("Fastboot UDP not enabled\n");
32 return CMD_RET_FAILURE;
36 static int do_fastboot_usb(int argc, char *const argv[],
37 uintptr_t buf_addr, size_t buf_size)
39 #if CONFIG_IS_ENABLED(USB_FUNCTION_FASTBOOT)
48 usb_controller = argv[1];
49 controller_index = simple_strtoul(usb_controller, &endp, 0);
51 pr_err("Error: Wrong USB controller index format\n");
52 return CMD_RET_FAILURE;
55 ret = usb_gadget_initialize(controller_index);
57 pr_err("USB init failed: %d\n", ret);
58 return CMD_RET_FAILURE;
62 ret = g_dnl_register("usb_dnl_fastboot");
66 if (!g_dnl_board_usb_cable_connected()) {
67 puts("\rUSB cable not detected.\n" \
69 ret = CMD_RET_FAILURE;
79 usb_gadget_handle_interrupts(controller_index);
82 ret = CMD_RET_SUCCESS;
87 usb_gadget_release(controller_index);
91 pr_err("Fastboot USB not enabled\n");
92 return CMD_RET_FAILURE;
96 static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
98 uintptr_t buf_addr = (uintptr_t)NULL;
102 return CMD_RET_USAGE;
104 while (argc > 1 && **(argv + 1) == '-') {
112 return CMD_RET_USAGE;
113 buf_addr = simple_strtoul(*++argv, NULL, 16);
118 return CMD_RET_USAGE;
119 buf_size = simple_strtoul(*++argv, NULL, 16);
123 return CMD_RET_USAGE;
130 /* Handle case when USB controller param is just '-' */
132 pr_err("Error: Incorrect USB controller index\n");
133 return CMD_RET_USAGE;
136 fastboot_init((void *)buf_addr, buf_size);
138 if (!strcmp(argv[1], "udp"))
139 return do_fastboot_udp(argc, argv, buf_addr, buf_size);
141 if (!strcmp(argv[1], "usb")) {
146 return do_fastboot_usb(argc, argv, buf_addr, buf_size);
149 #ifdef CONFIG_SYS_LONGHELP
150 static char fastboot_help_text[] =
151 "[-l addr] [-s size] usb <controller> | udp\n"
152 "\taddr - address of buffer used during data transfers ("
153 __stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
154 "\tsize - size of buffer used during data transfers ("
155 __stringify(CONFIG_FASTBOOT_BUF_SIZE) ")"
160 fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
161 "run as a fastboot usb or udp device", fastboot_help_text