blob: 62dd8e2a12bf33e293c5f37af19607e73588992c [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"
34#include "firmware.h"
35#include "install.h"
36#include "minui/minui.h"
37#include "minzip/DirUtil.h"
38#include "roots.h"
Doug Zongkerddd6a282009-06-09 12:22:33 -070039#include "recovery_ui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080040
Koushik K. Dutta6060e5c2010-02-11 22:27:06 -080041#include "extendedcommands.h"
42#include "commands.h"
43
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080044static const struct option OPTIONS[] = {
45 { "send_intent", required_argument, NULL, 's' },
46 { "update_package", required_argument, NULL, 'u' },
47 { "wipe_data", no_argument, NULL, 'w' },
48 { "wipe_cache", no_argument, NULL, 'c' },
Doug Zongker988500b2009-10-06 14:41:38 -070049 { NULL, 0, NULL, 0 },
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080050};
51
Koushik K. Duttaa3c2f732010-02-19 14:17:22 -080052static int allow_display_toggle = 1;
53
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080054static const char *COMMAND_FILE = "CACHE:recovery/command";
55static const char *INTENT_FILE = "CACHE:recovery/intent";
56static const char *LOG_FILE = "CACHE:recovery/log";
57static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip";
58static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
59
60/*
61 * The recovery tool communicates with the main system through /cache files.
62 * /cache/recovery/command - INPUT - command line for tool, one arg per line
63 * /cache/recovery/log - OUTPUT - combined log file from recovery run(s)
64 * /cache/recovery/intent - OUTPUT - intent that was passed in
65 *
66 * The arguments which may be supplied in the recovery.command file:
67 * --send_intent=anystring - write the text out to recovery.intent
68 * --update_package=root:path - verify install an OTA package file
69 * --wipe_data - erase user data (and cache), then reboot
70 * --wipe_cache - wipe cache (but not user data), then reboot
71 *
72 * After completing, we remove /cache/recovery/command and reboot.
73 * Arguments may also be supplied in the bootloader control block (BCB).
74 * These important scenarios must be safely restartable at any point:
75 *
76 * FACTORY RESET
77 * 1. user selects "factory reset"
78 * 2. main system writes "--wipe_data" to /cache/recovery/command
79 * 3. main system reboots into recovery
80 * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data"
81 * -- after this, rebooting will restart the erase --
82 * 5. erase_root() reformats /data
83 * 6. erase_root() reformats /cache
84 * 7. finish_recovery() erases BCB
85 * -- after this, rebooting will restart the main system --
86 * 8. main() calls reboot() to boot main system
87 *
88 * OTA INSTALL
89 * 1. main system downloads OTA package to /cache/some-filename.zip
90 * 2. main system writes "--update_package=CACHE:some-filename.zip"
91 * 3. main system reboots into recovery
92 * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
93 * -- after this, rebooting will attempt to reinstall the update --
94 * 5. install_package() attempts to install the update
95 * NOTE: the package install must itself be restartable from any point
96 * 6. finish_recovery() erases BCB
97 * -- after this, rebooting will (try to) restart the main system --
98 * 7. ** if install failed **
99 * 7a. prompt_and_wait() shows an error icon and waits for the user
100 * 7b; the user reboots (pulling the battery, etc) into the main system
101 * 8. main() calls maybe_install_firmware_update()
102 * ** if the update contained radio/hboot firmware **:
103 * 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache"
104 * -- after this, rebooting will reformat cache & restart main system --
105 * 8b. m_i_f_u() writes firmware image into raw cache partition
106 * 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache"
107 * -- after this, rebooting will attempt to reinstall firmware --
108 * 8d. bootloader tries to flash firmware
109 * 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache")
110 * -- after this, rebooting will reformat cache & restart main system --
111 * 8f. erase_root() reformats /cache
112 * 8g. finish_recovery() erases BCB
113 * -- after this, rebooting will (try to) restart the main system --
114 * 9. main() calls reboot() to boot main system
115 */
116
117static const int MAX_ARG_LENGTH = 4096;
118static const int MAX_ARGS = 100;
119
120// open a file given in root:path format, mounting partitions as necessary
121static FILE*
122fopen_root_path(const char *root_path, const char *mode) {
123 if (ensure_root_path_mounted(root_path) != 0) {
124 LOGE("Can't mount %s\n", root_path);
125 return NULL;
126 }
127
128 char path[PATH_MAX] = "";
129 if (translate_root_path(root_path, path, sizeof(path)) == NULL) {
130 LOGE("Bad path %s\n", root_path);
131 return NULL;
132 }
133
134 // When writing, try to create the containing directory, if necessary.
135 // Use generous permissions, the system (init.rc) will reset them.
136 if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1);
137
138 FILE *fp = fopen(path, mode);
Koushik K. Dutta261dde92010-02-25 16:51:45 -0800139 if (fp == NULL && root_path != COMMAND_FILE) LOGE("Can't open %s\n", path);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800140 return fp;
141}
142
143// close a file, log an error if the error indicator is set
144static void
145check_and_fclose(FILE *fp, const char *name) {
146 fflush(fp);
147 if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno));
148 fclose(fp);
149}
150
151// command line args come from, in decreasing precedence:
152// - the actual command line
153// - the bootloader control block (one per line, after "recovery")
154// - the contents of COMMAND_FILE (one per line)
155static void
156get_args(int *argc, char ***argv) {
157 struct bootloader_message boot;
158 memset(&boot, 0, sizeof(boot));
159 get_bootloader_message(&boot); // this may fail, leaving a zeroed structure
160
161 if (boot.command[0] != 0 && boot.command[0] != 255) {
162 LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command);
163 }
164
165 if (boot.status[0] != 0 && boot.status[0] != 255) {
166 LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status);
167 }
168
169 // --- if arguments weren't supplied, look in the bootloader control block
170 if (*argc <= 1) {
171 boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination
172 const char *arg = strtok(boot.recovery, "\n");
173 if (arg != NULL && !strcmp(arg, "recovery")) {
174 *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
175 (*argv)[0] = strdup(arg);
176 for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
177 if ((arg = strtok(NULL, "\n")) == NULL) break;
178 (*argv)[*argc] = strdup(arg);
179 }
180 LOGI("Got arguments from boot message\n");
181 } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) {
182 LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery);
183 }
184 }
185
186 // --- if that doesn't work, try the command file
187 if (*argc <= 1) {
188 FILE *fp = fopen_root_path(COMMAND_FILE, "r");
189 if (fp != NULL) {
190 char *argv0 = (*argv)[0];
191 *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
192 (*argv)[0] = argv0; // use the same program name
193
194 char buf[MAX_ARG_LENGTH];
195 for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
196 if (!fgets(buf, sizeof(buf), fp)) break;
197 (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline.
198 }
199
200 check_and_fclose(fp, COMMAND_FILE);
201 LOGI("Got arguments from %s\n", COMMAND_FILE);
202 }
203 }
204
205 // --> write the arguments we have back into the bootloader control block
206 // always boot into recovery after this (until finish_recovery() is called)
207 strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
208 strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
209 int i;
210 for (i = 1; i < *argc; ++i) {
211 strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery));
212 strlcat(boot.recovery, "\n", sizeof(boot.recovery));
213 }
214 set_bootloader_message(&boot);
215}
216
Koushik K. Duttae9234872010-02-12 00:43:24 -0800217void
Doug Zongker34c98df2009-08-18 12:05:45 -0700218set_sdcard_update_bootloader_message()
219{
220 struct bootloader_message boot;
221 memset(&boot, 0, sizeof(boot));
222 strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
223 strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
224 set_bootloader_message(&boot);
225}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800226
227// clear the recovery command and prepare to boot a (hopefully working) system,
228// copy our log file to cache as well (for the system to read), and
229// record any intent we were asked to communicate back to the system.
230// this function is idempotent: call it as many times as you like.
231static void
232finish_recovery(const char *send_intent)
233{
234 // By this point, we're ready to return to the main system...
235 if (send_intent != NULL) {
236 FILE *fp = fopen_root_path(INTENT_FILE, "w");
237 if (fp != NULL) {
238 fputs(send_intent, fp);
239 check_and_fclose(fp, INTENT_FILE);
240 }
241 }
242
243 // Copy logs to cache so the system can find out what happened.
244 FILE *log = fopen_root_path(LOG_FILE, "a");
245 if (log != NULL) {
246 FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r");
247 if (tmplog == NULL) {
248 LOGE("Can't open %s\n", TEMPORARY_LOG_FILE);
249 } else {
250 static long tmplog_offset = 0;
251 fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write
252 char buf[4096];
253 while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log);
254 tmplog_offset = ftell(tmplog);
255 check_and_fclose(tmplog, TEMPORARY_LOG_FILE);
256 }
257 check_and_fclose(log, LOG_FILE);
258 }
259
260 // Reset the bootloader message to revert to a normal main system boot.
261 struct bootloader_message boot;
262 memset(&boot, 0, sizeof(boot));
263 set_bootloader_message(&boot);
264
265 // Remove the command file, so recovery won't repeat indefinitely.
266 char path[PATH_MAX] = "";
267 if (ensure_root_path_mounted(COMMAND_FILE) != 0 ||
268 translate_root_path(COMMAND_FILE, path, sizeof(path)) == NULL ||
269 (unlink(path) && errno != ENOENT)) {
270 LOGW("Can't unlink %s\n", COMMAND_FILE);
271 }
272
273 sync(); // For good measure.
274}
275
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800276static int
277erase_root(const char *root)
278{
279 ui_set_background(BACKGROUND_ICON_INSTALLING);
280 ui_show_indeterminate_progress();
281 ui_print("Formatting %s...\n", root);
282 return format_root_device(root);
283}
284
Doug Zongkerf93d8162009-09-22 15:16:02 -0700285static char**
286prepend_title(char** headers) {
Koushik K. Dutta261dde92010-02-25 16:51:45 -0800287 char* title[] = { "ClockworkMod Recovery v"
288 EXPAND(RECOVERY_API_VERSION),
Doug Zongkerd6837852009-06-17 22:07:13 -0700289 "",
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800290 NULL };
291
Doug Zongkerd6837852009-06-17 22:07:13 -0700292 // count the number of lines in our title, plus the
Doug Zongkerf93d8162009-09-22 15:16:02 -0700293 // caller-provided headers.
Doug Zongkerd6837852009-06-17 22:07:13 -0700294 int count = 0;
295 char** p;
296 for (p = title; *p; ++p, ++count);
Doug Zongkerf93d8162009-09-22 15:16:02 -0700297 for (p = headers; *p; ++p, ++count);
Doug Zongkerd6837852009-06-17 22:07:13 -0700298
Doug Zongkerf93d8162009-09-22 15:16:02 -0700299 char** new_headers = malloc((count+1) * sizeof(char*));
300 char** h = new_headers;
Doug Zongkerd6837852009-06-17 22:07:13 -0700301 for (p = title; *p; ++p, ++h) *h = *p;
Doug Zongkerf93d8162009-09-22 15:16:02 -0700302 for (p = headers; *p; ++p, ++h) *h = *p;
Doug Zongkerd6837852009-06-17 22:07:13 -0700303 *h = NULL;
304
Doug Zongkerf93d8162009-09-22 15:16:02 -0700305 return new_headers;
306}
307
Koushik K. Duttae9234872010-02-12 00:43:24 -0800308int
Doug Zongkerf93d8162009-09-22 15:16:02 -0700309get_menu_selection(char** headers, char** items, int menu_only) {
310 // throw away keys pressed previously, so user doesn't
311 // accidentally trigger menu items.
312 ui_clear_key_queue();
313
314 ui_start_menu(headers, items);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800315 int selected = 0;
316 int chosen_item = -1;
317
Koushik K. Duttaa3c2f732010-02-19 14:17:22 -0800318 while (chosen_item < 0 && chosen_item != GO_BACK) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800319 int key = ui_wait_key();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800320 int visible = ui_text_visible();
321
Doug Zongkerddd6a282009-06-09 12:22:33 -0700322 int action = device_handle_key(key, visible);
323
324 if (action < 0) {
325 switch (action) {
326 case HIGHLIGHT_UP:
327 --selected;
328 selected = ui_menu_select(selected);
329 break;
330 case HIGHLIGHT_DOWN:
331 ++selected;
332 selected = ui_menu_select(selected);
333 break;
334 case SELECT_ITEM:
335 chosen_item = selected;
336 break;
337 case NO_ACTION:
338 break;
Koushik K. Duttae9234872010-02-12 00:43:24 -0800339 case GO_BACK:
Koushik K. Duttaa3c2f732010-02-19 14:17:22 -0800340 chosen_item = GO_BACK;
341 break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800342 }
Doug Zongkerf93d8162009-09-22 15:16:02 -0700343 } else if (!menu_only) {
Doug Zongkerddd6a282009-06-09 12:22:33 -0700344 chosen_item = action;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800345 }
Doug Zongkerf93d8162009-09-22 15:16:02 -0700346 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800347
Doug Zongkerf93d8162009-09-22 15:16:02 -0700348 ui_end_menu();
Koushik K. Dutta981b0cd2010-02-22 08:53:34 -0800349 ui_clear_key_queue();
Doug Zongkerf93d8162009-09-22 15:16:02 -0700350 return chosen_item;
351}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800352
Doug Zongkerf93d8162009-09-22 15:16:02 -0700353static void
354wipe_data(int confirm) {
355 if (confirm) {
356 static char** title_headers = NULL;
Doug Zongkerddd6a282009-06-09 12:22:33 -0700357
Doug Zongkerf93d8162009-09-22 15:16:02 -0700358 if (title_headers == NULL) {
359 char* headers[] = { "Confirm wipe of all user data?",
360 " THIS CAN NOT BE UNDONE.",
361 "",
362 NULL };
363 title_headers = prepend_title(headers);
364 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800365
Doug Zongkerf93d8162009-09-22 15:16:02 -0700366 char* items[] = { " No",
367 " No",
368 " No",
369 " No",
370 " No",
371 " No",
372 " No",
373 " Yes -- delete all user data", // [7]
374 " No",
375 " No",
376 " No",
377 NULL };
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800378
Doug Zongkerf93d8162009-09-22 15:16:02 -0700379 int chosen_item = get_menu_selection(title_headers, items, 1);
380 if (chosen_item != 7) {
381 return;
382 }
383 }
Doug Zongker1066d2c2009-04-01 13:57:40 -0700384
Doug Zongkerf93d8162009-09-22 15:16:02 -0700385 ui_print("\n-- Wiping data...\n");
386 device_wipe_data();
387 erase_root("DATA:");
388 erase_root("CACHE:");
389 ui_print("Data wipe complete.\n");
390}
391
392static void
393prompt_and_wait()
394{
395 char** headers = prepend_title(MENU_HEADERS);
Koushik K. Dutta261dde92010-02-25 16:51:45 -0800396 ui_print("ClockworkMod Recovery v"EXPAND(RECOVERY_API_VERSION)"\n");
397
Doug Zongkerf93d8162009-09-22 15:16:02 -0700398 for (;;) {
399 finish_recovery(NULL);
400 ui_reset_progress();
401
Koushik K. Duttaa3c2f732010-02-19 14:17:22 -0800402 allow_display_toggle = 1;
Doug Zongkerf93d8162009-09-22 15:16:02 -0700403 int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0);
Koushik K. Duttaa3c2f732010-02-19 14:17:22 -0800404 allow_display_toggle = 0;
Doug Zongkerf93d8162009-09-22 15:16:02 -0700405
406 // device-specific code may take some action here. It may
407 // return one of the core actions handled in the switch
408 // statement below.
409 chosen_item = device_perform_action(chosen_item);
410
411 switch (chosen_item) {
412 case ITEM_REBOOT:
413 return;
414
415 case ITEM_WIPE_DATA:
416 wipe_data(ui_text_visible());
417 if (!ui_text_visible()) return;
418 break;
419
420 case ITEM_WIPE_CACHE:
421 ui_print("\n-- Wiping cache...\n");
422 erase_root("CACHE:");
423 ui_print("Cache wipe complete.\n");
424 if (!ui_text_visible()) return;
425 break;
426
427 case ITEM_APPLY_SDCARD:
428 ui_print("\n-- Install from sdcard...\n");
429 set_sdcard_update_bootloader_message();
430 int status = install_package(SDCARD_PACKAGE_FILE);
431 if (status != INSTALL_SUCCESS) {
432 ui_set_background(BACKGROUND_ICON_ERROR);
433 ui_print("Installation aborted.\n");
434 } else if (!ui_text_visible()) {
435 return; // reboot if logs aren't visible
436 } else {
437 if (firmware_update_pending()) {
Doug Zongkerddd6a282009-06-09 12:22:33 -0700438 ui_print("\nReboot via menu to complete\n"
439 "installation.\n");
Doug Zongkerf93d8162009-09-22 15:16:02 -0700440 } else {
Doug Zongker07e1dca2009-05-28 19:02:45 -0700441 ui_print("\nInstall from sdcard complete.\n");
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800442 }
Doug Zongkerf93d8162009-09-22 15:16:02 -0700443 }
444 break;
Koushik K. Duttae9234872010-02-12 00:43:24 -0800445 case ITEM_INSTALL_ZIP:
Koushik K. Duttabcdd0032010-02-21 21:10:25 -0800446 show_install_update_menu();
447 break;
448 case ITEM_BACKUP:
449 do_nandroid_backup();
450 break;
451 case ITEM_RESTORE:
452 show_nandroid_restore_menu();
Koushik K. Duttae9234872010-02-12 00:43:24 -0800453 break;
Koushik K. Dutta1fa52ec2010-02-21 21:29:10 -0800454 case ITEM_MOUNT_SDCARD:
455 if (ensure_root_path_mounted("SDCARD:") != 0) {
456 LOGE ("Can't mount /sdcard\n");
457 }
458 break;
Koushik K. Dutta03173782010-02-26 14:14:23 -0800459 case ITEM_MOUNT_USB:
460 do_mount_usb_storage();
461 break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800462 }
463 }
464}
465
466static void
467print_property(const char *key, const char *name, void *cookie)
468{
469 fprintf(stderr, "%s=%s\n", key, name);
470}
471
472int
473main(int argc, char **argv)
474{
Koushik K. Dutta99fb6fe2010-03-03 00:42:58 -0800475 if (strstr(argv[0], "recovery") == NULL)
476 {
477 if (strstr(argv[0], "flash_image") != NULL)
478 return flash_image_main(argc, argv);
479 if (strstr(argv[0], "dump_image") != NULL)
480 return dump_image_main(argc, argv);
481 if (strstr(argv[0], "mkyaffs2image") != NULL)
482 return mkyaffs2image_main(argc, argv);
483 if (strstr(argv[0], "unyaffs") != NULL)
484 return unyaffs_main(argc, argv);
Koushik K. Duttaf68aaaf2010-03-07 13:39:21 -0800485 if (strstr(argv[0], "amend"))
486 return amend_main(argc, argv);
Koushik K. Dutta99fb6fe2010-03-03 00:42:58 -0800487 return busybox_driver(argc, argv);
488 }
Koushik K. Dutta03173782010-02-26 14:14:23 -0800489 int is_user_initiated_recovery = 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800490 time_t start = time(NULL);
491
492 // If these fail, there's not really anywhere to complain...
493 freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
494 freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
495 fprintf(stderr, "Starting recovery on %s", ctime(&start));
496
497 ui_init();
498 get_args(&argc, &argv);
499
500 int previous_runs = 0;
501 const char *send_intent = NULL;
502 const char *update_package = NULL;
503 int wipe_data = 0, wipe_cache = 0;
504
505 int arg;
506 while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
507 switch (arg) {
508 case 'p': previous_runs = atoi(optarg); break;
509 case 's': send_intent = optarg; break;
510 case 'u': update_package = optarg; break;
511 case 'w': wipe_data = wipe_cache = 1; break;
512 case 'c': wipe_cache = 1; break;
513 case '?':
514 LOGE("Invalid command argument\n");
515 continue;
516 }
517 }
518
519 fprintf(stderr, "Command:");
520 for (arg = 0; arg < argc; arg++) {
521 fprintf(stderr, " \"%s\"", argv[arg]);
522 }
523 fprintf(stderr, "\n\n");
524
525 property_list(print_property, NULL);
526 fprintf(stderr, "\n");
527
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800528 int status = INSTALL_SUCCESS;
Koushik K. Dutta6060e5c2010-02-11 22:27:06 -0800529
530 RecoveryCommandContext ctx = { NULL };
531 if (register_update_commands(&ctx)) {
532 LOGE("Can't install update commands\n");
533 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800534
535 if (update_package != NULL) {
Chris Soyarsa1749d92010-02-26 02:45:55 -0500536 if (wipe_data && erase_root("DATA:")) status = INSTALL_ERROR;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800537 status = install_package(update_package);
538 if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
Doug Zongkerb128f542009-06-18 15:07:14 -0700539 } else if (wipe_data) {
540 if (device_wipe_data()) status = INSTALL_ERROR;
541 if (erase_root("DATA:")) status = INSTALL_ERROR;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800542 if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR;
543 if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
Doug Zongkerb128f542009-06-18 15:07:14 -0700544 } else if (wipe_cache) {
545 if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR;
546 if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n");
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800547 } else {
548 status = INSTALL_ERROR; // No command specified
Koushik K. Dutta03173782010-02-26 14:14:23 -0800549 // we are starting up in user initiated recovery here
550 // let's set up some default options
551 signature_check_enabled = 0;
Koushik K. Dutta2bda3e92010-03-06 16:40:52 -0800552 script_assert_enabled = 0;
Koushik K. Dutta03173782010-02-26 14:14:23 -0800553 is_user_initiated_recovery = 1;
554 ui_set_show_text(1);
Koushik K. Dutta72a1db62010-03-07 14:10:26 -0800555
556 if (extendedcommand_file_exists())
557 run_and_remove_extendedcommand();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800558 }
559
Koushik K. Dutta03173782010-02-26 14:14:23 -0800560 if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) ui_set_background(BACKGROUND_ICON_ERROR);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800561 if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait();
562
563 // If there is a radio image pending, reboot now to install it.
564 maybe_install_firmware_update(send_intent);
565
566 // Otherwise, get ready to boot the main system...
567 finish_recovery(send_intent);
568 ui_print("Rebooting...\n");
569 sync();
570 reboot(RB_AUTOBOOT);
571 return EXIT_SUCCESS;
572}
Koushik K. Duttaa3c2f732010-02-19 14:17:22 -0800573
574int get_allow_toggle_display() {
575 return allow_display_toggle;
Chris Soyarsa1749d92010-02-26 02:45:55 -0500576}