Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 - 2009 |
| 3 | * Windriver, <www.windriver.com> |
| 4 | * Tom Rix <Tom.Rix@windriver.com> |
| 5 | * |
| 6 | * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 7 | * |
| 8 | * Copyright 2014 Linaro, Ltd. |
| 9 | * Rob Herring <robh@kernel.org> |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0+ |
| 12 | */ |
Steve Rae | 593cbd9 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 13 | #include <config.h> |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 14 | #include <common.h> |
| 15 | #include <errno.h> |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 16 | #include <fastboot.h> |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 17 | #include <malloc.h> |
| 18 | #include <linux/usb/ch9.h> |
| 19 | #include <linux/usb/gadget.h> |
| 20 | #include <linux/usb/composite.h> |
| 21 | #include <linux/compiler.h> |
| 22 | #include <version.h> |
| 23 | #include <g_dnl.h> |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 24 | #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV |
| 25 | #include <fb_mmc.h> |
| 26 | #endif |
Maxime Ripard | bf8940d | 2015-10-15 14:34:17 +0200 | [diff] [blame] | 27 | #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV |
| 28 | #include <fb_nand.h> |
| 29 | #endif |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 30 | |
| 31 | #define FASTBOOT_VERSION "0.4" |
| 32 | |
| 33 | #define FASTBOOT_INTERFACE_CLASS 0xff |
| 34 | #define FASTBOOT_INTERFACE_SUB_CLASS 0x42 |
| 35 | #define FASTBOOT_INTERFACE_PROTOCOL 0x03 |
| 36 | |
| 37 | #define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_2_0 (0x0200) |
| 38 | #define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1 (0x0040) |
| 39 | #define TX_ENDPOINT_MAXIMUM_PACKET_SIZE (0x0040) |
| 40 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 41 | #define EP_BUFFER_SIZE 4096 |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 42 | /* |
| 43 | * EP_BUFFER_SIZE must always be an integral multiple of maxpacket size |
| 44 | * (64 or 512 or 1024), else we break on certain controllers like DWC3 |
| 45 | * that expect bulk OUT requests to be divisible by maxpacket size. |
| 46 | */ |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 47 | |
| 48 | struct f_fastboot { |
| 49 | struct usb_function usb_function; |
| 50 | |
Steve Rae | 593cbd9 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 51 | /* IN/OUT EP's and corresponding requests */ |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 52 | struct usb_ep *in_ep, *out_ep; |
| 53 | struct usb_request *in_req, *out_req; |
| 54 | }; |
| 55 | |
| 56 | static inline struct f_fastboot *func_to_fastboot(struct usb_function *f) |
| 57 | { |
| 58 | return container_of(f, struct f_fastboot, usb_function); |
| 59 | } |
| 60 | |
| 61 | static struct f_fastboot *fastboot_func; |
| 62 | static unsigned int download_size; |
| 63 | static unsigned int download_bytes; |
| 64 | |
| 65 | static struct usb_endpoint_descriptor fs_ep_in = { |
| 66 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 67 | .bDescriptorType = USB_DT_ENDPOINT, |
| 68 | .bEndpointAddress = USB_DIR_IN, |
| 69 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
Roger Quadros | 718156a | 2016-04-12 15:51:48 +0300 | [diff] [blame] | 70 | .wMaxPacketSize = cpu_to_le16(64), |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static struct usb_endpoint_descriptor fs_ep_out = { |
| 74 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 75 | .bDescriptorType = USB_DT_ENDPOINT, |
| 76 | .bEndpointAddress = USB_DIR_OUT, |
| 77 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
Roger Quadros | 718156a | 2016-04-12 15:51:48 +0300 | [diff] [blame] | 78 | .wMaxPacketSize = cpu_to_le16(64), |
| 79 | }; |
| 80 | |
| 81 | static struct usb_endpoint_descriptor hs_ep_in = { |
| 82 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 83 | .bDescriptorType = USB_DT_ENDPOINT, |
| 84 | .bEndpointAddress = USB_DIR_IN, |
| 85 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 86 | .wMaxPacketSize = cpu_to_le16(512), |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static struct usb_endpoint_descriptor hs_ep_out = { |
| 90 | .bLength = USB_DT_ENDPOINT_SIZE, |
| 91 | .bDescriptorType = USB_DT_ENDPOINT, |
| 92 | .bEndpointAddress = USB_DIR_OUT, |
| 93 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
Roger Quadros | 718156a | 2016-04-12 15:51:48 +0300 | [diff] [blame] | 94 | .wMaxPacketSize = cpu_to_le16(512), |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | static struct usb_interface_descriptor interface_desc = { |
| 98 | .bLength = USB_DT_INTERFACE_SIZE, |
| 99 | .bDescriptorType = USB_DT_INTERFACE, |
| 100 | .bInterfaceNumber = 0x00, |
| 101 | .bAlternateSetting = 0x00, |
| 102 | .bNumEndpoints = 0x02, |
| 103 | .bInterfaceClass = FASTBOOT_INTERFACE_CLASS, |
| 104 | .bInterfaceSubClass = FASTBOOT_INTERFACE_SUB_CLASS, |
| 105 | .bInterfaceProtocol = FASTBOOT_INTERFACE_PROTOCOL, |
| 106 | }; |
| 107 | |
Roger Quadros | 718156a | 2016-04-12 15:51:48 +0300 | [diff] [blame] | 108 | static struct usb_descriptor_header *fb_fs_function[] = { |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 109 | (struct usb_descriptor_header *)&interface_desc, |
| 110 | (struct usb_descriptor_header *)&fs_ep_in, |
Roger Quadros | 718156a | 2016-04-12 15:51:48 +0300 | [diff] [blame] | 111 | (struct usb_descriptor_header *)&fs_ep_out, |
| 112 | }; |
| 113 | |
| 114 | static struct usb_descriptor_header *fb_hs_function[] = { |
| 115 | (struct usb_descriptor_header *)&interface_desc, |
| 116 | (struct usb_descriptor_header *)&hs_ep_in, |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 117 | (struct usb_descriptor_header *)&hs_ep_out, |
| 118 | NULL, |
| 119 | }; |
| 120 | |
Roger Quadros | 8b704a0 | 2016-04-13 11:30:00 +0300 | [diff] [blame] | 121 | static struct usb_endpoint_descriptor * |
| 122 | fb_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, |
| 123 | struct usb_endpoint_descriptor *hs) |
| 124 | { |
| 125 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) |
| 126 | return hs; |
| 127 | return fs; |
| 128 | } |
| 129 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 130 | /* |
| 131 | * static strings, in UTF-8 |
| 132 | */ |
| 133 | static const char fastboot_name[] = "Android Fastboot"; |
| 134 | |
| 135 | static struct usb_string fastboot_string_defs[] = { |
| 136 | [0].s = fastboot_name, |
| 137 | { } /* end of list */ |
| 138 | }; |
| 139 | |
| 140 | static struct usb_gadget_strings stringtab_fastboot = { |
| 141 | .language = 0x0409, /* en-us */ |
| 142 | .strings = fastboot_string_defs, |
| 143 | }; |
| 144 | |
| 145 | static struct usb_gadget_strings *fastboot_strings[] = { |
| 146 | &stringtab_fastboot, |
| 147 | NULL, |
| 148 | }; |
| 149 | |
| 150 | static void rx_handler_command(struct usb_ep *ep, struct usb_request *req); |
Alexey Firago | e2ec3e4 | 2015-02-25 17:10:47 +0300 | [diff] [blame] | 151 | static int strcmp_l1(const char *s1, const char *s2); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 152 | |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 153 | |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 154 | static char *fb_response_str; |
| 155 | |
| 156 | void fastboot_fail(const char *reason) |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 157 | { |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 158 | strncpy(fb_response_str, "FAIL\0", 5); |
| 159 | strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1); |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 162 | void fastboot_okay(const char *reason) |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 163 | { |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 164 | strncpy(fb_response_str, "OKAY\0", 5); |
| 165 | strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1); |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 168 | static void fastboot_complete(struct usb_ep *ep, struct usb_request *req) |
| 169 | { |
| 170 | int status = req->status; |
| 171 | if (!status) |
| 172 | return; |
| 173 | printf("status: %d ep '%s' trans: %d\n", status, ep->name, req->actual); |
| 174 | } |
| 175 | |
| 176 | static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) |
| 177 | { |
| 178 | int id; |
| 179 | struct usb_gadget *gadget = c->cdev->gadget; |
| 180 | struct f_fastboot *f_fb = func_to_fastboot(f); |
Dileep Katta | 537cd07 | 2015-02-13 14:33:43 +0800 | [diff] [blame] | 181 | const char *s; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 182 | |
| 183 | /* DYNAMIC interface numbers assignments */ |
| 184 | id = usb_interface_id(c, f); |
| 185 | if (id < 0) |
| 186 | return id; |
| 187 | interface_desc.bInterfaceNumber = id; |
| 188 | |
| 189 | id = usb_string_id(c->cdev); |
| 190 | if (id < 0) |
| 191 | return id; |
| 192 | fastboot_string_defs[0].id = id; |
| 193 | interface_desc.iInterface = id; |
| 194 | |
| 195 | f_fb->in_ep = usb_ep_autoconfig(gadget, &fs_ep_in); |
| 196 | if (!f_fb->in_ep) |
| 197 | return -ENODEV; |
| 198 | f_fb->in_ep->driver_data = c->cdev; |
| 199 | |
| 200 | f_fb->out_ep = usb_ep_autoconfig(gadget, &fs_ep_out); |
| 201 | if (!f_fb->out_ep) |
| 202 | return -ENODEV; |
| 203 | f_fb->out_ep->driver_data = c->cdev; |
| 204 | |
Roger Quadros | 718156a | 2016-04-12 15:51:48 +0300 | [diff] [blame] | 205 | f->descriptors = fb_fs_function; |
| 206 | |
| 207 | if (gadget_is_dualspeed(gadget)) { |
| 208 | /* Assume endpoint addresses are the same for both speeds */ |
| 209 | hs_ep_in.bEndpointAddress = fs_ep_in.bEndpointAddress; |
| 210 | hs_ep_out.bEndpointAddress = fs_ep_out.bEndpointAddress; |
| 211 | /* copy HS descriptors */ |
| 212 | f->hs_descriptors = fb_hs_function; |
| 213 | } |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 214 | |
Dileep Katta | 537cd07 | 2015-02-13 14:33:43 +0800 | [diff] [blame] | 215 | s = getenv("serial#"); |
| 216 | if (s) |
| 217 | g_dnl_set_serialnumber((char *)s); |
| 218 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static void fastboot_unbind(struct usb_configuration *c, struct usb_function *f) |
| 223 | { |
| 224 | memset(fastboot_func, 0, sizeof(*fastboot_func)); |
| 225 | } |
| 226 | |
| 227 | static void fastboot_disable(struct usb_function *f) |
| 228 | { |
| 229 | struct f_fastboot *f_fb = func_to_fastboot(f); |
| 230 | |
| 231 | usb_ep_disable(f_fb->out_ep); |
| 232 | usb_ep_disable(f_fb->in_ep); |
| 233 | |
| 234 | if (f_fb->out_req) { |
| 235 | free(f_fb->out_req->buf); |
| 236 | usb_ep_free_request(f_fb->out_ep, f_fb->out_req); |
| 237 | f_fb->out_req = NULL; |
| 238 | } |
| 239 | if (f_fb->in_req) { |
| 240 | free(f_fb->in_req->buf); |
| 241 | usb_ep_free_request(f_fb->in_ep, f_fb->in_req); |
| 242 | f_fb->in_req = NULL; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | static struct usb_request *fastboot_start_ep(struct usb_ep *ep) |
| 247 | { |
| 248 | struct usb_request *req; |
| 249 | |
| 250 | req = usb_ep_alloc_request(ep, 0); |
| 251 | if (!req) |
| 252 | return NULL; |
| 253 | |
| 254 | req->length = EP_BUFFER_SIZE; |
| 255 | req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, EP_BUFFER_SIZE); |
| 256 | if (!req->buf) { |
| 257 | usb_ep_free_request(ep, req); |
| 258 | return NULL; |
| 259 | } |
| 260 | |
| 261 | memset(req->buf, 0, req->length); |
| 262 | return req; |
| 263 | } |
| 264 | |
| 265 | static int fastboot_set_alt(struct usb_function *f, |
| 266 | unsigned interface, unsigned alt) |
| 267 | { |
| 268 | int ret; |
| 269 | struct usb_composite_dev *cdev = f->config->cdev; |
| 270 | struct usb_gadget *gadget = cdev->gadget; |
| 271 | struct f_fastboot *f_fb = func_to_fastboot(f); |
Roger Quadros | 8b704a0 | 2016-04-13 11:30:00 +0300 | [diff] [blame] | 272 | const struct usb_endpoint_descriptor *d; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 273 | |
| 274 | debug("%s: func: %s intf: %d alt: %d\n", |
| 275 | __func__, f->name, interface, alt); |
| 276 | |
Roger Quadros | 8b704a0 | 2016-04-13 11:30:00 +0300 | [diff] [blame] | 277 | d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out); |
| 278 | ret = usb_ep_enable(f_fb->out_ep, d); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 279 | if (ret) { |
| 280 | puts("failed to enable out ep\n"); |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | f_fb->out_req = fastboot_start_ep(f_fb->out_ep); |
| 285 | if (!f_fb->out_req) { |
| 286 | puts("failed to alloc out req\n"); |
| 287 | ret = -EINVAL; |
| 288 | goto err; |
| 289 | } |
| 290 | f_fb->out_req->complete = rx_handler_command; |
| 291 | |
Roger Quadros | 8b704a0 | 2016-04-13 11:30:00 +0300 | [diff] [blame] | 292 | d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in); |
| 293 | ret = usb_ep_enable(f_fb->in_ep, d); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 294 | if (ret) { |
| 295 | puts("failed to enable in ep\n"); |
| 296 | goto err; |
| 297 | } |
| 298 | |
| 299 | f_fb->in_req = fastboot_start_ep(f_fb->in_ep); |
| 300 | if (!f_fb->in_req) { |
| 301 | puts("failed alloc req in\n"); |
| 302 | ret = -EINVAL; |
| 303 | goto err; |
| 304 | } |
| 305 | f_fb->in_req->complete = fastboot_complete; |
| 306 | |
| 307 | ret = usb_ep_queue(f_fb->out_ep, f_fb->out_req, 0); |
| 308 | if (ret) |
| 309 | goto err; |
| 310 | |
| 311 | return 0; |
| 312 | err: |
| 313 | fastboot_disable(f); |
| 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | static int fastboot_add(struct usb_configuration *c) |
| 318 | { |
| 319 | struct f_fastboot *f_fb = fastboot_func; |
| 320 | int status; |
| 321 | |
| 322 | debug("%s: cdev: 0x%p\n", __func__, c->cdev); |
| 323 | |
| 324 | if (!f_fb) { |
| 325 | f_fb = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*f_fb)); |
| 326 | if (!f_fb) |
| 327 | return -ENOMEM; |
| 328 | |
| 329 | fastboot_func = f_fb; |
| 330 | memset(f_fb, 0, sizeof(*f_fb)); |
| 331 | } |
| 332 | |
| 333 | f_fb->usb_function.name = "f_fastboot"; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 334 | f_fb->usb_function.bind = fastboot_bind; |
| 335 | f_fb->usb_function.unbind = fastboot_unbind; |
| 336 | f_fb->usb_function.set_alt = fastboot_set_alt; |
| 337 | f_fb->usb_function.disable = fastboot_disable; |
| 338 | f_fb->usb_function.strings = fastboot_strings; |
| 339 | |
| 340 | status = usb_add_function(c, &f_fb->usb_function); |
| 341 | if (status) { |
| 342 | free(f_fb); |
| 343 | fastboot_func = f_fb; |
| 344 | } |
| 345 | |
| 346 | return status; |
| 347 | } |
| 348 | DECLARE_GADGET_BIND_CALLBACK(usb_dnl_fastboot, fastboot_add); |
| 349 | |
Steve Rae | 593cbd9 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 350 | static int fastboot_tx_write(const char *buffer, unsigned int buffer_size) |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 351 | { |
| 352 | struct usb_request *in_req = fastboot_func->in_req; |
| 353 | int ret; |
| 354 | |
| 355 | memcpy(in_req->buf, buffer, buffer_size); |
| 356 | in_req->length = buffer_size; |
Paul Kocialkowski | bc9071c | 2015-07-04 16:46:16 +0200 | [diff] [blame] | 357 | |
| 358 | usb_ep_dequeue(fastboot_func->in_ep, in_req); |
| 359 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 360 | ret = usb_ep_queue(fastboot_func->in_ep, in_req, 0); |
| 361 | if (ret) |
| 362 | printf("Error %d on queue\n", ret); |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int fastboot_tx_write_str(const char *buffer) |
| 367 | { |
| 368 | return fastboot_tx_write(buffer, strlen(buffer)); |
| 369 | } |
| 370 | |
| 371 | static void compl_do_reset(struct usb_ep *ep, struct usb_request *req) |
| 372 | { |
| 373 | do_reset(NULL, 0, 0, NULL); |
| 374 | } |
| 375 | |
Alexey Firago | e2ec3e4 | 2015-02-25 17:10:47 +0300 | [diff] [blame] | 376 | int __weak fb_set_reboot_flag(void) |
| 377 | { |
| 378 | return -ENOSYS; |
| 379 | } |
| 380 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 381 | static void cb_reboot(struct usb_ep *ep, struct usb_request *req) |
| 382 | { |
Alexey Firago | e2ec3e4 | 2015-02-25 17:10:47 +0300 | [diff] [blame] | 383 | char *cmd = req->buf; |
| 384 | if (!strcmp_l1("reboot-bootloader", cmd)) { |
| 385 | if (fb_set_reboot_flag()) { |
| 386 | fastboot_tx_write_str("FAILCannot set reboot flag"); |
| 387 | return; |
| 388 | } |
| 389 | } |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 390 | fastboot_func->in_req->complete = compl_do_reset; |
| 391 | fastboot_tx_write_str("OKAY"); |
| 392 | } |
| 393 | |
| 394 | static int strcmp_l1(const char *s1, const char *s2) |
| 395 | { |
| 396 | if (!s1 || !s2) |
| 397 | return -1; |
| 398 | return strncmp(s1, s2, strlen(s1)); |
| 399 | } |
| 400 | |
| 401 | static void cb_getvar(struct usb_ep *ep, struct usb_request *req) |
| 402 | { |
| 403 | char *cmd = req->buf; |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 404 | char response[FASTBOOT_RESPONSE_LEN]; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 405 | const char *s; |
Jeroen Hofstee | 29425be | 2014-06-14 00:57:14 +0200 | [diff] [blame] | 406 | size_t chars_left; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 407 | |
| 408 | strcpy(response, "OKAY"); |
Jeroen Hofstee | 29425be | 2014-06-14 00:57:14 +0200 | [diff] [blame] | 409 | chars_left = sizeof(response) - strlen(response) - 1; |
| 410 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 411 | strsep(&cmd, ":"); |
| 412 | if (!cmd) { |
Steve Rae | a18c270 | 2016-01-27 15:02:41 -0800 | [diff] [blame] | 413 | error("missing variable"); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 414 | fastboot_tx_write_str("FAILmissing var"); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | if (!strcmp_l1("version", cmd)) { |
Jeroen Hofstee | 29425be | 2014-06-14 00:57:14 +0200 | [diff] [blame] | 419 | strncat(response, FASTBOOT_VERSION, chars_left); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 420 | } else if (!strcmp_l1("bootloader-version", cmd)) { |
Jeroen Hofstee | 29425be | 2014-06-14 00:57:14 +0200 | [diff] [blame] | 421 | strncat(response, U_BOOT_VERSION, chars_left); |
Eric Nelson | c674a66 | 2014-09-30 12:05:40 -0700 | [diff] [blame] | 422 | } else if (!strcmp_l1("downloadsize", cmd) || |
| 423 | !strcmp_l1("max-download-size", cmd)) { |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 424 | char str_num[12]; |
| 425 | |
Paul Kocialkowski | a588d99 | 2015-07-20 12:38:22 +0200 | [diff] [blame] | 426 | sprintf(str_num, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE); |
Jeroen Hofstee | 29425be | 2014-06-14 00:57:14 +0200 | [diff] [blame] | 427 | strncat(response, str_num, chars_left); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 428 | } else if (!strcmp_l1("serialno", cmd)) { |
| 429 | s = getenv("serial#"); |
| 430 | if (s) |
Jeroen Hofstee | 29425be | 2014-06-14 00:57:14 +0200 | [diff] [blame] | 431 | strncat(response, s, chars_left); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 432 | else |
| 433 | strcpy(response, "FAILValue not set"); |
| 434 | } else { |
Rob Herring | 7432220 | 2016-03-17 17:21:23 +0100 | [diff] [blame] | 435 | char envstr[32]; |
| 436 | |
| 437 | snprintf(envstr, sizeof(envstr) - 1, "fastboot.%s", cmd); |
| 438 | s = getenv(envstr); |
| 439 | if (s) { |
| 440 | strncat(response, s, chars_left); |
| 441 | } else { |
| 442 | printf("WARNING: unknown variable: %s\n", cmd); |
| 443 | strcpy(response, "FAILVariable not implemented"); |
| 444 | } |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 445 | } |
| 446 | fastboot_tx_write_str(response); |
| 447 | } |
| 448 | |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 449 | static unsigned int rx_bytes_expected(struct usb_ep *ep) |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 450 | { |
| 451 | int rx_remain = download_size - download_bytes; |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 452 | unsigned int rem; |
| 453 | unsigned int maxpacket = ep->maxpacket; |
| 454 | |
| 455 | if (rx_remain <= 0) |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 456 | return 0; |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 457 | else if (rx_remain > EP_BUFFER_SIZE) |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 458 | return EP_BUFFER_SIZE; |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 459 | |
| 460 | /* |
| 461 | * Some controllers e.g. DWC3 don't like OUT transfers to be |
| 462 | * not ending in maxpacket boundary. So just make them happy by |
| 463 | * always requesting for integral multiple of maxpackets. |
| 464 | * This shouldn't bother controllers that don't care about it. |
| 465 | */ |
| 466 | rem = rx_remain % maxpacket; |
| 467 | if (rem > 0) |
Dileep Katta | 9e4b510 | 2015-02-17 02:02:36 +0530 | [diff] [blame] | 468 | rx_remain = rx_remain + (maxpacket - rem); |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 469 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 470 | return rx_remain; |
| 471 | } |
| 472 | |
| 473 | #define BYTES_PER_DOT 0x20000 |
| 474 | static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) |
| 475 | { |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 476 | char response[FASTBOOT_RESPONSE_LEN]; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 477 | unsigned int transfer_size = download_size - download_bytes; |
| 478 | const unsigned char *buffer = req->buf; |
| 479 | unsigned int buffer_size = req->actual; |
Bo Shen | 23d1d10 | 2014-09-19 14:15:12 +0800 | [diff] [blame] | 480 | unsigned int pre_dot_num, now_dot_num; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 481 | |
| 482 | if (req->status != 0) { |
| 483 | printf("Bad status: %d\n", req->status); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | if (buffer_size < transfer_size) |
| 488 | transfer_size = buffer_size; |
| 489 | |
Paul Kocialkowski | a588d99 | 2015-07-20 12:38:22 +0200 | [diff] [blame] | 490 | memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + download_bytes, |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 491 | buffer, transfer_size); |
| 492 | |
Bo Shen | 23d1d10 | 2014-09-19 14:15:12 +0800 | [diff] [blame] | 493 | pre_dot_num = download_bytes / BYTES_PER_DOT; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 494 | download_bytes += transfer_size; |
Bo Shen | 23d1d10 | 2014-09-19 14:15:12 +0800 | [diff] [blame] | 495 | now_dot_num = download_bytes / BYTES_PER_DOT; |
| 496 | |
| 497 | if (pre_dot_num != now_dot_num) { |
| 498 | putc('.'); |
| 499 | if (!(now_dot_num % 74)) |
| 500 | putc('\n'); |
| 501 | } |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 502 | |
| 503 | /* Check if transfer is done */ |
| 504 | if (download_bytes >= download_size) { |
| 505 | /* |
| 506 | * Reset global transfer variable, keep download_bytes because |
| 507 | * it will be used in the next possible flashing command |
| 508 | */ |
| 509 | download_size = 0; |
| 510 | req->complete = rx_handler_command; |
| 511 | req->length = EP_BUFFER_SIZE; |
| 512 | |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 513 | strcpy(response, "OKAY"); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 514 | fastboot_tx_write_str(response); |
| 515 | |
| 516 | printf("\ndownloading of %d bytes finished\n", download_bytes); |
| 517 | } else { |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 518 | req->length = rx_bytes_expected(ep); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 519 | } |
| 520 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 521 | req->actual = 0; |
| 522 | usb_ep_queue(ep, req, 0); |
| 523 | } |
| 524 | |
| 525 | static void cb_download(struct usb_ep *ep, struct usb_request *req) |
| 526 | { |
| 527 | char *cmd = req->buf; |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 528 | char response[FASTBOOT_RESPONSE_LEN]; |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 529 | |
| 530 | strsep(&cmd, ":"); |
| 531 | download_size = simple_strtoul(cmd, NULL, 16); |
| 532 | download_bytes = 0; |
| 533 | |
| 534 | printf("Starting download of %d bytes\n", download_size); |
| 535 | |
| 536 | if (0 == download_size) { |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 537 | strcpy(response, "FAILdata invalid size"); |
Paul Kocialkowski | a588d99 | 2015-07-20 12:38:22 +0200 | [diff] [blame] | 538 | } else if (download_size > CONFIG_FASTBOOT_BUF_SIZE) { |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 539 | download_size = 0; |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 540 | strcpy(response, "FAILdata too large"); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 541 | } else { |
| 542 | sprintf(response, "DATA%08x", download_size); |
| 543 | req->complete = rx_handler_dl_image; |
Roger Quadros | ac484c5 | 2016-04-19 10:16:59 +0300 | [diff] [blame] | 544 | req->length = rx_bytes_expected(ep); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 545 | } |
| 546 | fastboot_tx_write_str(response); |
| 547 | } |
| 548 | |
| 549 | static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req) |
| 550 | { |
| 551 | char boot_addr_start[12]; |
| 552 | char *bootm_args[] = { "bootm", boot_addr_start, NULL }; |
| 553 | |
| 554 | puts("Booting kernel..\n"); |
| 555 | |
| 556 | sprintf(boot_addr_start, "0x%lx", load_addr); |
| 557 | do_bootm(NULL, 0, 2, bootm_args); |
| 558 | |
| 559 | /* This only happens if image is somehow faulty so we start over */ |
| 560 | do_reset(NULL, 0, 0, NULL); |
| 561 | } |
| 562 | |
| 563 | static void cb_boot(struct usb_ep *ep, struct usb_request *req) |
| 564 | { |
| 565 | fastboot_func->in_req->complete = do_bootm_on_complete; |
| 566 | fastboot_tx_write_str("OKAY"); |
| 567 | } |
| 568 | |
Rob Herring | 267abc6 | 2014-12-10 14:43:04 -0600 | [diff] [blame] | 569 | static void do_exit_on_complete(struct usb_ep *ep, struct usb_request *req) |
| 570 | { |
| 571 | g_dnl_trigger_detach(); |
| 572 | } |
| 573 | |
| 574 | static void cb_continue(struct usb_ep *ep, struct usb_request *req) |
| 575 | { |
| 576 | fastboot_func->in_req->complete = do_exit_on_complete; |
| 577 | fastboot_tx_write_str("OKAY"); |
| 578 | } |
| 579 | |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 580 | #ifdef CONFIG_FASTBOOT_FLASH |
| 581 | static void cb_flash(struct usb_ep *ep, struct usb_request *req) |
| 582 | { |
| 583 | char *cmd = req->buf; |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 584 | char response[FASTBOOT_RESPONSE_LEN]; |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 585 | |
| 586 | strsep(&cmd, ":"); |
| 587 | if (!cmd) { |
Steve Rae | a18c270 | 2016-01-27 15:02:41 -0800 | [diff] [blame] | 588 | error("missing partition name"); |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 589 | fastboot_tx_write_str("FAILmissing partition name"); |
| 590 | return; |
| 591 | } |
| 592 | |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 593 | /* initialize the response buffer */ |
| 594 | fb_response_str = response; |
| 595 | |
| 596 | fastboot_fail("no flash device defined"); |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 597 | #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV |
Steve Rae | 64ece84 | 2016-06-07 11:19:35 -0700 | [diff] [blame] | 598 | fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR, |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 599 | download_bytes); |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 600 | #endif |
Maxime Ripard | bf8940d | 2015-10-15 14:34:17 +0200 | [diff] [blame] | 601 | #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV |
Steve Rae | 64ece84 | 2016-06-07 11:19:35 -0700 | [diff] [blame] | 602 | fb_nand_flash_write(cmd, |
Maxime Ripard | bf8940d | 2015-10-15 14:34:17 +0200 | [diff] [blame] | 603 | (void *)CONFIG_FASTBOOT_BUF_ADDR, |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 604 | download_bytes); |
Maxime Ripard | bf8940d | 2015-10-15 14:34:17 +0200 | [diff] [blame] | 605 | #endif |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 606 | fastboot_tx_write_str(response); |
| 607 | } |
| 608 | #endif |
| 609 | |
Michael Scott | de19562 | 2015-01-26 15:49:00 -0600 | [diff] [blame] | 610 | static void cb_oem(struct usb_ep *ep, struct usb_request *req) |
| 611 | { |
| 612 | char *cmd = req->buf; |
Maxime Ripard | 4adef27 | 2015-10-15 22:04:04 +0200 | [diff] [blame] | 613 | #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV |
Rob Herring | 372d7de | 2015-01-26 15:49:01 -0600 | [diff] [blame] | 614 | if (strncmp("format", cmd + 4, 6) == 0) { |
| 615 | char cmdbuf[32]; |
| 616 | sprintf(cmdbuf, "gpt write mmc %x $partitions", |
| 617 | CONFIG_FASTBOOT_FLASH_MMC_DEV); |
| 618 | if (run_command(cmdbuf, 0)) |
| 619 | fastboot_tx_write_str("FAIL"); |
| 620 | else |
| 621 | fastboot_tx_write_str("OKAY"); |
| 622 | } else |
| 623 | #endif |
Michael Scott | de19562 | 2015-01-26 15:49:00 -0600 | [diff] [blame] | 624 | if (strncmp("unlock", cmd + 4, 8) == 0) { |
| 625 | fastboot_tx_write_str("FAILnot implemented"); |
| 626 | } |
| 627 | else { |
| 628 | fastboot_tx_write_str("FAILunknown oem command"); |
| 629 | } |
| 630 | } |
| 631 | |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 632 | #ifdef CONFIG_FASTBOOT_FLASH |
| 633 | static void cb_erase(struct usb_ep *ep, struct usb_request *req) |
| 634 | { |
| 635 | char *cmd = req->buf; |
Maxime Ripard | 3c8f98f | 2015-10-15 14:34:13 +0200 | [diff] [blame] | 636 | char response[FASTBOOT_RESPONSE_LEN]; |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 637 | |
| 638 | strsep(&cmd, ":"); |
| 639 | if (!cmd) { |
| 640 | error("missing partition name"); |
| 641 | fastboot_tx_write_str("FAILmissing partition name"); |
| 642 | return; |
| 643 | } |
| 644 | |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 645 | /* initialize the response buffer */ |
| 646 | fb_response_str = response; |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 647 | |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 648 | fastboot_fail("no flash device defined"); |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 649 | #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 650 | fb_mmc_erase(cmd); |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 651 | #endif |
Maxime Ripard | bf8940d | 2015-10-15 14:34:17 +0200 | [diff] [blame] | 652 | #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame] | 653 | fb_nand_erase(cmd); |
Maxime Ripard | bf8940d | 2015-10-15 14:34:17 +0200 | [diff] [blame] | 654 | #endif |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 655 | fastboot_tx_write_str(response); |
| 656 | } |
| 657 | #endif |
| 658 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 659 | struct cmd_dispatch_info { |
| 660 | char *cmd; |
| 661 | void (*cb)(struct usb_ep *ep, struct usb_request *req); |
| 662 | }; |
| 663 | |
| 664 | static const struct cmd_dispatch_info cmd_dispatch_info[] = { |
| 665 | { |
| 666 | .cmd = "reboot", |
| 667 | .cb = cb_reboot, |
| 668 | }, { |
| 669 | .cmd = "getvar:", |
| 670 | .cb = cb_getvar, |
| 671 | }, { |
| 672 | .cmd = "download:", |
| 673 | .cb = cb_download, |
| 674 | }, { |
| 675 | .cmd = "boot", |
| 676 | .cb = cb_boot, |
Rob Herring | 267abc6 | 2014-12-10 14:43:04 -0600 | [diff] [blame] | 677 | }, { |
| 678 | .cmd = "continue", |
| 679 | .cb = cb_continue, |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 680 | }, |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 681 | #ifdef CONFIG_FASTBOOT_FLASH |
| 682 | { |
| 683 | .cmd = "flash", |
| 684 | .cb = cb_flash, |
Dileep Katta | 8979238 | 2015-02-17 18:48:23 +0530 | [diff] [blame] | 685 | }, { |
| 686 | .cmd = "erase", |
| 687 | .cb = cb_erase, |
Steve Rae | d1b5ed0 | 2014-08-26 11:47:28 -0700 | [diff] [blame] | 688 | }, |
| 689 | #endif |
Michael Scott | de19562 | 2015-01-26 15:49:00 -0600 | [diff] [blame] | 690 | { |
| 691 | .cmd = "oem", |
| 692 | .cb = cb_oem, |
| 693 | }, |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 694 | }; |
| 695 | |
| 696 | static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) |
| 697 | { |
| 698 | char *cmdbuf = req->buf; |
| 699 | void (*func_cb)(struct usb_ep *ep, struct usb_request *req) = NULL; |
| 700 | int i; |
| 701 | |
Paul Kocialkowski | 94b385f | 2015-07-04 16:46:15 +0200 | [diff] [blame] | 702 | if (req->status != 0 || req->length == 0) |
| 703 | return; |
| 704 | |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 705 | for (i = 0; i < ARRAY_SIZE(cmd_dispatch_info); i++) { |
| 706 | if (!strcmp_l1(cmd_dispatch_info[i].cmd, cmdbuf)) { |
| 707 | func_cb = cmd_dispatch_info[i].cb; |
| 708 | break; |
| 709 | } |
| 710 | } |
| 711 | |
Steve Rae | 593cbd9 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 712 | if (!func_cb) { |
Steve Rae | a18c270 | 2016-01-27 15:02:41 -0800 | [diff] [blame] | 713 | error("unknown command: %s", cmdbuf); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 714 | fastboot_tx_write_str("FAILunknown command"); |
Steve Rae | 593cbd9 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 715 | } else { |
Eric Nelson | e214058 | 2014-10-01 14:30:56 -0700 | [diff] [blame] | 716 | if (req->actual < req->length) { |
| 717 | u8 *buf = (u8 *)req->buf; |
| 718 | buf[req->actual] = 0; |
| 719 | func_cb(ep, req); |
| 720 | } else { |
Steve Rae | a18c270 | 2016-01-27 15:02:41 -0800 | [diff] [blame] | 721 | error("buffer overflow"); |
Eric Nelson | e214058 | 2014-10-01 14:30:56 -0700 | [diff] [blame] | 722 | fastboot_tx_write_str("FAILbuffer overflow"); |
| 723 | } |
Steve Rae | 593cbd9 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 724 | } |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 725 | |
Paul Kocialkowski | 94b385f | 2015-07-04 16:46:15 +0200 | [diff] [blame] | 726 | *cmdbuf = '\0'; |
| 727 | req->actual = 0; |
| 728 | usb_ep_queue(ep, req, 0); |
Sebastian Siewior | 3aab70a | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 729 | } |