The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 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 Pomazau | 5ae3f93 | 2012-02-28 07:21:08 -0800 | [diff] [blame] | 12 | * the documentation and/or other materials provided with the |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 13 | * 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 Pomazau | 5ae3f93 | 2012-02-28 07:21:08 -0800 | [diff] [blame] | 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 23 | * 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 Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 29 | #include "fastboot.h" |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 30 | #include "fs.h" |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 31 | |
Colin Cross | 81c632e | 2013-01-23 19:13:43 -0800 | [diff] [blame] | 32 | #include <errno.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | #include <stdarg.h> |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 34 | #include <stdbool.h> |
Mark Salyzyn | 5957c1f | 2014-04-30 14:05:28 -0700 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 37 | #include <string.h> |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 38 | #include <sys/stat.h> |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 39 | #include <sys/types.h> |
| 40 | #include <unistd.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 42 | #ifdef USE_MINGW |
| 43 | #include <fcntl.h> |
| 44 | #else |
| 45 | #include <sys/mman.h> |
| 46 | #endif |
| 47 | |
Mark Salyzyn | 5957c1f | 2014-04-30 14:05:28 -0700 | [diff] [blame] | 48 | #ifndef __unused |
| 49 | #define __unused __attribute__((__unused__)) |
| 50 | #endif |
| 51 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 52 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 53 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 54 | #define OP_DOWNLOAD 1 |
| 55 | #define OP_COMMAND 2 |
| 56 | #define OP_QUERY 3 |
| 57 | #define OP_NOTICE 4 |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 58 | #define OP_DOWNLOAD_SPARSE 5 |
| 59 | #define OP_WAIT_FOR_DISCONNECT 6 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 60 | |
| 61 | typedef struct Action Action; |
| 62 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 63 | #define CMD_SIZE 64 |
| 64 | |
Anatol Pomazau | 5ae3f93 | 2012-02-28 07:21:08 -0800 | [diff] [blame] | 65 | struct Action |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 66 | { |
| 67 | unsigned op; |
| 68 | Action *next; |
| 69 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 70 | char cmd[CMD_SIZE]; |
Wink Saville | b98762f | 2011-04-04 17:54:59 -0700 | [diff] [blame] | 71 | const char *prod; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 72 | void *data; |
Alexander Levitskiy | 8d7ddb3 | 2014-05-07 23:31:59 +0000 | [diff] [blame] | 73 | unsigned size; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 74 | |
| 75 | const char *msg; |
| 76 | int (*func)(Action *a, int status, char *resp); |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 77 | |
| 78 | double start; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static Action *action_list = 0; |
| 82 | static Action *action_last = 0; |
| 83 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 84 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 85 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 86 | |
Colin Cross | 80f2d03 | 2012-05-24 18:24:53 -0700 | [diff] [blame] | 87 | int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...) |
| 88 | { |
| 89 | char cmd[CMD_SIZE] = "getvar:"; |
| 90 | int getvar_len = strlen(cmd); |
| 91 | va_list args; |
| 92 | |
| 93 | response[FB_RESPONSE_SZ] = '\0'; |
| 94 | va_start(args, fmt); |
| 95 | vsnprintf(cmd + getvar_len, sizeof(cmd) - getvar_len, fmt, args); |
| 96 | va_end(args); |
| 97 | cmd[CMD_SIZE - 1] = '\0'; |
| 98 | return fb_command_response(usb, cmd, response); |
| 99 | } |
| 100 | |
Anatol Pomazau | c8ba536 | 2011-12-15 17:50:18 -0800 | [diff] [blame] | 101 | |
Ken Sumrall | 5ee5d38 | 2012-09-29 14:46:25 -0700 | [diff] [blame] | 102 | /* Return true if this partition is supported by the fastboot format command. |
| 103 | * It is also used to determine if we should first erase a partition before |
| 104 | * flashing it with an ext4 filesystem. See needs_erase() |
| 105 | * |
| 106 | * Not all devices report the filesystem type, so don't report any errors, |
| 107 | * just return false. |
| 108 | */ |
JP Abgrall | 7e85974 | 2014-05-06 15:14:15 -0700 | [diff] [blame] | 109 | int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override) |
Ken Sumrall | 5ee5d38 | 2012-09-29 14:46:25 -0700 | [diff] [blame] | 110 | { |
JP Abgrall | 7e85974 | 2014-05-06 15:14:15 -0700 | [diff] [blame] | 111 | char fs_type[FB_RESPONSE_SZ + 1] = {0,}; |
Ken Sumrall | 5ee5d38 | 2012-09-29 14:46:25 -0700 | [diff] [blame] | 112 | int status; |
Ken Sumrall | 5ee5d38 | 2012-09-29 14:46:25 -0700 | [diff] [blame] | 113 | |
JP Abgrall | 7e85974 | 2014-05-06 15:14:15 -0700 | [diff] [blame] | 114 | if (type_override) { |
| 115 | return !!fs_get_generator(type_override); |
| 116 | } |
| 117 | status = fb_getvar(usb, fs_type, "partition-type:%s", partition); |
Ken Sumrall | 5ee5d38 | 2012-09-29 14:46:25 -0700 | [diff] [blame] | 118 | if (status) { |
| 119 | return 0; |
| 120 | } |
JP Abgrall | 7e85974 | 2014-05-06 15:14:15 -0700 | [diff] [blame] | 121 | return !!fs_get_generator(fs_type); |
Ken Sumrall | 5ee5d38 | 2012-09-29 14:46:25 -0700 | [diff] [blame] | 122 | } |
| 123 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 124 | static int cb_default(Action *a, int status, char *resp) |
| 125 | { |
| 126 | if (status) { |
| 127 | fprintf(stderr,"FAILED (%s)\n", resp); |
| 128 | } else { |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 129 | double split = now(); |
| 130 | fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start)); |
| 131 | a->start = split; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 132 | } |
| 133 | return status; |
| 134 | } |
| 135 | |
| 136 | static Action *queue_action(unsigned op, const char *fmt, ...) |
| 137 | { |
| 138 | Action *a; |
| 139 | va_list ap; |
Bruce Beare | 50b3995 | 2010-07-15 08:52:01 -0700 | [diff] [blame] | 140 | size_t cmdsize; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 141 | |
| 142 | a = calloc(1, sizeof(Action)); |
| 143 | if (a == 0) die("out of memory"); |
| 144 | |
| 145 | va_start(ap, fmt); |
Bruce Beare | 50b3995 | 2010-07-15 08:52:01 -0700 | [diff] [blame] | 146 | cmdsize = vsnprintf(a->cmd, sizeof(a->cmd), fmt, ap); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 147 | va_end(ap); |
| 148 | |
Bruce Beare | 50b3995 | 2010-07-15 08:52:01 -0700 | [diff] [blame] | 149 | if (cmdsize >= sizeof(a->cmd)) { |
| 150 | free(a); |
| 151 | die("Command length (%d) exceeds maximum size (%d)", cmdsize, sizeof(a->cmd)); |
| 152 | } |
| 153 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 154 | if (action_last) { |
| 155 | action_last->next = a; |
| 156 | } else { |
| 157 | action_list = a; |
| 158 | } |
| 159 | action_last = a; |
| 160 | a->op = op; |
| 161 | a->func = cb_default; |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 162 | |
| 163 | a->start = -1; |
| 164 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 165 | return a; |
| 166 | } |
| 167 | |
| 168 | void fb_queue_erase(const char *ptn) |
| 169 | { |
| 170 | Action *a; |
| 171 | a = queue_action(OP_COMMAND, "erase:%s", ptn); |
| 172 | a->msg = mkmsg("erasing '%s'", ptn); |
| 173 | } |
| 174 | |
Alexander Levitskiy | 8d7ddb3 | 2014-05-07 23:31:59 +0000 | [diff] [blame] | 175 | void fb_queue_flash(const char *ptn, void *data, unsigned sz) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 176 | { |
| 177 | Action *a; |
| 178 | |
| 179 | a = queue_action(OP_DOWNLOAD, ""); |
| 180 | a->data = data; |
| 181 | a->size = sz; |
| 182 | a->msg = mkmsg("sending '%s' (%d KB)", ptn, sz / 1024); |
| 183 | |
| 184 | a = queue_action(OP_COMMAND, "flash:%s", ptn); |
| 185 | a->msg = mkmsg("writing '%s'", ptn); |
| 186 | } |
| 187 | |
Alexander Levitskiy | 8d7ddb3 | 2014-05-07 23:31:59 +0000 | [diff] [blame] | 188 | void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz) |
Colin Cross | f838788 | 2012-05-24 17:18:41 -0700 | [diff] [blame] | 189 | { |
| 190 | Action *a; |
| 191 | |
| 192 | a = queue_action(OP_DOWNLOAD_SPARSE, ""); |
| 193 | a->data = s; |
| 194 | a->size = 0; |
| 195 | a->msg = mkmsg("sending sparse '%s' (%d KB)", ptn, sz / 1024); |
| 196 | |
| 197 | a = queue_action(OP_COMMAND, "flash:%s", ptn); |
| 198 | a->msg = mkmsg("writing '%s'", ptn); |
| 199 | } |
| 200 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 201 | static int match(char *str, const char **value, unsigned count) |
| 202 | { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 203 | unsigned n; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 204 | |
| 205 | for (n = 0; n < count; n++) { |
| 206 | const char *val = value[n]; |
| 207 | int len = strlen(val); |
| 208 | int match; |
| 209 | |
| 210 | if ((len > 1) && (val[len-1] == '*')) { |
| 211 | len--; |
| 212 | match = !strncmp(val, str, len); |
| 213 | } else { |
| 214 | match = !strcmp(val, str); |
| 215 | } |
| 216 | |
| 217 | if (match) return 1; |
| 218 | } |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | static int cb_check(Action *a, int status, char *resp, int invert) |
| 226 | { |
| 227 | const char **value = a->data; |
| 228 | unsigned count = a->size; |
| 229 | unsigned n; |
| 230 | int yes; |
| 231 | |
| 232 | if (status) { |
| 233 | fprintf(stderr,"FAILED (%s)\n", resp); |
| 234 | return status; |
| 235 | } |
| 236 | |
Wink Saville | b98762f | 2011-04-04 17:54:59 -0700 | [diff] [blame] | 237 | if (a->prod) { |
| 238 | if (strcmp(a->prod, cur_product) != 0) { |
| 239 | double split = now(); |
| 240 | fprintf(stderr,"IGNORE, product is %s required only for %s [%7.3fs]\n", |
| 241 | cur_product, a->prod, (split - a->start)); |
| 242 | a->start = split; |
| 243 | return 0; |
| 244 | } |
| 245 | } |
| 246 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 247 | yes = match(resp, value, count); |
| 248 | if (invert) yes = !yes; |
| 249 | |
| 250 | if (yes) { |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 251 | double split = now(); |
| 252 | fprintf(stderr,"OKAY [%7.3fs]\n", (split - a->start)); |
| 253 | a->start = split; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | fprintf(stderr,"FAILED\n\n"); |
| 258 | fprintf(stderr,"Device %s is '%s'.\n", a->cmd + 7, resp); |
| 259 | fprintf(stderr,"Update %s '%s'", |
| 260 | invert ? "rejects" : "requires", value[0]); |
| 261 | for (n = 1; n < count; n++) { |
| 262 | fprintf(stderr," or '%s'", value[n]); |
| 263 | } |
| 264 | fprintf(stderr,".\n\n"); |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | static int cb_require(Action *a, int status, char *resp) |
| 269 | { |
| 270 | return cb_check(a, status, resp, 0); |
| 271 | } |
| 272 | |
| 273 | static int cb_reject(Action *a, int status, char *resp) |
| 274 | { |
| 275 | return cb_check(a, status, resp, 1); |
| 276 | } |
| 277 | |
Wink Saville | b98762f | 2011-04-04 17:54:59 -0700 | [diff] [blame] | 278 | void fb_queue_require(const char *prod, const char *var, |
| 279 | int invert, unsigned nvalues, const char **value) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 280 | { |
| 281 | Action *a; |
| 282 | a = queue_action(OP_QUERY, "getvar:%s", var); |
Wink Saville | b98762f | 2011-04-04 17:54:59 -0700 | [diff] [blame] | 283 | a->prod = prod; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 284 | a->data = value; |
| 285 | a->size = nvalues; |
| 286 | a->msg = mkmsg("checking %s", var); |
| 287 | a->func = invert ? cb_reject : cb_require; |
| 288 | if (a->data == 0) die("out of memory"); |
| 289 | } |
| 290 | |
| 291 | static int cb_display(Action *a, int status, char *resp) |
| 292 | { |
| 293 | if (status) { |
| 294 | fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); |
| 295 | return status; |
| 296 | } |
| 297 | fprintf(stderr, "%s: %s\n", (char*) a->data, resp); |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | void fb_queue_display(const char *var, const char *prettyname) |
| 302 | { |
| 303 | Action *a; |
| 304 | a = queue_action(OP_QUERY, "getvar:%s", var); |
| 305 | a->data = strdup(prettyname); |
| 306 | if (a->data == 0) die("out of memory"); |
| 307 | a->func = cb_display; |
| 308 | } |
| 309 | |
Wink Saville | b98762f | 2011-04-04 17:54:59 -0700 | [diff] [blame] | 310 | static int cb_save(Action *a, int status, char *resp) |
| 311 | { |
| 312 | if (status) { |
| 313 | fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); |
| 314 | return status; |
| 315 | } |
| 316 | strncpy(a->data, resp, a->size); |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | void fb_queue_query_save(const char *var, char *dest, unsigned dest_size) |
| 321 | { |
| 322 | Action *a; |
| 323 | a = queue_action(OP_QUERY, "getvar:%s", var); |
| 324 | a->data = (void *)dest; |
| 325 | a->size = dest_size; |
| 326 | a->func = cb_save; |
| 327 | } |
| 328 | |
Mark Salyzyn | 5957c1f | 2014-04-30 14:05:28 -0700 | [diff] [blame] | 329 | static int cb_do_nothing(Action *a __unused, int status __unused, char *resp __unused) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 330 | { |
| 331 | fprintf(stderr,"\n"); |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | void fb_queue_reboot(void) |
| 336 | { |
| 337 | Action *a = queue_action(OP_COMMAND, "reboot"); |
| 338 | a->func = cb_do_nothing; |
| 339 | a->msg = "rebooting"; |
| 340 | } |
| 341 | |
| 342 | void fb_queue_command(const char *cmd, const char *msg) |
| 343 | { |
| 344 | Action *a = queue_action(OP_COMMAND, cmd); |
| 345 | a->msg = msg; |
| 346 | } |
| 347 | |
| 348 | void fb_queue_download(const char *name, void *data, unsigned size) |
| 349 | { |
| 350 | Action *a = queue_action(OP_DOWNLOAD, ""); |
| 351 | a->data = data; |
| 352 | a->size = size; |
| 353 | a->msg = mkmsg("downloading '%s'", name); |
| 354 | } |
| 355 | |
| 356 | void fb_queue_notice(const char *notice) |
| 357 | { |
| 358 | Action *a = queue_action(OP_NOTICE, ""); |
| 359 | a->data = (void*) notice; |
| 360 | } |
| 361 | |
Mark Wachsler | 157b001 | 2013-10-02 09:35:38 -0400 | [diff] [blame] | 362 | void fb_queue_wait_for_disconnect(void) |
| 363 | { |
| 364 | queue_action(OP_WAIT_FOR_DISCONNECT, ""); |
| 365 | } |
| 366 | |
Brian Carlstrom | eb31c0b | 2010-04-23 12:38:51 -0700 | [diff] [blame] | 367 | int fb_execute_queue(usb_handle *usb) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 368 | { |
| 369 | Action *a; |
| 370 | char resp[FB_RESPONSE_SZ+1]; |
Brian Carlstrom | eb31c0b | 2010-04-23 12:38:51 -0700 | [diff] [blame] | 371 | int status = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 372 | |
| 373 | a = action_list; |
Scott Anderson | 13081c6 | 2012-04-06 12:39:30 -0700 | [diff] [blame] | 374 | if (!a) |
| 375 | return status; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 376 | resp[FB_RESPONSE_SZ] = 0; |
| 377 | |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 378 | double start = -1; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 379 | for (a = action_list; a; a = a->next) { |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 380 | a->start = now(); |
| 381 | if (start < 0) start = a->start; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 382 | if (a->msg) { |
Brian Swetland | 63e5205 | 2010-06-28 11:14:26 -0700 | [diff] [blame] | 383 | // fprintf(stderr,"%30s... ",a->msg); |
| 384 | fprintf(stderr,"%s...\n",a->msg); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 385 | } |
| 386 | if (a->op == OP_DOWNLOAD) { |
| 387 | status = fb_download_data(usb, a->data, a->size); |
| 388 | status = a->func(a, status, status ? fb_get_error() : ""); |
| 389 | if (status) break; |
| 390 | } else if (a->op == OP_COMMAND) { |
| 391 | status = fb_command(usb, a->cmd); |
| 392 | status = a->func(a, status, status ? fb_get_error() : ""); |
| 393 | if (status) break; |
| 394 | } else if (a->op == OP_QUERY) { |
| 395 | status = fb_command_response(usb, a->cmd, resp); |
| 396 | status = a->func(a, status, status ? fb_get_error() : resp); |
| 397 | if (status) break; |
| 398 | } else if (a->op == OP_NOTICE) { |
| 399 | fprintf(stderr,"%s\n",(char*)a->data); |
Colin Cross | f838788 | 2012-05-24 17:18:41 -0700 | [diff] [blame] | 400 | } else if (a->op == OP_DOWNLOAD_SPARSE) { |
| 401 | status = fb_download_data_sparse(usb, a->data); |
| 402 | status = a->func(a, status, status ? fb_get_error() : ""); |
| 403 | if (status) break; |
Mark Wachsler | 157b001 | 2013-10-02 09:35:38 -0400 | [diff] [blame] | 404 | } else if (a->op == OP_WAIT_FOR_DISCONNECT) { |
| 405 | usb_wait_for_disconnect(usb); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 406 | } else { |
| 407 | die("bogus action"); |
| 408 | } |
| 409 | } |
Daniel Sandler | cb6e22b | 2010-02-25 14:05:33 -0500 | [diff] [blame] | 410 | |
| 411 | fprintf(stderr,"finished. total time: %.3fs\n", (now() - start)); |
Brian Carlstrom | eb31c0b | 2010-04-23 12:38:51 -0700 | [diff] [blame] | 412 | return status; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 413 | } |
Scott Anderson | 13081c6 | 2012-04-06 12:39:30 -0700 | [diff] [blame] | 414 | |
| 415 | int fb_queue_is_empty(void) |
| 416 | { |
| 417 | return (action_list == NULL); |
| 418 | } |