blob: b07e74251adcec82633400f3664f1dd98028bd57 [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>
Daniel Sandlercb6e22b2010-02-25 14:05:33 -050039#include <sys/time.h>
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080040#include <sys/types.h>
41#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080043#ifdef USE_MINGW
44#include <fcntl.h>
45#else
46#include <sys/mman.h>
47#endif
48
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080049#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080050
Daniel Sandlercb6e22b2010-02-25 14:05:33 -050051double now()
52{
53 struct timeval tv;
54 gettimeofday(&tv, NULL);
55 return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
56}
57
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080058char *mkmsg(const char *fmt, ...)
59{
60 char buf[256];
61 char *s;
62 va_list ap;
63
64 va_start(ap, fmt);
65 vsprintf(buf, fmt, ap);
66 va_end(ap);
Anatol Pomazau5ae3f932012-02-28 07:21:08 -080067
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080068 s = strdup(buf);
69 if (s == 0) die("out of memory");
70 return s;
71}
72
73#define OP_DOWNLOAD 1
74#define OP_COMMAND 2
75#define OP_QUERY 3
76#define OP_NOTICE 4
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080077#define OP_FORMAT 5
Colin Crossf8387882012-05-24 17:18:41 -070078#define OP_DOWNLOAD_SPARSE 6
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079
80typedef struct Action Action;
81
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080082#define CMD_SIZE 64
83
Anatol Pomazau5ae3f932012-02-28 07:21:08 -080084struct Action
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080085{
86 unsigned op;
87 Action *next;
88
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080089 char cmd[CMD_SIZE];
Wink Savilleb98762f2011-04-04 17:54:59 -070090 const char *prod;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091 void *data;
92 unsigned size;
93
94 const char *msg;
95 int (*func)(Action *a, int status, char *resp);
Daniel Sandlercb6e22b2010-02-25 14:05:33 -050096
97 double start;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080098};
99
100static Action *action_list = 0;
101static Action *action_last = 0;
102
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800103
104struct image_data {
105 long long partition_size;
106 long long image_size; // real size of image file
107 void *buffer;
108};
109
110void generate_ext4_image(struct image_data *image);
111void cleanup_image(struct image_data *image);
112
Colin Cross80f2d032012-05-24 18:24:53 -0700113int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...)
114{
115 char cmd[CMD_SIZE] = "getvar:";
116 int getvar_len = strlen(cmd);
117 va_list args;
118
119 response[FB_RESPONSE_SZ] = '\0';
120 va_start(args, fmt);
121 vsnprintf(cmd + getvar_len, sizeof(cmd) - getvar_len, fmt, args);
122 va_end(args);
123 cmd[CMD_SIZE - 1] = '\0';
124 return fb_command_response(usb, cmd, response);
125}
126
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800127struct generator {
128 char *fs_type;
129
130 /* generate image and return it as image->buffer.
131 * size of the buffer returned as image->image_size.
132 *
133 * image->partition_size specifies what is the size of the
134 * file partition we generate image for.
135 */
136 void (*generate)(struct image_data *image);
137
138 /* it cleans the buffer allocated during image creation.
139 * this function probably does free() or munmap().
140 */
141 void (*cleanup)(struct image_data *image);
142} generators[] = {
143 { "ext4", generate_ext4_image, cleanup_image }
144};
145
Ken Sumrall5ee5d382012-09-29 14:46:25 -0700146/* Return true if this partition is supported by the fastboot format command.
147 * It is also used to determine if we should first erase a partition before
148 * flashing it with an ext4 filesystem. See needs_erase()
149 *
150 * Not all devices report the filesystem type, so don't report any errors,
151 * just return false.
152 */
153int fb_format_supported(usb_handle *usb, const char *partition)
154{
155 char response[FB_RESPONSE_SZ+1];
156 struct generator *generator = NULL;
157 int status;
158 unsigned int i;
159
160 status = fb_getvar(usb, response, "partition-type:%s", partition);
161 if (status) {
162 return 0;
163 }
164
165 for (i = 0; i < ARRAY_SIZE(generators); i++) {
166 if (!strncmp(generators[i].fs_type, response, FB_RESPONSE_SZ)) {
167 generator = &generators[i];
168 break;
169 }
170 }
171
172 if (generator) {
173 return 1;
174 }
175
176 return 0;
177}
178
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800179static int cb_default(Action *a, int status, char *resp)
180{
181 if (status) {
182 fprintf(stderr,"FAILED (%s)\n", resp);
183 } else {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500184 double split = now();
185 fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start));
186 a->start = split;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800187 }
188 return status;
189}
190
191static Action *queue_action(unsigned op, const char *fmt, ...)
192{
193 Action *a;
194 va_list ap;
Bruce Beare50b39952010-07-15 08:52:01 -0700195 size_t cmdsize;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800196
197 a = calloc(1, sizeof(Action));
198 if (a == 0) die("out of memory");
199
200 va_start(ap, fmt);
Bruce Beare50b39952010-07-15 08:52:01 -0700201 cmdsize = vsnprintf(a->cmd, sizeof(a->cmd), fmt, ap);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800202 va_end(ap);
203
Bruce Beare50b39952010-07-15 08:52:01 -0700204 if (cmdsize >= sizeof(a->cmd)) {
205 free(a);
206 die("Command length (%d) exceeds maximum size (%d)", cmdsize, sizeof(a->cmd));
207 }
208
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800209 if (action_last) {
210 action_last->next = a;
211 } else {
212 action_list = a;
213 }
214 action_last = a;
215 a->op = op;
216 a->func = cb_default;
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500217
218 a->start = -1;
219
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800220 return a;
221}
222
223void fb_queue_erase(const char *ptn)
224{
225 Action *a;
226 a = queue_action(OP_COMMAND, "erase:%s", ptn);
227 a->msg = mkmsg("erasing '%s'", ptn);
228}
229
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800230/* Loads file content into buffer. Returns NULL on error. */
231static void *load_buffer(int fd, off_t size)
232{
233 void *buffer;
234
235#ifdef USE_MINGW
236 ssize_t count = 0;
237
238 // mmap is more efficient but mingw does not support it.
239 // In this case we read whole image into memory buffer.
240 buffer = malloc(size);
241 if (!buffer) {
242 perror("malloc");
243 return NULL;
244 }
245
246 lseek(fd, 0, SEEK_SET);
247 while(count < size) {
248 ssize_t actually_read = read(fd, (char*)buffer+count, size-count);
249
250 if (actually_read == 0) {
251 break;
252 }
253 if (actually_read < 0) {
254 if (errno == EINTR) {
255 continue;
256 }
257 perror("read");
258 free(buffer);
259 return NULL;
260 }
261
262 count += actually_read;
263 }
264#else
265 buffer = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
266 if (buffer == MAP_FAILED) {
267 perror("mmap");
268 return NULL;
269 }
270#endif
271
272 return buffer;
273}
274
275void cleanup_image(struct image_data *image)
276{
277#ifdef USE_MINGW
278 free(image->buffer);
279#else
280 munmap(image->buffer, image->image_size);
281#endif
282}
283
284void generate_ext4_image(struct image_data *image)
285{
286 int fd;
287 struct stat st;
288
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800289 fd = fileno(tmpfile());
Colin Cross2aaf5e82013-01-23 15:41:08 -0800290 make_ext4fs_sparse_fd(fd, image->partition_size, NULL, NULL);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800291
292 fstat(fd, &st);
293 image->image_size = st.st_size;
294 image->buffer = load_buffer(fd, st.st_size);
295
296 close(fd);
297}
298
JP Abgrall30ae5802012-05-07 20:25:24 -0700299int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported)
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800300{
301 const char *partition = a->cmd;
302 char response[FB_RESPONSE_SZ+1];
303 int status = 0;
304 struct image_data image;
305 struct generator *generator = NULL;
306 int fd;
307 unsigned i;
308 char cmd[CMD_SIZE];
309
Colin Cross80f2d032012-05-24 18:24:53 -0700310 status = fb_getvar(usb, response, "partition-type:%s", partition);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800311 if (status) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700312 if (skip_if_not_supported) {
313 fprintf(stderr,
314 "Erase successful, but not automatically formatting.\n");
315 fprintf(stderr,
316 "Can't determine partition type.\n");
317 return 0;
318 }
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800319 fprintf(stderr,"FAILED (%s)\n", fb_get_error());
320 return status;
321 }
322
323 for (i = 0; i < ARRAY_SIZE(generators); i++) {
324 if (!strncmp(generators[i].fs_type, response, FB_RESPONSE_SZ)) {
325 generator = &generators[i];
326 break;
327 }
328 }
329 if (!generator) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700330 if (skip_if_not_supported) {
331 fprintf(stderr,
332 "Erase successful, but not automatically formatting.\n");
333 fprintf(stderr,
334 "File system type %s not supported.\n", response);
335 return 0;
336 }
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800337 fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n",
338 response);
339 return -1;
340 }
341
Colin Cross80f2d032012-05-24 18:24:53 -0700342 status = fb_getvar(usb, response, "partition-size:%s", partition);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800343 if (status) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700344 if (skip_if_not_supported) {
345 fprintf(stderr,
346 "Erase successful, but not automatically formatting.\n");
347 fprintf(stderr, "Unable to get partition size\n.");
348 return 0;
349 }
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800350 fprintf(stderr,"FAILED (%s)\n", fb_get_error());
351 return status;
352 }
353 image.partition_size = strtoll(response, (char **)NULL, 16);
354
355 generator->generate(&image);
356 if (!image.buffer) {
357 fprintf(stderr,"Cannot generate image.\n");
358 return -1;
359 }
360
361 // Following piece of code is similar to fb_queue_flash() but executes
362 // actions directly without queuing
363 fprintf(stderr, "sending '%s' (%lli KB)...\n", partition, image.image_size/1024);
364 status = fb_download_data(usb, image.buffer, image.image_size);
365 if (status) goto cleanup;
366
367 fprintf(stderr, "writing '%s'...\n", partition);
368 snprintf(cmd, sizeof(cmd), "flash:%s", partition);
369 status = fb_command(usb, cmd);
370 if (status) goto cleanup;
371
372cleanup:
373 generator->cleanup(&image);
374
375 return status;
376}
377
JP Abgrall30ae5802012-05-07 20:25:24 -0700378void fb_queue_format(const char *partition, int skip_if_not_supported)
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800379{
380 Action *a;
381
382 a = queue_action(OP_FORMAT, partition);
JP Abgrall30ae5802012-05-07 20:25:24 -0700383 a->data = (void*)skip_if_not_supported;
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800384 a->msg = mkmsg("formatting '%s' partition", partition);
385}
386
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800387void fb_queue_flash(const char *ptn, void *data, unsigned sz)
388{
389 Action *a;
390
391 a = queue_action(OP_DOWNLOAD, "");
392 a->data = data;
393 a->size = sz;
394 a->msg = mkmsg("sending '%s' (%d KB)", ptn, sz / 1024);
395
396 a = queue_action(OP_COMMAND, "flash:%s", ptn);
397 a->msg = mkmsg("writing '%s'", ptn);
398}
399
Colin Crossf8387882012-05-24 17:18:41 -0700400void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz)
401{
402 Action *a;
403
404 a = queue_action(OP_DOWNLOAD_SPARSE, "");
405 a->data = s;
406 a->size = 0;
407 a->msg = mkmsg("sending sparse '%s' (%d KB)", ptn, sz / 1024);
408
409 a = queue_action(OP_COMMAND, "flash:%s", ptn);
410 a->msg = mkmsg("writing '%s'", ptn);
411}
412
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800413static int match(char *str, const char **value, unsigned count)
414{
415 const char *val;
416 unsigned n;
417 int len;
418
419 for (n = 0; n < count; n++) {
420 const char *val = value[n];
421 int len = strlen(val);
422 int match;
423
424 if ((len > 1) && (val[len-1] == '*')) {
425 len--;
426 match = !strncmp(val, str, len);
427 } else {
428 match = !strcmp(val, str);
429 }
430
431 if (match) return 1;
432 }
433
434 return 0;
435}
436
437
438
439static int cb_check(Action *a, int status, char *resp, int invert)
440{
441 const char **value = a->data;
442 unsigned count = a->size;
443 unsigned n;
444 int yes;
445
446 if (status) {
447 fprintf(stderr,"FAILED (%s)\n", resp);
448 return status;
449 }
450
Wink Savilleb98762f2011-04-04 17:54:59 -0700451 if (a->prod) {
452 if (strcmp(a->prod, cur_product) != 0) {
453 double split = now();
454 fprintf(stderr,"IGNORE, product is %s required only for %s [%7.3fs]\n",
455 cur_product, a->prod, (split - a->start));
456 a->start = split;
457 return 0;
458 }
459 }
460
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800461 yes = match(resp, value, count);
462 if (invert) yes = !yes;
463
464 if (yes) {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500465 double split = now();
466 fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start));
467 a->start = split;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800468 return 0;
469 }
470
471 fprintf(stderr,"FAILED\n\n");
472 fprintf(stderr,"Device %s is '%s'.\n", a->cmd + 7, resp);
473 fprintf(stderr,"Update %s '%s'",
474 invert ? "rejects" : "requires", value[0]);
475 for (n = 1; n < count; n++) {
476 fprintf(stderr," or '%s'", value[n]);
477 }
478 fprintf(stderr,".\n\n");
479 return -1;
480}
481
482static int cb_require(Action *a, int status, char *resp)
483{
484 return cb_check(a, status, resp, 0);
485}
486
487static int cb_reject(Action *a, int status, char *resp)
488{
489 return cb_check(a, status, resp, 1);
490}
491
Wink Savilleb98762f2011-04-04 17:54:59 -0700492void fb_queue_require(const char *prod, const char *var,
493 int invert, unsigned nvalues, const char **value)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800494{
495 Action *a;
496 a = queue_action(OP_QUERY, "getvar:%s", var);
Wink Savilleb98762f2011-04-04 17:54:59 -0700497 a->prod = prod;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800498 a->data = value;
499 a->size = nvalues;
500 a->msg = mkmsg("checking %s", var);
501 a->func = invert ? cb_reject : cb_require;
502 if (a->data == 0) die("out of memory");
503}
504
505static int cb_display(Action *a, int status, char *resp)
506{
507 if (status) {
508 fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp);
509 return status;
510 }
511 fprintf(stderr, "%s: %s\n", (char*) a->data, resp);
512 return 0;
513}
514
515void fb_queue_display(const char *var, const char *prettyname)
516{
517 Action *a;
518 a = queue_action(OP_QUERY, "getvar:%s", var);
519 a->data = strdup(prettyname);
520 if (a->data == 0) die("out of memory");
521 a->func = cb_display;
522}
523
Wink Savilleb98762f2011-04-04 17:54:59 -0700524static int cb_save(Action *a, int status, char *resp)
525{
526 if (status) {
527 fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp);
528 return status;
529 }
530 strncpy(a->data, resp, a->size);
531 return 0;
532}
533
534void fb_queue_query_save(const char *var, char *dest, unsigned dest_size)
535{
536 Action *a;
537 a = queue_action(OP_QUERY, "getvar:%s", var);
538 a->data = (void *)dest;
539 a->size = dest_size;
540 a->func = cb_save;
541}
542
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800543static int cb_do_nothing(Action *a, int status, char *resp)
544{
545 fprintf(stderr,"\n");
546 return 0;
547}
548
549void fb_queue_reboot(void)
550{
551 Action *a = queue_action(OP_COMMAND, "reboot");
552 a->func = cb_do_nothing;
553 a->msg = "rebooting";
554}
555
556void fb_queue_command(const char *cmd, const char *msg)
557{
558 Action *a = queue_action(OP_COMMAND, cmd);
559 a->msg = msg;
560}
561
562void fb_queue_download(const char *name, void *data, unsigned size)
563{
jp abgrall88e8f612013-06-26 03:51:29 +0000564 Action *a = queue_action(OP_DOWNLOAD, "");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800565 a->data = data;
566 a->size = size;
567 a->msg = mkmsg("downloading '%s'", name);
568}
569
570void fb_queue_notice(const char *notice)
571{
572 Action *a = queue_action(OP_NOTICE, "");
573 a->data = (void*) notice;
574}
575
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700576int fb_execute_queue(usb_handle *usb)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800577{
578 Action *a;
579 char resp[FB_RESPONSE_SZ+1];
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700580 int status = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800581
582 a = action_list;
Scott Anderson13081c62012-04-06 12:39:30 -0700583 if (!a)
584 return status;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800585 resp[FB_RESPONSE_SZ] = 0;
586
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500587 double start = -1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800588 for (a = action_list; a; a = a->next) {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500589 a->start = now();
590 if (start < 0) start = a->start;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800591 if (a->msg) {
Brian Swetland63e52052010-06-28 11:14:26 -0700592 // fprintf(stderr,"%30s... ",a->msg);
593 fprintf(stderr,"%s...\n",a->msg);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800594 }
595 if (a->op == OP_DOWNLOAD) {
596 status = fb_download_data(usb, a->data, a->size);
597 status = a->func(a, status, status ? fb_get_error() : "");
598 if (status) break;
599 } else if (a->op == OP_COMMAND) {
600 status = fb_command(usb, a->cmd);
601 status = a->func(a, status, status ? fb_get_error() : "");
602 if (status) break;
603 } else if (a->op == OP_QUERY) {
604 status = fb_command_response(usb, a->cmd, resp);
605 status = a->func(a, status, status ? fb_get_error() : resp);
606 if (status) break;
607 } else if (a->op == OP_NOTICE) {
608 fprintf(stderr,"%s\n",(char*)a->data);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800609 } else if (a->op == OP_FORMAT) {
JP Abgrall30ae5802012-05-07 20:25:24 -0700610 status = fb_format(a, usb, (int)a->data);
Anatol Pomazauc8ba5362011-12-15 17:50:18 -0800611 status = a->func(a, status, status ? fb_get_error() : "");
612 if (status) break;
Colin Crossf8387882012-05-24 17:18:41 -0700613 } else if (a->op == OP_DOWNLOAD_SPARSE) {
614 status = fb_download_data_sparse(usb, a->data);
615 status = a->func(a, status, status ? fb_get_error() : "");
616 if (status) break;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800617 } else {
618 die("bogus action");
619 }
620 }
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500621
622 fprintf(stderr,"finished. total time: %.3fs\n", (now() - start));
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700623 return status;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800624}
Scott Anderson13081c62012-04-06 12:39:30 -0700625
626int fb_queue_is_empty(void)
627{
628 return (action_list == NULL);
629}