blob: 087258fe8c72e825d39449b0521bb6c95c6b553e [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <ctype.h>
18#include <errno.h>
19#include <fcntl.h>
20#include <getopt.h>
21#include <limits.h>
22#include <linux/input.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/reboot.h>
27#include <sys/types.h>
28#include <time.h>
29#include <unistd.h>
30
31#include "bootloader.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080032#include "common.h"
33#include "cutils/properties.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080034#include "install.h"
35#include "minui/minui.h"
36#include "minzip/DirUtil.h"
37#include "roots.h"
Doug Zongkerddd6a282009-06-09 12:22:33 -070038#include "recovery_ui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080039
40static const struct option OPTIONS[] = {
41 { "send_intent", required_argument, NULL, 's' },
42 { "update_package", required_argument, NULL, 'u' },
43 { "wipe_data", no_argument, NULL, 'w' },
44 { "wipe_cache", no_argument, NULL, 'c' },
Doug Zongker988500b2009-10-06 14:41:38 -070045 { NULL, 0, NULL, 0 },
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080046};
47
48static const char *COMMAND_FILE = "CACHE:recovery/command";
49static const char *INTENT_FILE = "CACHE:recovery/intent";
50static const char *LOG_FILE = "CACHE:recovery/log";
51static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip";
52static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
53
54/*
55 * The recovery tool communicates with the main system through /cache files.
56 * /cache/recovery/command - INPUT - command line for tool, one arg per line
57 * /cache/recovery/log - OUTPUT - combined log file from recovery run(s)
58 * /cache/recovery/intent - OUTPUT - intent that was passed in
59 *
60 * The arguments which may be supplied in the recovery.command file:
61 * --send_intent=anystring - write the text out to recovery.intent
62 * --update_package=root:path - verify install an OTA package file
63 * --wipe_data - erase user data (and cache), then reboot
64 * --wipe_cache - wipe cache (but not user data), then reboot
Oscar Montemayor05231562009-11-30 08:40:57 -080065 * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080066 *
67 * After completing, we remove /cache/recovery/command and reboot.
68 * Arguments may also be supplied in the bootloader control block (BCB).
69 * These important scenarios must be safely restartable at any point:
70 *
71 * FACTORY RESET
72 * 1. user selects "factory reset"
73 * 2. main system writes "--wipe_data" to /cache/recovery/command
74 * 3. main system reboots into recovery
75 * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data"
76 * -- after this, rebooting will restart the erase --
77 * 5. erase_root() reformats /data
78 * 6. erase_root() reformats /cache
79 * 7. finish_recovery() erases BCB
80 * -- after this, rebooting will restart the main system --
81 * 8. main() calls reboot() to boot main system
82 *
83 * OTA INSTALL
84 * 1. main system downloads OTA package to /cache/some-filename.zip
85 * 2. main system writes "--update_package=CACHE:some-filename.zip"
86 * 3. main system reboots into recovery
87 * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
88 * -- after this, rebooting will attempt to reinstall the update --
89 * 5. install_package() attempts to install the update
90 * NOTE: the package install must itself be restartable from any point
91 * 6. finish_recovery() erases BCB
92 * -- after this, rebooting will (try to) restart the main system --
93 * 7. ** if install failed **
94 * 7a. prompt_and_wait() shows an error icon and waits for the user
95 * 7b; the user reboots (pulling the battery, etc) into the main system
96 * 8. main() calls maybe_install_firmware_update()
97 * ** if the update contained radio/hboot firmware **:
98 * 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache"
99 * -- after this, rebooting will reformat cache & restart main system --
100 * 8b. m_i_f_u() writes firmware image into raw cache partition
101 * 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache"
102 * -- after this, rebooting will attempt to reinstall firmware --
103 * 8d. bootloader tries to flash firmware
104 * 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache")
105 * -- after this, rebooting will reformat cache & restart main system --
106 * 8f. erase_root() reformats /cache
107 * 8g. finish_recovery() erases BCB
108 * -- after this, rebooting will (try to) restart the main system --
109 * 9. main() calls reboot() to boot main system
Oscar Montemayor05231562009-11-30 08:40:57 -0800110 *
111 * ENCRYPTED FILE SYSTEMS ENABLE/DISABLE
112 * 1. user selects "enable encrypted file systems"
113 * 2. main system writes "--set_encrypted_filesystem=on|off" to
114 * /cache/recovery/command
115 * 3. main system reboots into recovery
116 * 4. get_args() writes BCB with "boot-recovery" and
117 * "--set_encrypted_filesystems=on|off"
118 * -- after this, rebooting will restart the transition --
119 * 5. read_encrypted_fs_info() retrieves encrypted file systems settings from /data
120 * Settings include: property to specify the Encrypted FS istatus and
121 * FS encryption key if enabled (not yet implemented)
122 * 6. erase_root() reformats /data
123 * 7. erase_root() reformats /cache
124 * 8. restore_encrypted_fs_info() writes required encrypted file systems settings to /data
125 * Settings include: property to specify the Encrypted FS status and
126 * FS encryption key if enabled (not yet implemented)
127 * 9. finish_recovery() erases BCB
128 * -- after this, rebooting will restart the main system --
129 * 10. main() calls reboot() to boot main system
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800130 */
131
132static const int MAX_ARG_LENGTH = 4096;
133static const int MAX_ARGS = 100;
134
135// open a file given in root:path format, mounting partitions as necessary
136static FILE*
137fopen_root_path(const char *root_path, const char *mode) {
138 if (ensure_root_path_mounted(root_path) != 0) {
139 LOGE("Can't mount %s\n", root_path);
140 return NULL;
141 }
142
143 char path[PATH_MAX] = "";
144 if (translate_root_path(root_path, path, sizeof(path)) == NULL) {
145 LOGE("Bad path %s\n", root_path);
146 return NULL;
147 }
148
149 // When writing, try to create the containing directory, if necessary.
150 // Use generous permissions, the system (init.rc) will reset them.
151 if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1);
152
153 FILE *fp = fopen(path, mode);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800154 return fp;
155}
156
157// close a file, log an error if the error indicator is set
158static void
159check_and_fclose(FILE *fp, const char *name) {
160 fflush(fp);
161 if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno));
162 fclose(fp);
163}
164
165// command line args come from, in decreasing precedence:
166// - the actual command line
167// - the bootloader control block (one per line, after "recovery")
168// - the contents of COMMAND_FILE (one per line)
169static void
170get_args(int *argc, char ***argv) {
171 struct bootloader_message boot;
172 memset(&boot, 0, sizeof(boot));
173 get_bootloader_message(&boot); // this may fail, leaving a zeroed structure
174
175 if (boot.command[0] != 0 && boot.command[0] != 255) {
176 LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command);
177 }
178
179 if (boot.status[0] != 0 && boot.status[0] != 255) {
180 LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status);
181 }
182
183 // --- if arguments weren't supplied, look in the bootloader control block
184 if (*argc <= 1) {
185 boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination
186 const char *arg = strtok(boot.recovery, "\n");
187 if (arg != NULL && !strcmp(arg, "recovery")) {
188 *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
189 (*argv)[0] = strdup(arg);
190 for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
191 if ((arg = strtok(NULL, "\n")) == NULL) break;
192 (*argv)[*argc] = strdup(arg);
193 }
194 LOGI("Got arguments from boot message\n");
195 } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) {
196 LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery);
197 }
198 }
199
200 // --- if that doesn't work, try the command file
201 if (*argc <= 1) {
202 FILE *fp = fopen_root_path(COMMAND_FILE, "r");
203 if (fp != NULL) {
204 char *argv0 = (*argv)[0];
205 *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
206 (*argv)[0] = argv0; // use the same program name
207
208 char buf[MAX_ARG_LENGTH];
209 for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
210 if (!fgets(buf, sizeof(buf), fp)) break;
211 (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline.
212 }
213
214 check_and_fclose(fp, COMMAND_FILE);
215 LOGI("Got arguments from %s\n", COMMAND_FILE);
216 }
217 }
218
219 // --> write the arguments we have back into the bootloader control block
220 // always boot into recovery after this (until finish_recovery() is called)
221 strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
222 strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
223 int i;
224 for (i = 1; i < *argc; ++i) {
225 strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery));
226 strlcat(boot.recovery, "\n", sizeof(boot.recovery));
227 }
228 set_bootloader_message(&boot);
229}
230
Doug Zongker34c98df2009-08-18 12:05:45 -0700231static void
Oscar Montemayor05231562009-11-30 08:40:57 -0800232set_sdcard_update_bootloader_message() {
Doug Zongker34c98df2009-08-18 12:05:45 -0700233 struct bootloader_message boot;
234 memset(&boot, 0, sizeof(boot));
235 strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
236 strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
237 set_bootloader_message(&boot);
238}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800239
240// clear the recovery command and prepare to boot a (hopefully working) system,
241// copy our log file to cache as well (for the system to read), and
242// record any intent we were asked to communicate back to the system.
243// this function is idempotent: call it as many times as you like.
244static void
Oscar Montemayor05231562009-11-30 08:40:57 -0800245finish_recovery(const char *send_intent) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800246 // By this point, we're ready to return to the main system...
247 if (send_intent != NULL) {
248 FILE *fp = fopen_root_path(INTENT_FILE, "w");
Jay Freeman (saurik)619ec2f2008-11-17 01:56:05 +0000249 if (fp == NULL) {
250 LOGE("Can't open %s\n", INTENT_FILE);
251 } else {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800252 fputs(send_intent, fp);
253 check_and_fclose(fp, INTENT_FILE);
254 }
255 }
256
257 // Copy logs to cache so the system can find out what happened.
258 FILE *log = fopen_root_path(LOG_FILE, "a");
Jay Freeman (saurik)619ec2f2008-11-17 01:56:05 +0000259 if (log == NULL) {
260 LOGE("Can't open %s\n", LOG_FILE);
261 } else {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800262 FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r");
263 if (tmplog == NULL) {
264 LOGE("Can't open %s\n", TEMPORARY_LOG_FILE);
265 } else {
266 static long tmplog_offset = 0;
267 fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write
268 char buf[4096];
269 while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log);
270 tmplog_offset = ftell(tmplog);
271 check_and_fclose(tmplog, TEMPORARY_LOG_FILE);
272 }
273 check_and_fclose(log, LOG_FILE);
274 }
275
Oscar Montemayor05231562009-11-30 08:40:57 -0800276 // Reset to mormal system boot so recovery won't cycle indefinitely.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800277 struct bootloader_message boot;
278 memset(&boot, 0, sizeof(boot));
279 set_bootloader_message(&boot);
280
281 // Remove the command file, so recovery won't repeat indefinitely.
282 char path[PATH_MAX] = "";
283 if (ensure_root_path_mounted(COMMAND_FILE) != 0 ||
284 translate_root_path(COMMAND_FILE, path, sizeof(path)) == NULL ||
285 (unlink(path) && errno != ENOENT)) {
286 LOGW("Can't unlink %s\n", COMMAND_FILE);
287 }
288
289 sync(); // For good measure.
290}
291
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800292static int
Oscar Montemayor05231562009-11-30 08:40:57 -0800293erase_root(const char *root) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800294 ui_set_background(BACKGROUND_ICON_INSTALLING);
295 ui_show_indeterminate_progress();
296 ui_print("Formatting %s...\n", root);
297 return format_root_device(root);
298}
299
Doug Zongkerf93d8162009-09-22 15:16:02 -0700300static char**
301prepend_title(char** headers) {
Doug Zongkerd6837852009-06-17 22:07:13 -0700302 char* title[] = { "Android system recovery <"
Doug Zongker64893cc2009-07-14 16:31:56 -0700303 EXPAND(RECOVERY_API_VERSION) "e>",
Doug Zongkerd6837852009-06-17 22:07:13 -0700304 "",
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800305 NULL };
306
Doug Zongkerd6837852009-06-17 22:07:13 -0700307 // count the number of lines in our title, plus the
Doug Zongkerf93d8162009-09-22 15:16:02 -0700308 // caller-provided headers.
Doug Zongkerd6837852009-06-17 22:07:13 -0700309 int count = 0;
310 char** p;
311 for (p = title; *p; ++p, ++count);
Doug Zongkerf93d8162009-09-22 15:16:02 -0700312 for (p = headers; *p; ++p, ++count);
Doug Zongkerd6837852009-06-17 22:07:13 -0700313
Doug Zongkerf93d8162009-09-22 15:16:02 -0700314 char** new_headers = malloc((count+1) * sizeof(char*));
315 char** h = new_headers;
Doug Zongkerd6837852009-06-17 22:07:13 -0700316 for (p = title; *p; ++p, ++h) *h = *p;
Doug Zongkerf93d8162009-09-22 15:16:02 -0700317 for (p = headers; *p; ++p, ++h) *h = *p;
Doug Zongkerd6837852009-06-17 22:07:13 -0700318 *h = NULL;
319
Doug Zongkerf93d8162009-09-22 15:16:02 -0700320 return new_headers;
321}
322
323static int
324get_menu_selection(char** headers, char** items, int menu_only) {
325 // throw away keys pressed previously, so user doesn't
326 // accidentally trigger menu items.
327 ui_clear_key_queue();
328
329 ui_start_menu(headers, items);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800330 int selected = 0;
331 int chosen_item = -1;
332
Doug Zongkerf93d8162009-09-22 15:16:02 -0700333 while (chosen_item < 0) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800334 int key = ui_wait_key();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800335 int visible = ui_text_visible();
336
Doug Zongkerddd6a282009-06-09 12:22:33 -0700337 int action = device_handle_key(key, visible);
338
339 if (action < 0) {
340 switch (action) {
341 case HIGHLIGHT_UP:
342 --selected;
343 selected = ui_menu_select(selected);
344 break;
345 case HIGHLIGHT_DOWN:
346 ++selected;
347 selected = ui_menu_select(selected);
348 break;
349 case SELECT_ITEM:
350 chosen_item = selected;
351 break;
352 case NO_ACTION:
353 break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800354 }
Doug Zongkerf93d8162009-09-22 15:16:02 -0700355 } else if (!menu_only) {
Doug Zongkerddd6a282009-06-09 12:22:33 -0700356 chosen_item = action;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800357 }
Doug Zongkerf93d8162009-09-22 15:16:02 -0700358 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800359
Doug Zongkerf93d8162009-09-22 15:16:02 -0700360 ui_end_menu();
361 return chosen_item;
362}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800363
Doug Zongkerf93d8162009-09-22 15:16:02 -0700364static void
365wipe_data(int confirm) {
366 if (confirm) {
367 static char** title_headers = NULL;
Doug Zongkerddd6a282009-06-09 12:22:33 -0700368
Doug Zongkerf93d8162009-09-22 15:16:02 -0700369 if (title_headers == NULL) {
370 char* headers[] = { "Confirm wipe of all user data?",
371 " THIS CAN NOT BE UNDONE.",
372 "",
373 NULL };
374 title_headers = prepend_title(headers);
375 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800376
Doug Zongkerf93d8162009-09-22 15:16:02 -0700377 char* items[] = { " No",
378 " No",
379 " No",
380 " No",
381 " No",
382 " No",
383 " No",
384 " Yes -- delete all user data", // [7]
385 " No",
386 " No",
387 " No",
388 NULL };
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800389
Doug Zongkerf93d8162009-09-22 15:16:02 -0700390 int chosen_item = get_menu_selection(title_headers, items, 1);
391 if (chosen_item != 7) {
392 return;
393 }
394 }
Doug Zongker1066d2c2009-04-01 13:57:40 -0700395
Doug Zongkerf93d8162009-09-22 15:16:02 -0700396 ui_print("\n-- Wiping data...\n");
397 device_wipe_data();
398 erase_root("DATA:");
399 erase_root("CACHE:");
400 ui_print("Data wipe complete.\n");
401}
402
403static void
Oscar Montemayor05231562009-11-30 08:40:57 -0800404prompt_and_wait() {
Doug Zongkerf93d8162009-09-22 15:16:02 -0700405 char** headers = prepend_title(MENU_HEADERS);
406
407 for (;;) {
408 finish_recovery(NULL);
409 ui_reset_progress();
410
411 int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0);
412
413 // device-specific code may take some action here. It may
414 // return one of the core actions handled in the switch
415 // statement below.
416 chosen_item = device_perform_action(chosen_item);
417
418 switch (chosen_item) {
419 case ITEM_REBOOT:
420 return;
421
422 case ITEM_WIPE_DATA:
423 wipe_data(ui_text_visible());
424 if (!ui_text_visible()) return;
425 break;
426
427 case ITEM_WIPE_CACHE:
428 ui_print("\n-- Wiping cache...\n");
429 erase_root("CACHE:");
430 ui_print("Cache wipe complete.\n");
431 if (!ui_text_visible()) return;
432 break;
433
434 case ITEM_APPLY_SDCARD:
435 ui_print("\n-- Install from sdcard...\n");
436 set_sdcard_update_bootloader_message();
437 int status = install_package(SDCARD_PACKAGE_FILE);
438 if (status != INSTALL_SUCCESS) {
439 ui_set_background(BACKGROUND_ICON_ERROR);
440 ui_print("Installation aborted.\n");
441 } else if (!ui_text_visible()) {
442 return; // reboot if logs aren't visible
443 } else {
Doug Zongkere08991e2010-02-02 13:09:52 -0800444 ui_print("\nInstall from sdcard complete.\n");
Doug Zongkerf93d8162009-09-22 15:16:02 -0700445 }
446 break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800447 }
448 }
449}
450
451static void
Oscar Montemayor05231562009-11-30 08:40:57 -0800452print_property(const char *key, const char *name, void *cookie) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800453 fprintf(stderr, "%s=%s\n", key, name);
454}
455
456int
Oscar Montemayor05231562009-11-30 08:40:57 -0800457main(int argc, char **argv) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800458 time_t start = time(NULL);
459
460 // If these fail, there's not really anywhere to complain...
461 freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
462 freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
463 fprintf(stderr, "Starting recovery on %s", ctime(&start));
464
465 ui_init();
466 get_args(&argc, &argv);
467
468 int previous_runs = 0;
469 const char *send_intent = NULL;
470 const char *update_package = NULL;
471 int wipe_data = 0, wipe_cache = 0;
472
473 int arg;
474 while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
475 switch (arg) {
476 case 'p': previous_runs = atoi(optarg); break;
477 case 's': send_intent = optarg; break;
478 case 'u': update_package = optarg; break;
479 case 'w': wipe_data = wipe_cache = 1; break;
480 case 'c': wipe_cache = 1; break;
481 case '?':
482 LOGE("Invalid command argument\n");
483 continue;
484 }
485 }
486
Doug Zongkerefa1bab2010-02-01 15:59:12 -0800487 device_recovery_start();
488
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800489 fprintf(stderr, "Command:");
490 for (arg = 0; arg < argc; arg++) {
491 fprintf(stderr, " \"%s\"", argv[arg]);
492 }
493 fprintf(stderr, "\n\n");
494
495 property_list(print_property, NULL);
496 fprintf(stderr, "\n");
497
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800498 int status = INSTALL_SUCCESS;
499
Oscar Montemayor2654f5a2010-03-26 16:03:44 -0700500 if (update_package != NULL) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800501 status = install_package(update_package);
502 if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
Doug Zongkerb128f542009-06-18 15:07:14 -0700503 } else if (wipe_data) {
504 if (device_wipe_data()) status = INSTALL_ERROR;
505 if (erase_root("DATA:")) status = INSTALL_ERROR;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800506 if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR;
507 if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
Doug Zongkerb128f542009-06-18 15:07:14 -0700508 } else if (wipe_cache) {
509 if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR;
510 if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n");
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800511 } else {
512 status = INSTALL_ERROR; // No command specified
513 }
514
515 if (status != INSTALL_SUCCESS) ui_set_background(BACKGROUND_ICON_ERROR);
516 if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait();
517
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800518 // Otherwise, get ready to boot the main system...
519 finish_recovery(send_intent);
520 ui_print("Rebooting...\n");
521 sync();
522 reboot(RB_AUTOBOOT);
523 return EXIT_SUCCESS;
524}