blob: 6890643396d5df3278bf0721671f059e0d9d0ef6 [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 */
Aaron Wisnerdb511202018-06-26 15:38:35 -050028#include "engine.h"
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080029
Colin Cross81c632e2013-01-23 19:13:43 -080030#include <errno.h>
Elliott Hughes3ab8b852015-08-25 19:34:13 -070031#include <stdarg.h>
Mark Salyzyn5957c1f2014-04-30 14:05:28 -070032#include <stdio.h>
33#include <stdlib.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080034#include <string.h>
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080035#include <sys/stat.h>
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080036#include <sys/types.h>
37#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080038
Elliott Hughes5620d222018-03-28 08:20:00 -070039#include <memory>
40#include <vector>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080041
Elliott Hughes5620d222018-03-28 08:20:00 -070042#include <android-base/stringprintf.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080043
Jerry Zhang769a9c12018-05-15 17:02:50 -070044#include "constants.h"
Elliott Hughes11ff3452018-04-09 13:58:41 -070045#include "transport.h"
46
Elliott Hughes5620d222018-03-28 08:20:00 -070047enum Op {
48 OP_DOWNLOAD,
49 OP_COMMAND,
50 OP_QUERY,
51 OP_NOTICE,
52 OP_DOWNLOAD_SPARSE,
53 OP_WAIT_FOR_DISCONNECT,
54 OP_DOWNLOAD_FD,
55 OP_UPLOAD,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080056};
57
Elliott Hughes5620d222018-03-28 08:20:00 -070058struct Action {
59 Action(Op op, const std::string& cmd) : op(op), cmd(cmd) {}
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080060
Elliott Hughes5620d222018-03-28 08:20:00 -070061 Op op;
62 std::string cmd;
63 std::string msg;
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080064
Elliott Hughes5620d222018-03-28 08:20:00 -070065 std::string product;
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080066
Elliott Hughes5620d222018-03-28 08:20:00 -070067 void* data = nullptr;
68 // The protocol only supports 32-bit sizes, so you'll have to break
69 // anything larger into multiple chunks.
70 uint32_t size = 0;
71
72 int fd = -1;
73
74 int (*func)(Action& a, int status, const char* resp) = nullptr;
75
76 double start = -1;
77};
78
79static std::vector<std::unique_ptr<Action>> action_list;
Aaron Wisnerdb511202018-06-26 15:38:35 -050080static fastboot::FastBootDriver* fb = nullptr;
Anatol Pomazauc8ba5362011-12-15 17:50:18 -080081
Aaron Wisnerdb511202018-06-26 15:38:35 -050082void fb_init(fastboot::FastBootDriver& fbi) {
83 fb = &fbi;
84 auto cb = [](std::string& info) { fprintf(stderr, "(bootloader) %s\n", info.c_str()); };
85 fb->SetInfoCallback(cb);
86}
Colin Cross80f2d032012-05-24 18:24:53 -070087
Aaron Wisnerdb511202018-06-26 15:38:35 -050088const std::string fb_get_error() {
89 return fb->Error();
90}
91
92bool fb_getvar(const std::string& key, std::string* value) {
93 return !fb->GetVar(key, value);
Colin Cross80f2d032012-05-24 18:24:53 -070094}
95
Elliott Hughes5620d222018-03-28 08:20:00 -070096static int cb_default(Action& a, int status, const char* resp) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080097 if (status) {
98 fprintf(stderr,"FAILED (%s)\n", resp);
99 } else {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500100 double split = now();
Elliott Hughes5620d222018-03-28 08:20:00 -0700101 fprintf(stderr, "OKAY [%7.3fs]\n", (split - a.start));
102 a.start = split;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800103 }
104 return status;
105}
106
Elliott Hughes5620d222018-03-28 08:20:00 -0700107static Action& queue_action(Op op, const std::string& cmd) {
108 std::unique_ptr<Action> a{new Action(op, cmd)};
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800109 a->func = cb_default;
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500110
Elliott Hughes5620d222018-03-28 08:20:00 -0700111 action_list.push_back(std::move(a));
112 return *action_list.back();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800113}
114
Elliott Hughes5620d222018-03-28 08:20:00 -0700115void fb_set_active(const std::string& slot) {
Jerry Zhang769a9c12018-05-15 17:02:50 -0700116 Action& a = queue_action(OP_COMMAND, FB_CMD_SET_ACTIVE ":" + slot);
Elliott Hughesf238d872018-03-29 14:46:29 -0700117 a.msg = "Setting current slot to '" + slot + "'";
Daniel Rosenbergb7bd4ae2015-09-14 21:05:41 -0700118}
119
Elliott Hughes5620d222018-03-28 08:20:00 -0700120void fb_queue_erase(const std::string& partition) {
Jerry Zhang769a9c12018-05-15 17:02:50 -0700121 Action& a = queue_action(OP_COMMAND, FB_CMD_ERASE ":" + partition);
Elliott Hughesf238d872018-03-29 14:46:29 -0700122 a.msg = "Erasing '" + partition + "'";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800123}
124
Elliott Hughes5620d222018-03-28 08:20:00 -0700125void fb_queue_flash_fd(const std::string& partition, int fd, uint32_t sz) {
126 Action& a = queue_action(OP_DOWNLOAD_FD, "");
127 a.fd = fd;
128 a.size = sz;
Elliott Hughesf238d872018-03-29 14:46:29 -0700129 a.msg = android::base::StringPrintf("Sending '%s' (%u KB)", partition.c_str(), sz / 1024);
Chris Fries0ea946c2017-04-12 10:25:57 -0500130
Jerry Zhang769a9c12018-05-15 17:02:50 -0700131 Action& b = queue_action(OP_COMMAND, FB_CMD_FLASH ":" + partition);
Elliott Hughesf238d872018-03-29 14:46:29 -0700132 b.msg = "Writing '" + partition + "'";
Chris Fries0ea946c2017-04-12 10:25:57 -0500133}
134
Elliott Hughes5620d222018-03-28 08:20:00 -0700135void fb_queue_flash(const std::string& partition, void* data, uint32_t sz) {
136 Action& a = queue_action(OP_DOWNLOAD, "");
137 a.data = data;
138 a.size = sz;
Elliott Hughesf238d872018-03-29 14:46:29 -0700139 a.msg = android::base::StringPrintf("Sending '%s' (%u KB)", partition.c_str(), sz / 1024);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800140
Jerry Zhang769a9c12018-05-15 17:02:50 -0700141 Action& b = queue_action(OP_COMMAND, FB_CMD_FLASH ":" + partition);
Elliott Hughesf238d872018-03-29 14:46:29 -0700142 b.msg = "Writing '" + partition + "'";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800143}
144
Elliott Hughes5620d222018-03-28 08:20:00 -0700145void fb_queue_flash_sparse(const std::string& partition, struct sparse_file* s, uint32_t sz,
146 size_t current, size_t total) {
147 Action& a = queue_action(OP_DOWNLOAD_SPARSE, "");
148 a.data = s;
149 a.size = 0;
Elliott Hughesf238d872018-03-29 14:46:29 -0700150 a.msg = android::base::StringPrintf("Sending sparse '%s' %zu/%zu (%u KB)", partition.c_str(),
Elliott Hughes5620d222018-03-28 08:20:00 -0700151 current, total, sz / 1024);
Colin Crossf8387882012-05-24 17:18:41 -0700152
Jerry Zhang769a9c12018-05-15 17:02:50 -0700153 Action& b = queue_action(OP_COMMAND, FB_CMD_FLASH ":" + partition);
Elliott Hughesf238d872018-03-29 14:46:29 -0700154 b.msg = android::base::StringPrintf("Writing sparse '%s' %zu/%zu", partition.c_str(), current,
155 total);
Colin Crossf8387882012-05-24 17:18:41 -0700156}
157
David Anderson0d4277d2018-07-31 13:27:37 -0700158void fb_queue_create_partition(const std::string& partition, const std::string& size) {
159 Action& a = queue_action(OP_COMMAND, FB_CMD_CREATE_PARTITION ":" + partition + ":" + size);
160 a.msg = "Creating '" + partition + "'";
161}
162
163void fb_queue_delete_partition(const std::string& partition) {
164 Action& a = queue_action(OP_COMMAND, FB_CMD_DELETE_PARTITION ":" + partition);
165 a.msg = "Deleting '" + partition + "'";
166}
167
168void fb_queue_resize_partition(const std::string& partition, const std::string& size) {
169 Action& a = queue_action(OP_COMMAND, FB_CMD_RESIZE_PARTITION ":" + partition + ":" + size);
170 a.msg = "Resizing '" + partition + "'";
171}
172
Elliott Hughesb3748de2015-06-23 20:27:58 -0700173static int match(const char* str, const char** value, unsigned count) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800174 unsigned n;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800175
176 for (n = 0; n < count; n++) {
177 const char *val = value[n];
178 int len = strlen(val);
179 int match;
180
181 if ((len > 1) && (val[len-1] == '*')) {
182 len--;
183 match = !strncmp(val, str, len);
184 } else {
185 match = !strcmp(val, str);
186 }
187
188 if (match) return 1;
189 }
190
191 return 0;
192}
193
Elliott Hughes5620d222018-03-28 08:20:00 -0700194static int cb_check(Action& a, int status, const char* resp, int invert) {
195 const char** value = reinterpret_cast<const char**>(a.data);
196 unsigned count = a.size;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800197 unsigned n;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800198
199 if (status) {
200 fprintf(stderr,"FAILED (%s)\n", resp);
201 return status;
202 }
203
Elliott Hughes5620d222018-03-28 08:20:00 -0700204 if (!a.product.empty()) {
205 if (a.product != cur_product) {
Wink Savilleb98762f2011-04-04 17:54:59 -0700206 double split = now();
Elliott Hughes5620d222018-03-28 08:20:00 -0700207 fprintf(stderr, "IGNORE, product is %s required only for %s [%7.3fs]\n", cur_product,
208 a.product.c_str(), (split - a.start));
209 a.start = split;
Wink Savilleb98762f2011-04-04 17:54:59 -0700210 return 0;
211 }
212 }
213
Elliott Hughes5620d222018-03-28 08:20:00 -0700214 int yes = match(resp, value, count);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800215 if (invert) yes = !yes;
216
217 if (yes) {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500218 double split = now();
Elliott Hughes5620d222018-03-28 08:20:00 -0700219 fprintf(stderr, "OKAY [%7.3fs]\n", (split - a.start));
220 a.start = split;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800221 return 0;
222 }
223
Elliott Hughes5620d222018-03-28 08:20:00 -0700224 fprintf(stderr, "FAILED\n\n");
225 fprintf(stderr, "Device %s is '%s'.\n", a.cmd.c_str() + 7, resp);
226 fprintf(stderr, "Update %s '%s'", invert ? "rejects" : "requires", value[0]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800227 for (n = 1; n < count; n++) {
Elliott Hughes5620d222018-03-28 08:20:00 -0700228 fprintf(stderr, " or '%s'", value[n]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800229 }
Elliott Hughes5620d222018-03-28 08:20:00 -0700230 fprintf(stderr, ".\n\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800231 return -1;
232}
233
Elliott Hughes5620d222018-03-28 08:20:00 -0700234static int cb_require(Action& a, int status, const char* resp) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800235 return cb_check(a, status, resp, 0);
236}
237
Elliott Hughes5620d222018-03-28 08:20:00 -0700238static int cb_reject(Action& a, int status, const char* resp) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800239 return cb_check(a, status, resp, 1);
240}
241
Elliott Hughes5620d222018-03-28 08:20:00 -0700242void fb_queue_require(const std::string& product, const std::string& var, bool invert,
243 size_t nvalues, const char** values) {
Jerry Zhang769a9c12018-05-15 17:02:50 -0700244 Action& a = queue_action(OP_QUERY, FB_CMD_GETVAR ":" + var);
Elliott Hughes5620d222018-03-28 08:20:00 -0700245 a.product = product;
246 a.data = values;
247 a.size = nvalues;
248 a.msg = "Checking " + var;
249 a.func = invert ? cb_reject : cb_require;
250 if (a.data == nullptr) die("out of memory");
Elliott Hughesd6365a72017-05-08 18:04:49 -0700251}
252
Elliott Hughes5620d222018-03-28 08:20:00 -0700253static int cb_display(Action& a, int status, const char* resp) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800254 if (status) {
Elliott Hughes5620d222018-03-28 08:20:00 -0700255 fprintf(stderr, "%s FAILED (%s)\n", a.cmd.c_str(), resp);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800256 return status;
257 }
Elliott Hughes5620d222018-03-28 08:20:00 -0700258 fprintf(stderr, "%s: %s\n", static_cast<const char*>(a.data), resp);
259 free(static_cast<char*>(a.data));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800260 return 0;
261}
262
Elliott Hughes5620d222018-03-28 08:20:00 -0700263void fb_queue_display(const std::string& label, const std::string& var) {
Jerry Zhang769a9c12018-05-15 17:02:50 -0700264 Action& a = queue_action(OP_QUERY, FB_CMD_GETVAR ":" + var);
Elliott Hughes5620d222018-03-28 08:20:00 -0700265 a.data = xstrdup(label.c_str());
266 a.func = cb_display;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800267}
268
Elliott Hughes5620d222018-03-28 08:20:00 -0700269static int cb_save(Action& a, int status, const char* resp) {
Wink Savilleb98762f2011-04-04 17:54:59 -0700270 if (status) {
Elliott Hughes5620d222018-03-28 08:20:00 -0700271 fprintf(stderr, "%s FAILED (%s)\n", a.cmd.c_str(), resp);
Wink Savilleb98762f2011-04-04 17:54:59 -0700272 return status;
273 }
Elliott Hughes5620d222018-03-28 08:20:00 -0700274 strncpy(reinterpret_cast<char*>(a.data), resp, a.size);
Wink Savilleb98762f2011-04-04 17:54:59 -0700275 return 0;
276}
277
Elliott Hughes5620d222018-03-28 08:20:00 -0700278void fb_queue_query_save(const std::string& var, char* dest, uint32_t dest_size) {
Jerry Zhang769a9c12018-05-15 17:02:50 -0700279 Action& a = queue_action(OP_QUERY, FB_CMD_GETVAR ":" + var);
Elliott Hughes5620d222018-03-28 08:20:00 -0700280 a.data = dest;
281 a.size = dest_size;
282 a.func = cb_save;
Wink Savilleb98762f2011-04-04 17:54:59 -0700283}
284
Elliott Hughes5620d222018-03-28 08:20:00 -0700285static int cb_do_nothing(Action&, int, const char*) {
286 fprintf(stderr, "\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800287 return 0;
288}
289
Elliott Hughes5620d222018-03-28 08:20:00 -0700290void fb_queue_reboot() {
Jerry Zhang769a9c12018-05-15 17:02:50 -0700291 Action& a = queue_action(OP_COMMAND, FB_CMD_REBOOT);
Elliott Hughes5620d222018-03-28 08:20:00 -0700292 a.func = cb_do_nothing;
Elliott Hughesf238d872018-03-29 14:46:29 -0700293 a.msg = "Rebooting";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800294}
295
Elliott Hughes5620d222018-03-28 08:20:00 -0700296void fb_queue_command(const std::string& cmd, const std::string& msg) {
297 Action& a = queue_action(OP_COMMAND, cmd);
298 a.msg = msg;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800299}
300
Elliott Hughes5620d222018-03-28 08:20:00 -0700301void fb_queue_download(const std::string& name, void* data, uint32_t size) {
302 Action& a = queue_action(OP_DOWNLOAD, "");
303 a.data = data;
304 a.size = size;
305 a.msg = "Downloading '" + name + "'";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800306}
307
Elliott Hughes5620d222018-03-28 08:20:00 -0700308void fb_queue_download_fd(const std::string& name, int fd, uint32_t sz) {
309 Action& a = queue_action(OP_DOWNLOAD_FD, "");
310 a.fd = fd;
311 a.size = sz;
Elliott Hughesf238d872018-03-29 14:46:29 -0700312 a.msg = android::base::StringPrintf("Sending '%s' (%u KB)", name.c_str(), sz / 1024);
Jocelyn Bohr98cc2832017-01-26 19:20:53 -0800313}
314
Elliott Hughes5620d222018-03-28 08:20:00 -0700315void fb_queue_upload(const std::string& outfile) {
316 Action& a = queue_action(OP_UPLOAD, "");
317 a.data = xstrdup(outfile.c_str());
318 a.msg = "Uploading '" + outfile + "'";
Jocelyn Bohr91fefad2017-01-27 14:17:56 -0800319}
320
Elliott Hughes5620d222018-03-28 08:20:00 -0700321void fb_queue_notice(const std::string& notice) {
322 Action& a = queue_action(OP_NOTICE, "");
323 a.msg = notice;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800324}
325
Elliott Hughes5620d222018-03-28 08:20:00 -0700326void fb_queue_wait_for_disconnect() {
Mark Wachsler157b0012013-10-02 09:35:38 -0400327 queue_action(OP_WAIT_FOR_DISCONNECT, "");
328}
329
Aaron Wisnerdb511202018-06-26 15:38:35 -0500330int64_t fb_execute_queue() {
Chris Fries6a999712017-04-04 09:52:47 -0500331 int64_t status = 0;
Elliott Hughes5620d222018-03-28 08:20:00 -0700332 for (auto& a : action_list) {
Daniel Sandlercb6e22b2010-02-25 14:05:33 -0500333 a->start = now();
Elliott Hughes5620d222018-03-28 08:20:00 -0700334 if (!a->msg.empty()) {
Elliott Hughesf238d872018-03-29 14:46:29 -0700335 fprintf(stderr, "%-50s ", a->msg.c_str());
Elliott Hughes855cdf82018-04-02 14:24:03 -0700336 verbose("\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800337 }
338 if (a->op == OP_DOWNLOAD) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500339 char* cbuf = static_cast<char*>(a->data);
340 status = fb->Download(cbuf, a->size);
Elliott Hughes5620d222018-03-28 08:20:00 -0700341 status = a->func(*a, status, status ? fb_get_error().c_str() : "");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800342 if (status) break;
Chris Fries0ea946c2017-04-12 10:25:57 -0500343 } else if (a->op == OP_DOWNLOAD_FD) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500344 status = fb->Download(a->fd, a->size);
Elliott Hughes5620d222018-03-28 08:20:00 -0700345 status = a->func(*a, status, status ? fb_get_error().c_str() : "");
Chris Fries0ea946c2017-04-12 10:25:57 -0500346 if (status) break;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800347 } else if (a->op == OP_COMMAND) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500348 status = fb->RawCommand(a->cmd);
Elliott Hughes5620d222018-03-28 08:20:00 -0700349 status = a->func(*a, status, status ? fb_get_error().c_str() : "");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800350 if (status) break;
351 } else if (a->op == OP_QUERY) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500352 std::string resp;
353 status = fb->RawCommand(a->cmd, &resp);
354 status = a->func(*a, status, status ? fb_get_error().c_str() : resp.c_str());
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800355 if (status) break;
356 } else if (a->op == OP_NOTICE) {
Elliott Hughes5620d222018-03-28 08:20:00 -0700357 // We already showed the notice because it's in `Action::msg`.
Elliott Hughesf238d872018-03-29 14:46:29 -0700358 fprintf(stderr, "\n");
Colin Crossf8387882012-05-24 17:18:41 -0700359 } else if (a->op == OP_DOWNLOAD_SPARSE) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500360 status = fb->Download(reinterpret_cast<sparse_file*>(a->data));
Elliott Hughes5620d222018-03-28 08:20:00 -0700361 status = a->func(*a, status, status ? fb_get_error().c_str() : "");
Colin Crossf8387882012-05-24 17:18:41 -0700362 if (status) break;
Mark Wachsler157b0012013-10-02 09:35:38 -0400363 } else if (a->op == OP_WAIT_FOR_DISCONNECT) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500364 fb->WaitForDisconnect();
Jocelyn Bohr91fefad2017-01-27 14:17:56 -0800365 } else if (a->op == OP_UPLOAD) {
Aaron Wisnerdb511202018-06-26 15:38:35 -0500366 status = fb->Upload(reinterpret_cast<const char*>(a->data));
Elliott Hughes5620d222018-03-28 08:20:00 -0700367 status = a->func(*a, status, status ? fb_get_error().c_str() : "");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800368 } else {
Elliott Hughes5620d222018-03-28 08:20:00 -0700369 die("unknown action: %d", a->op);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800370 }
371 }
Elliott Hughes5620d222018-03-28 08:20:00 -0700372 action_list.clear();
Brian Carlstromeb31c0b2010-04-23 12:38:51 -0700373 return status;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800374}