blob: 972c4ed0136c6aab451d708b3228f36b8d7255ce [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
Anatol Pomazau5ae3f932012-02-28 07:21:08 -080012 * the documentation and/or other materials provided with the
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080013 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
Anatol Pomazau5ae3f932012-02-28 07:21:08 -080022 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080029#include "fastboot.h"
30#include "make_ext4fs.h"
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080031
Colin Cross81c632e2013-01-23 19:13:43 -080032#include <errno.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080033#include <stdio.h>
34#include <stdlib.h>
35#include <stdarg.h>
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080036#include <stdbool.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080037#include <string.h>
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080038#include <sys/stat.h>
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080039#include <sys/types.h>
40#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080041
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080042#ifdef USE_MINGW
43#include <fcntl.h>
44#else
45#include <sys/mman.h>
46#endif
47
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080048#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080049
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080050#define OP_DOWNLOAD 1
51#define OP_COMMAND 2
52#define OP_QUERY 3
53#define OP_NOTICE 4
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080054#define OP_FORMAT 5
Colin Crossf8387882012-05-24 17:18:41 -070055#define OP_DOWNLOAD_SPARSE 6
Mark Wachsler157b0012013-10-02 09:35:38 -040056#define OP_WAIT_FOR_DISCONNECT 7
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080057
58typedef struct Action Action;
59
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080060#define CMD_SIZE 64
61
Anatol Pomazau5ae3f932012-02-28 07:21:08 -080062struct Action
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080063{
64 unsigned op;
65 Action *next;
66
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080067 char cmd[CMD_SIZE];
Wink Savilleb98762f2011-04-04 17:54:59 -070068 const char *prod;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080069 void *data;
70 unsigned size;
71
72 const char *msg;
73 int (*func)(Action *a, int status, char *resp);
Daniel Sandlercb6e22b2010-02-25 14:05:33 -050074
75 double start;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080076};
77
78static Action *action_list = 0;
79static Action *action_last = 0;
80
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080081
82struct image_data {
83 long long partition_size;
84 long long image_size; // real size of image file
85 void *buffer;
86};
87
88void generate_ext4_image(struct image_data *image);
89void cleanup_image(struct image_data *image);
90
Colin Cross80f2d032012-05-24 18:24:53 -070091int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...)
92{
93 char cmd[CMD_SIZE] = "getvar:";
94 int getvar_len = strlen(cmd);
95 va_list args;
96
97 response[FB_RESPONSE_SZ] = '\0';
98 va_start(args, fmt);
99 vsnprintf(cmd + getvar_len, sizeof(cmd) - getvar_len, fmt, args);
100 va_end(args);
101 cmd[CMD_SIZE - 1] = '\0';
102 return fb_command_response(usb, cmd, response);
103}
104
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800105struct generator {
106 char *fs_type;
107
108 /* generate image and return it as image->buffer.
109 * size of the buffer returned as image->image_size.
110 *
111 * image->partition_size specifies what is the size of the
112 * file partition we generate image for.
113 */
114 void (*generate)(struct image_data *image);
115
116 /* it cleans the buffer allocated during image creation.
117 * this function probably does free() or munmap().
118 */
119 void (*cleanup)(struct image_data *image);
120} generators[] = {
121 { "ext4", generate_ext4_image, cleanup_image }
122};
123
Ken Sumrall5ee5d382012-09-29 14:46:25 -0700124/* Return true if this partition is supported by the fastboot format command.
125 * It is also used to determine if we should first erase a partition before
126 * flashing it with an ext4 filesystem. See needs_erase()
127 *
128 * Not all devices report the filesystem type, so don't report any errors,
129 * just return false.
130 */
131int fb_format_supported(usb_handle *usb, const char *partition)
132{
133 char response[FB_RESPONSE_SZ+1];
134 struct generator *generator = NULL;
135 int status;
136 unsigned int i;
137
138 status = fb_getvar(usb, response, "partition-type:%s", partition);
139 if (status) {
140 return 0;
141 }
142
143 for (i = 0; i < ARRAY_SIZE(generators); i++) {
144 if (!strncmp(generators[i].fs_type, response, FB_RESPONSE_SZ)) {
145 generator = &generators[i];
146 break;
147 }
148 }
149
150 if (generator) {
151 return 1;
152 }
153
154 return 0;
155}
156
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800157static int cb_default(Action *a, int status, char *resp)
158{
159 if (status) {
160 fprintf(stderr,"FAILED (%s)\n", resp);
161 } else {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500162 double split = now();
163 fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start));
164 a->start = split;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800165 }
166 return status;
167}
168
169static Action *queue_action(unsigned op, const char *fmt, ...)
170{
171 Action *a;
172 va_list ap;
Bruce Beare50b39952010-07-15 08:52:01 -0700173 size_t cmdsize;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800174
175 a = calloc(1, sizeof(Action));
176 if (a == 0) die("out of memory");
177
178 va_start(ap, fmt);
Bruce Beare50b39952010-07-15 08:52:01 -0700179 cmdsize = vsnprintf(a->cmd, sizeof(a->cmd), fmt, ap);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800180 va_end(ap);
181
Bruce Beare50b39952010-07-15 08:52:01 -0700182 if (cmdsize >= sizeof(a->cmd)) {
183 free(a);
184 die("Command length (%d) exceeds maximum size (%d)", cmdsize, sizeof(a->cmd));
185 }
186
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800187 if (action_last) {
188 action_last->next = a;
189 } else {
190 action_list = a;
191 }
192 action_last = a;
193 a->op = op;
194 a->func = cb_default;
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500195
196 a->start = -1;
197
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800198 return a;
199}
200
201void fb_queue_erase(const char *ptn)
202{
203 Action *a;
204 a = queue_action(OP_COMMAND, "erase:%s", ptn);
205 a->msg = mkmsg("erasing '%s'", ptn);
206}
207
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800208/* Loads file content into buffer. Returns NULL on error. */
209static void *load_buffer(int fd, off_t size)
210{
211 void *buffer;
212
213#ifdef USE_MINGW
214 ssize_t count = 0;
215
216 // mmap is more efficient but mingw does not support it.
217 // In this case we read whole image into memory buffer.
218 buffer = malloc(size);
219 if (!buffer) {
220 perror("malloc");
221 return NULL;
222 }
223
224 lseek(fd, 0, SEEK_SET);
225 while(count < size) {
226 ssize_t actually_read = read(fd, (char*)buffer+count, size-count);
227
228 if (actually_read == 0) {
229 break;
230 }
231 if (actually_read < 0) {
232 if (errno == EINTR) {
233 continue;
234 }
235 perror("read");
236 free(buffer);
237 return NULL;
238 }
239
240 count += actually_read;
241 }
242#else
243 buffer = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
244 if (buffer == MAP_FAILED) {
245 perror("mmap");
246 return NULL;
247 }
248#endif
249
250 return buffer;
251}
252
253void cleanup_image(struct image_data *image)
254{
255#ifdef USE_MINGW
256 free(image->buffer);
257#else
258 munmap(image->buffer, image->image_size);
259#endif
260}
261
262void generate_ext4_image(struct image_data *image)
263{
264 int fd;
265 struct stat st;
266
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800267 fd = fileno(tmpfile());
Colin Cross2aaf5e82013-01-23 15:41:08 -0800268 make_ext4fs_sparse_fd(fd, image->partition_size, NULL, NULL);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800269
270 fstat(fd, &st);
271 image->image_size = st.st_size;
272 image->buffer = load_buffer(fd, st.st_size);
273
274 close(fd);
275}
276
JP Abgrall30ae5802012-05-07 20:25:24 -0700277int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported)
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800278{
279 const char *partition = a->cmd;
280 char response[FB_RESPONSE_SZ+1];
281 int status = 0;
282 struct image_data image;
283 struct generator *generator = NULL;
284 int fd;
285 unsigned i;
286 char cmd[CMD_SIZE];
287
Colin Cross80f2d032012-05-24 18:24:53 -0700288 status = fb_getvar(usb, response, "partition-type:%s", partition);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800289 if (status) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700290 if (skip_if_not_supported) {
291 fprintf(stderr,
292 "Erase successful, but not automatically formatting.\n");
293 fprintf(stderr,
294 "Can't determine partition type.\n");
295 return 0;
296 }
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800297 fprintf(stderr,"FAILED (%s)\n", fb_get_error());
298 return status;
299 }
300
301 for (i = 0; i < ARRAY_SIZE(generators); i++) {
302 if (!strncmp(generators[i].fs_type, response, FB_RESPONSE_SZ)) {
303 generator = &generators[i];
304 break;
305 }
306 }
307 if (!generator) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700308 if (skip_if_not_supported) {
309 fprintf(stderr,
310 "Erase successful, but not automatically formatting.\n");
311 fprintf(stderr,
312 "File system type %s not supported.\n", response);
313 return 0;
314 }
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800315 fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n",
316 response);
317 return -1;
318 }
319
Colin Cross80f2d032012-05-24 18:24:53 -0700320 status = fb_getvar(usb, response, "partition-size:%s", partition);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800321 if (status) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700322 if (skip_if_not_supported) {
323 fprintf(stderr,
324 "Erase successful, but not automatically formatting.\n");
325 fprintf(stderr, "Unable to get partition size\n.");
326 return 0;
327 }
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800328 fprintf(stderr,"FAILED (%s)\n", fb_get_error());
329 return status;
330 }
331 image.partition_size = strtoll(response, (char **)NULL, 16);
332
333 generator->generate(&image);
334 if (!image.buffer) {
335 fprintf(stderr,"Cannot generate image.\n");
336 return -1;
337 }
338
339 // Following piece of code is similar to fb_queue_flash() but executes
340 // actions directly without queuing
341 fprintf(stderr, "sending '%s' (%lli KB)...\n", partition, image.image_size/1024);
342 status = fb_download_data(usb, image.buffer, image.image_size);
343 if (status) goto cleanup;
344
345 fprintf(stderr, "writing '%s'...\n", partition);
346 snprintf(cmd, sizeof(cmd), "flash:%s", partition);
347 status = fb_command(usb, cmd);
348 if (status) goto cleanup;
349
350cleanup:
351 generator->cleanup(&image);
352
353 return status;
354}
355
JP Abgrall30ae5802012-05-07 20:25:24 -0700356void fb_queue_format(const char *partition, int skip_if_not_supported)
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800357{
358 Action *a;
359
360 a = queue_action(OP_FORMAT, partition);
JP Abgrall30ae5802012-05-07 20:25:24 -0700361 a->data = (void*)skip_if_not_supported;
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800362 a->msg = mkmsg("formatting '%s' partition", partition);
363}
364
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800365void fb_queue_flash(const char *ptn, void *data, unsigned sz)
366{
367 Action *a;
368
369 a = queue_action(OP_DOWNLOAD, "");
370 a->data = data;
371 a->size = sz;
372 a->msg = mkmsg("sending '%s' (%d KB)", ptn, sz / 1024);
373
374 a = queue_action(OP_COMMAND, "flash:%s", ptn);
375 a->msg = mkmsg("writing '%s'", ptn);
376}
377
Colin Crossf8387882012-05-24 17:18:41 -0700378void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz)
379{
380 Action *a;
381
382 a = queue_action(OP_DOWNLOAD_SPARSE, "");
383 a->data = s;
384 a->size = 0;
385 a->msg = mkmsg("sending sparse '%s' (%d KB)", ptn, sz / 1024);
386
387 a = queue_action(OP_COMMAND, "flash:%s", ptn);
388 a->msg = mkmsg("writing '%s'", ptn);
389}
390
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800391static int match(char *str, const char **value, unsigned count)
392{
393 const char *val;
394 unsigned n;
395 int len;
396
397 for (n = 0; n < count; n++) {
398 const char *val = value[n];
399 int len = strlen(val);
400 int match;
401
402 if ((len > 1) && (val[len-1] == '*')) {
403 len--;
404 match = !strncmp(val, str, len);
405 } else {
406 match = !strcmp(val, str);
407 }
408
409 if (match) return 1;
410 }
411
412 return 0;
413}
414
415
416
417static int cb_check(Action *a, int status, char *resp, int invert)
418{
419 const char **value = a->data;
420 unsigned count = a->size;
421 unsigned n;
422 int yes;
423
424 if (status) {
425 fprintf(stderr,"FAILED (%s)\n", resp);
426 return status;
427 }
428
Wink Savilleb98762f2011-04-04 17:54:59 -0700429 if (a->prod) {
430 if (strcmp(a->prod, cur_product) != 0) {
431 double split = now();
432 fprintf(stderr,"IGNORE, product is %s required only for %s [%7.3fs]\n",
433 cur_product, a->prod, (split - a->start));
434 a->start = split;
435 return 0;
436 }
437 }
438
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800439 yes = match(resp, value, count);
440 if (invert) yes = !yes;
441
442 if (yes) {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500443 double split = now();
444 fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start));
445 a->start = split;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800446 return 0;
447 }
448
449 fprintf(stderr,"FAILED\n\n");
450 fprintf(stderr,"Device %s is '%s'.\n", a->cmd + 7, resp);
451 fprintf(stderr,"Update %s '%s'",
452 invert ? "rejects" : "requires", value[0]);
453 for (n = 1; n < count; n++) {
454 fprintf(stderr," or '%s'", value[n]);
455 }
456 fprintf(stderr,".\n\n");
457 return -1;
458}
459
460static int cb_require(Action *a, int status, char *resp)
461{
462 return cb_check(a, status, resp, 0);
463}
464
465static int cb_reject(Action *a, int status, char *resp)
466{
467 return cb_check(a, status, resp, 1);
468}
469
Wink Savilleb98762f2011-04-04 17:54:59 -0700470void fb_queue_require(const char *prod, const char *var,
471 int invert, unsigned nvalues, const char **value)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800472{
473 Action *a;
474 a = queue_action(OP_QUERY, "getvar:%s", var);
Wink Savilleb98762f2011-04-04 17:54:59 -0700475 a->prod = prod;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800476 a->data = value;
477 a->size = nvalues;
478 a->msg = mkmsg("checking %s", var);
479 a->func = invert ? cb_reject : cb_require;
480 if (a->data == 0) die("out of memory");
481}
482
483static int cb_display(Action *a, int status, char *resp)
484{
485 if (status) {
486 fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp);
487 return status;
488 }
489 fprintf(stderr, "%s: %s\n", (char*) a->data, resp);
490 return 0;
491}
492
493void fb_queue_display(const char *var, const char *prettyname)
494{
495 Action *a;
496 a = queue_action(OP_QUERY, "getvar:%s", var);
497 a->data = strdup(prettyname);
498 if (a->data == 0) die("out of memory");
499 a->func = cb_display;
500}
501
Wink Savilleb98762f2011-04-04 17:54:59 -0700502static int cb_save(Action *a, int status, char *resp)
503{
504 if (status) {
505 fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp);
506 return status;
507 }
508 strncpy(a->data, resp, a->size);
509 return 0;
510}
511
512void fb_queue_query_save(const char *var, char *dest, unsigned dest_size)
513{
514 Action *a;
515 a = queue_action(OP_QUERY, "getvar:%s", var);
516 a->data = (void *)dest;
517 a->size = dest_size;
518 a->func = cb_save;
519}
520
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800521static int cb_do_nothing(Action *a, int status, char *resp)
522{
523 fprintf(stderr,"\n");
524 return 0;
525}
526
527void fb_queue_reboot(void)
528{
529 Action *a = queue_action(OP_COMMAND, "reboot");
530 a->func = cb_do_nothing;
531 a->msg = "rebooting";
532}
533
534void fb_queue_command(const char *cmd, const char *msg)
535{
536 Action *a = queue_action(OP_COMMAND, cmd);
537 a->msg = msg;
538}
539
540void fb_queue_download(const char *name, void *data, unsigned size)
541{
jp abgrall88e8f612013-06-26 03:51:29 +0000542 Action *a = queue_action(OP_DOWNLOAD, "");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800543 a->data = data;
544 a->size = size;
545 a->msg = mkmsg("downloading '%s'", name);
546}
547
548void fb_queue_notice(const char *notice)
549{
550 Action *a = queue_action(OP_NOTICE, "");
551 a->data = (void*) notice;
552}
553
Mark Wachsler157b0012013-10-02 09:35:38 -0400554void fb_queue_wait_for_disconnect(void)
555{
556 queue_action(OP_WAIT_FOR_DISCONNECT, "");
557}
558
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700559int fb_execute_queue(usb_handle *usb)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800560{
561 Action *a;
562 char resp[FB_RESPONSE_SZ+1];
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700563 int status = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800564
565 a = action_list;
Scott Anderson13081c62012-04-06 12:39:30 -0700566 if (!a)
567 return status;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800568 resp[FB_RESPONSE_SZ] = 0;
569
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500570 double start = -1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800571 for (a = action_list; a; a = a->next) {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500572 a->start = now();
573 if (start < 0) start = a->start;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800574 if (a->msg) {
Brian Swetland63e52052010-06-28 11:14:26 -0700575 // fprintf(stderr,"%30s... ",a->msg);
576 fprintf(stderr,"%s...\n",a->msg);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800577 }
578 if (a->op == OP_DOWNLOAD) {
579 status = fb_download_data(usb, a->data, a->size);
580 status = a->func(a, status, status ? fb_get_error() : "");
581 if (status) break;
582 } else if (a->op == OP_COMMAND) {
583 status = fb_command(usb, a->cmd);
584 status = a->func(a, status, status ? fb_get_error() : "");
585 if (status) break;
586 } else if (a->op == OP_QUERY) {
587 status = fb_command_response(usb, a->cmd, resp);
588 status = a->func(a, status, status ? fb_get_error() : resp);
589 if (status) break;
590 } else if (a->op == OP_NOTICE) {
591 fprintf(stderr,"%s\n",(char*)a->data);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800592 } else if (a->op == OP_FORMAT) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700593 status = fb_format(a, usb, (int)a->data);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800594 status = a->func(a, status, status ? fb_get_error() : "");
595 if (status) break;
Colin Crossf8387882012-05-24 17:18:41 -0700596 } else if (a->op == OP_DOWNLOAD_SPARSE) {
597 status = fb_download_data_sparse(usb, a->data);
598 status = a->func(a, status, status ? fb_get_error() : "");
599 if (status) break;
Mark Wachsler157b0012013-10-02 09:35:38 -0400600 } else if (a->op == OP_WAIT_FOR_DISCONNECT) {
601 usb_wait_for_disconnect(usb);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800602 } else {
603 die("bogus action");
604 }
605 }
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500606
607 fprintf(stderr,"finished. total time: %.3fs\n", (now() - start));
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700608 return status;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800609}
Scott Anderson13081c62012-04-06 12:39:30 -0700610
611int fb_queue_is_empty(void)
612{
613 return (action_list == NULL);
614}