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>
16 #include <linux/printk.h>
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
)
24 if (!IS_ENABLED(CONFIG_UDP_FUNCTION_FASTBOOT
)) {
25 pr_err("Fastboot UDP not enabled\n");
26 return CMD_RET_FAILURE
;
29 err
= net_loop(FASTBOOT_UDP
);
32 printf("fastboot udp error: %d\n", err
);
33 return CMD_RET_FAILURE
;
36 return CMD_RET_SUCCESS
;
39 static int do_fastboot_tcp(int argc
, char *const argv
[],
40 uintptr_t buf_addr
, size_t buf_size
)
44 if (!IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT
)) {
45 pr_err("Fastboot TCP not enabled\n");
46 return CMD_RET_FAILURE
;
49 err
= net_loop(FASTBOOT_TCP
);
52 printf("fastboot tcp error: %d\n", err
);
53 return CMD_RET_FAILURE
;
56 return CMD_RET_SUCCESS
;
59 static int do_fastboot_usb(int argc
, char *const argv
[],
60 uintptr_t buf_addr
, size_t buf_size
)
68 if (!IS_ENABLED(CONFIG_USB_FUNCTION_FASTBOOT
)) {
69 pr_err("Fastboot USB not enabled\n");
70 return CMD_RET_FAILURE
;
76 usb_controller
= argv
[1];
77 controller_index
= simple_strtoul(usb_controller
, &endp
, 0);
79 pr_err("Error: Wrong USB controller index format\n");
80 return CMD_RET_FAILURE
;
83 ret
= udc_device_get_by_index(controller_index
, &udc
);
85 pr_err("USB init failed: %d\n", ret
);
86 return CMD_RET_FAILURE
;
90 ret
= g_dnl_register("usb_dnl_fastboot");
94 if (!g_dnl_board_usb_cable_connected()) {
95 puts("\rUSB cable not detected.\n" \
97 ret
= CMD_RET_FAILURE
;
107 dm_usb_gadget_handle_interrupts(udc
);
110 ret
= CMD_RET_SUCCESS
;
115 g_dnl_clear_detach();
120 static int do_fastboot(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
123 uintptr_t buf_addr
= (uintptr_t)NULL
;
127 return CMD_RET_USAGE
;
129 while (argc
> 1 && **(argv
+ 1) == '-') {
137 return CMD_RET_USAGE
;
138 buf_addr
= hextoul(*++argv
, NULL
);
143 return CMD_RET_USAGE
;
144 buf_size
= hextoul(*++argv
, NULL
);
148 return CMD_RET_USAGE
;
155 /* Handle case when USB controller param is just '-' */
157 pr_err("Error: Incorrect USB controller index\n");
158 return CMD_RET_USAGE
;
161 fastboot_init((void *)buf_addr
, buf_size
);
163 if (!strcmp(argv
[1], "udp"))
164 return do_fastboot_udp(argc
, argv
, buf_addr
, buf_size
);
165 if (!strcmp(argv
[1], "tcp"))
166 return do_fastboot_tcp(argc
, argv
, buf_addr
, buf_size
);
167 if (!strcmp(argv
[1], "usb")) {
172 return do_fastboot_usb(argc
, argv
, buf_addr
, buf_size
);
176 fastboot
, CONFIG_SYS_MAXARGS
, 1, do_fastboot
,
177 "run as a fastboot usb or udp device",
178 "[-l addr] [-s size] usb <controller> | udp\n"
179 "\taddr - address of buffer used during data transfers ("
180 __stringify(CONFIG_FASTBOOT_BUF_ADDR
) ")\n"
181 "\tsize - size of buffer used during data transfers ("
182 __stringify(CONFIG_FASTBOOT_BUF_SIZE
) ")"