]> Git Repo - u-boot.git/blame - cmd/fastboot.c
Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[u-boot.git] / cmd / fastboot.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
3aab70af
SS
2/*
3 * Copyright 2008 - 2009 Windriver, <www.windriver.com>
4 * Author: Tom Rix <[email protected]>
5 *
6 * (C) Copyright 2014 Linaro, Ltd.
7 * Rob Herring <[email protected]>
3aab70af 8 */
3aab70af 9#include <command.h>
24b852a7 10#include <console.h>
3aab70af 11#include <g_dnl.h>
f73a7df9
AK
12#include <fastboot.h>
13#include <net.h>
8d2f0039 14#include <usb.h>
731785df 15#include <watchdog.h>
1e94b46f 16#include <linux/printk.h>
1af3c7f4 17#include <linux/stringify.h>
3aab70af 18
f73a7df9
AK
19static int do_fastboot_udp(int argc, char *const argv[],
20 uintptr_t buf_addr, size_t buf_size)
3aab70af 21{
d0379900
PD
22 int err;
23
942b3096 24 if (!IS_ENABLED(CONFIG_UDP_FUNCTION_FASTBOOT)) {
d0379900
PD
25 pr_err("Fastboot UDP not enabled\n");
26 return CMD_RET_FAILURE;
27 }
28
443d3191 29 err = net_loop(FASTBOOT_UDP);
f73a7df9
AK
30
31 if (err < 0) {
32 printf("fastboot udp error: %d\n", err);
33 return CMD_RET_FAILURE;
34 }
35
36 return CMD_RET_SUCCESS;
f73a7df9
AK
37}
38
443d3191
DM
39static int do_fastboot_tcp(int argc, char *const argv[],
40 uintptr_t buf_addr, size_t buf_size)
41{
42 int err;
43
44 if (!IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT)) {
45 pr_err("Fastboot TCP not enabled\n");
46 return CMD_RET_FAILURE;
47 }
48
49 err = net_loop(FASTBOOT_TCP);
50
51 if (err < 0) {
52 printf("fastboot tcp error: %d\n", err);
53 return CMD_RET_FAILURE;
54 }
55
56 return CMD_RET_SUCCESS;
57}
58
f73a7df9
AK
59static int do_fastboot_usb(int argc, char *const argv[],
60 uintptr_t buf_addr, size_t buf_size)
61{
8d2f0039
PK
62 int controller_index;
63 char *usb_controller;
bac356c3 64 struct udevice *udc;
aa51579f 65 char *endp;
3aab70af
SS
66 int ret;
67
37407ac2 68 if (!IS_ENABLED(CONFIG_USB_FUNCTION_FASTBOOT)) {
d0379900
PD
69 pr_err("Fastboot USB not enabled\n");
70 return CMD_RET_FAILURE;
71 }
72
8d2f0039
PK
73 if (argc < 2)
74 return CMD_RET_USAGE;
75
76 usb_controller = argv[1];
aa51579f
SP
77 controller_index = simple_strtoul(usb_controller, &endp, 0);
78 if (*endp != '\0') {
79 pr_err("Error: Wrong USB controller index format\n");
80 return CMD_RET_FAILURE;
81 }
8d2f0039 82
bac356c3 83 ret = udc_device_get_by_index(controller_index, &udc);
8d2f0039 84 if (ret) {
71002b50 85 pr_err("USB init failed: %d\n", ret);
8d2f0039
PK
86 return CMD_RET_FAILURE;
87 }
88
267abc62 89 g_dnl_clear_detach();
3aab70af
SS
90 ret = g_dnl_register("usb_dnl_fastboot");
91 if (ret)
92 return ret;
93
7c23bcb9
RH
94 if (!g_dnl_board_usb_cable_connected()) {
95 puts("\rUSB cable not detected.\n" \
96 "Command exit.\n");
8d2f0039
PK
97 ret = CMD_RET_FAILURE;
98 goto exit;
7c23bcb9
RH
99 }
100
3aab70af 101 while (1) {
267abc62
RH
102 if (g_dnl_detach())
103 break;
3aab70af
SS
104 if (ctrlc())
105 break;
29caf930 106 schedule();
bac356c3 107 dm_usb_gadget_handle_interrupts(udc);
3aab70af
SS
108 }
109
8d2f0039
PK
110 ret = CMD_RET_SUCCESS;
111
112exit:
bac356c3 113 udc_device_put(udc);
3aab70af 114 g_dnl_unregister();
267abc62 115 g_dnl_clear_detach();
8d2f0039
PK
116
117 return ret;
f73a7df9
AK
118}
119
09140113
SG
120static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
121 char *const argv[])
f73a7df9
AK
122{
123 uintptr_t buf_addr = (uintptr_t)NULL;
124 size_t buf_size = 0;
125
126 if (argc < 2)
127 return CMD_RET_USAGE;
128
129 while (argc > 1 && **(argv + 1) == '-') {
130 char *arg = *++argv;
131
132 --argc;
133 while (*++arg) {
134 switch (*arg) {
135 case 'l':
136 if (--argc <= 0)
137 return CMD_RET_USAGE;
7e5f460e 138 buf_addr = hextoul(*++argv, NULL);
f73a7df9
AK
139 goto NXTARG;
140
141 case 's':
142 if (--argc <= 0)
143 return CMD_RET_USAGE;
7e5f460e 144 buf_size = hextoul(*++argv, NULL);
f73a7df9
AK
145 goto NXTARG;
146
147 default:
148 return CMD_RET_USAGE;
149 }
150 }
151NXTARG:
152 ;
153 }
154
aa51579f
SP
155 /* Handle case when USB controller param is just '-' */
156 if (argc == 1) {
157 pr_err("Error: Incorrect USB controller index\n");
158 return CMD_RET_USAGE;
159 }
160
cdd20e3f 161 fastboot_init((void *)buf_addr, buf_size);
f73a7df9
AK
162
163 if (!strcmp(argv[1], "udp"))
164 return do_fastboot_udp(argc, argv, buf_addr, buf_size);
443d3191
DM
165 if (!strcmp(argv[1], "tcp"))
166 return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
f73a7df9
AK
167 if (!strcmp(argv[1], "usb")) {
168 argv++;
169 argc--;
170 }
171
172 return do_fastboot_usb(argc, argv, buf_addr, buf_size);
3aab70af
SS
173}
174
d0379900
PD
175U_BOOT_CMD(
176 fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
177 "run as a fastboot usb or udp device",
f73a7df9
AK
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) ")"
3aab70af 183);
This page took 0.271486 seconds and 4 git commands to generate.