The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
Shashank Mittal | 815ca5d | 2010-07-27 11:09:19 -0700 | [diff] [blame] | 3 | * Copyright (c) 2010, Code Aurora Forum. All rights reserved. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <ctype.h> |
| 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <getopt.h> |
| 22 | #include <limits.h> |
| 23 | #include <linux/input.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <sys/reboot.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <time.h> |
| 30 | #include <unistd.h> |
Koushik Dutta | 1741dcd | 2010-06-11 00:49:49 -0700 | [diff] [blame] | 31 | #include <sys/stat.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 32 | |
| 33 | #include "bootloader.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | #include "common.h" |
| 35 | #include "cutils/properties.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 36 | #include "install.h" |
| 37 | #include "minui/minui.h" |
| 38 | #include "minzip/DirUtil.h" |
| 39 | #include "roots.h" |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 40 | #include "recovery_ui.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 41 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 42 | #include "extendedcommands.h" |
| 43 | #include "commands.h" |
| 44 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 45 | static const struct option OPTIONS[] = { |
| 46 | { "send_intent", required_argument, NULL, 's' }, |
| 47 | { "update_package", required_argument, NULL, 'u' }, |
| 48 | { "wipe_data", no_argument, NULL, 'w' }, |
| 49 | { "wipe_cache", no_argument, NULL, 'c' }, |
Doug Zongker | 988500b | 2009-10-06 14:41:38 -0700 | [diff] [blame] | 50 | { NULL, 0, NULL, 0 }, |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 53 | static int allow_display_toggle = 1; |
| 54 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 55 | static const char *COMMAND_FILE = "CACHE:recovery/command"; |
| 56 | static const char *INTENT_FILE = "CACHE:recovery/intent"; |
| 57 | static const char *LOG_FILE = "CACHE:recovery/log"; |
| 58 | static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip"; |
| 59 | static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; |
| 60 | |
| 61 | /* |
| 62 | * The recovery tool communicates with the main system through /cache files. |
| 63 | * /cache/recovery/command - INPUT - command line for tool, one arg per line |
| 64 | * /cache/recovery/log - OUTPUT - combined log file from recovery run(s) |
| 65 | * /cache/recovery/intent - OUTPUT - intent that was passed in |
| 66 | * |
| 67 | * The arguments which may be supplied in the recovery.command file: |
| 68 | * --send_intent=anystring - write the text out to recovery.intent |
| 69 | * --update_package=root:path - verify install an OTA package file |
| 70 | * --wipe_data - erase user data (and cache), then reboot |
| 71 | * --wipe_cache - wipe cache (but not user data), then reboot |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 72 | * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 73 | * |
| 74 | * After completing, we remove /cache/recovery/command and reboot. |
| 75 | * Arguments may also be supplied in the bootloader control block (BCB). |
| 76 | * These important scenarios must be safely restartable at any point: |
| 77 | * |
| 78 | * FACTORY RESET |
| 79 | * 1. user selects "factory reset" |
| 80 | * 2. main system writes "--wipe_data" to /cache/recovery/command |
| 81 | * 3. main system reboots into recovery |
| 82 | * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data" |
| 83 | * -- after this, rebooting will restart the erase -- |
| 84 | * 5. erase_root() reformats /data |
| 85 | * 6. erase_root() reformats /cache |
| 86 | * 7. finish_recovery() erases BCB |
| 87 | * -- after this, rebooting will restart the main system -- |
| 88 | * 8. main() calls reboot() to boot main system |
| 89 | * |
| 90 | * OTA INSTALL |
| 91 | * 1. main system downloads OTA package to /cache/some-filename.zip |
| 92 | * 2. main system writes "--update_package=CACHE:some-filename.zip" |
| 93 | * 3. main system reboots into recovery |
| 94 | * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..." |
| 95 | * -- after this, rebooting will attempt to reinstall the update -- |
| 96 | * 5. install_package() attempts to install the update |
| 97 | * NOTE: the package install must itself be restartable from any point |
| 98 | * 6. finish_recovery() erases BCB |
| 99 | * -- after this, rebooting will (try to) restart the main system -- |
| 100 | * 7. ** if install failed ** |
| 101 | * 7a. prompt_and_wait() shows an error icon and waits for the user |
| 102 | * 7b; the user reboots (pulling the battery, etc) into the main system |
| 103 | * 8. main() calls maybe_install_firmware_update() |
| 104 | * ** if the update contained radio/hboot firmware **: |
| 105 | * 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache" |
| 106 | * -- after this, rebooting will reformat cache & restart main system -- |
| 107 | * 8b. m_i_f_u() writes firmware image into raw cache partition |
| 108 | * 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache" |
| 109 | * -- after this, rebooting will attempt to reinstall firmware -- |
| 110 | * 8d. bootloader tries to flash firmware |
| 111 | * 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache") |
| 112 | * -- after this, rebooting will reformat cache & restart main system -- |
| 113 | * 8f. erase_root() reformats /cache |
| 114 | * 8g. finish_recovery() erases BCB |
| 115 | * -- after this, rebooting will (try to) restart the main system -- |
| 116 | * 9. main() calls reboot() to boot main system |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 117 | * |
| 118 | * ENCRYPTED FILE SYSTEMS ENABLE/DISABLE |
| 119 | * 1. user selects "enable encrypted file systems" |
| 120 | * 2. main system writes "--set_encrypted_filesystem=on|off" to |
| 121 | * /cache/recovery/command |
| 122 | * 3. main system reboots into recovery |
| 123 | * 4. get_args() writes BCB with "boot-recovery" and |
| 124 | * "--set_encrypted_filesystems=on|off" |
| 125 | * -- after this, rebooting will restart the transition -- |
| 126 | * 5. read_encrypted_fs_info() retrieves encrypted file systems settings from /data |
| 127 | * Settings include: property to specify the Encrypted FS istatus and |
| 128 | * FS encryption key if enabled (not yet implemented) |
| 129 | * 6. erase_root() reformats /data |
| 130 | * 7. erase_root() reformats /cache |
| 131 | * 8. restore_encrypted_fs_info() writes required encrypted file systems settings to /data |
| 132 | * Settings include: property to specify the Encrypted FS status and |
| 133 | * FS encryption key if enabled (not yet implemented) |
| 134 | * 9. finish_recovery() erases BCB |
| 135 | * -- after this, rebooting will restart the main system -- |
| 136 | * 10. main() calls reboot() to boot main system |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 137 | */ |
| 138 | |
| 139 | static const int MAX_ARG_LENGTH = 4096; |
| 140 | static const int MAX_ARGS = 100; |
| 141 | |
| 142 | // open a file given in root:path format, mounting partitions as necessary |
| 143 | static FILE* |
| 144 | fopen_root_path(const char *root_path, const char *mode) { |
| 145 | if (ensure_root_path_mounted(root_path) != 0) { |
| 146 | LOGE("Can't mount %s\n", root_path); |
| 147 | return NULL; |
| 148 | } |
| 149 | |
| 150 | char path[PATH_MAX] = ""; |
| 151 | if (translate_root_path(root_path, path, sizeof(path)) == NULL) { |
| 152 | LOGE("Bad path %s\n", root_path); |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | // When writing, try to create the containing directory, if necessary. |
| 157 | // Use generous permissions, the system (init.rc) will reset them. |
| 158 | if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1); |
| 159 | |
| 160 | FILE *fp = fopen(path, mode); |
Koushik K. Dutta | 261dde9 | 2010-02-25 16:51:45 -0800 | [diff] [blame] | 161 | if (fp == NULL && root_path != COMMAND_FILE) LOGE("Can't open %s\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 162 | return fp; |
| 163 | } |
| 164 | |
| 165 | // close a file, log an error if the error indicator is set |
| 166 | static void |
| 167 | check_and_fclose(FILE *fp, const char *name) { |
| 168 | fflush(fp); |
| 169 | if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno)); |
| 170 | fclose(fp); |
| 171 | } |
| 172 | |
| 173 | // command line args come from, in decreasing precedence: |
| 174 | // - the actual command line |
| 175 | // - the bootloader control block (one per line, after "recovery") |
| 176 | // - the contents of COMMAND_FILE (one per line) |
| 177 | static void |
| 178 | get_args(int *argc, char ***argv) { |
| 179 | struct bootloader_message boot; |
| 180 | memset(&boot, 0, sizeof(boot)); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 181 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 182 | get_bootloader_message(&boot); // this may fail, leaving a zeroed structure |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 183 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 184 | |
| 185 | if (boot.command[0] != 0 && boot.command[0] != 255) { |
| 186 | LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command); |
| 187 | } |
| 188 | |
| 189 | if (boot.status[0] != 0 && boot.status[0] != 255) { |
| 190 | LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status); |
| 191 | } |
| 192 | |
Koushik Dutta | 1741dcd | 2010-06-11 00:49:49 -0700 | [diff] [blame] | 193 | struct stat file_info; |
| 194 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 195 | // --- if arguments weren't supplied, look in the bootloader control block |
Koushik Dutta | 1741dcd | 2010-06-11 00:49:49 -0700 | [diff] [blame] | 196 | if (*argc <= 1 && 0 != stat("/tmp/.ignorebootmessage", &file_info)) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 197 | boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination |
| 198 | const char *arg = strtok(boot.recovery, "\n"); |
| 199 | if (arg != NULL && !strcmp(arg, "recovery")) { |
| 200 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 201 | (*argv)[0] = strdup(arg); |
| 202 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 203 | if ((arg = strtok(NULL, "\n")) == NULL) break; |
| 204 | (*argv)[*argc] = strdup(arg); |
| 205 | } |
| 206 | LOGI("Got arguments from boot message\n"); |
| 207 | } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) { |
| 208 | LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // --- if that doesn't work, try the command file |
| 213 | if (*argc <= 1) { |
| 214 | FILE *fp = fopen_root_path(COMMAND_FILE, "r"); |
| 215 | if (fp != NULL) { |
| 216 | char *argv0 = (*argv)[0]; |
| 217 | *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); |
| 218 | (*argv)[0] = argv0; // use the same program name |
| 219 | |
| 220 | char buf[MAX_ARG_LENGTH]; |
| 221 | for (*argc = 1; *argc < MAX_ARGS; ++*argc) { |
| 222 | if (!fgets(buf, sizeof(buf), fp)) break; |
| 223 | (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline. |
| 224 | } |
| 225 | |
| 226 | check_and_fclose(fp, COMMAND_FILE); |
| 227 | LOGI("Got arguments from %s\n", COMMAND_FILE); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // --> write the arguments we have back into the bootloader control block |
| 232 | // always boot into recovery after this (until finish_recovery() is called) |
| 233 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 234 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 235 | int i; |
| 236 | for (i = 1; i < *argc; ++i) { |
| 237 | strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); |
| 238 | strlcat(boot.recovery, "\n", sizeof(boot.recovery)); |
| 239 | } |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 240 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 241 | set_bootloader_message(&boot); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 242 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 245 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 246 | void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 247 | set_sdcard_update_bootloader_message() { |
Doug Zongker | 34c98df | 2009-08-18 12:05:45 -0700 | [diff] [blame] | 248 | struct bootloader_message boot; |
| 249 | memset(&boot, 0, sizeof(boot)); |
| 250 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 251 | strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); |
| 252 | set_bootloader_message(&boot); |
| 253 | } |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 254 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 255 | |
| 256 | // clear the recovery command and prepare to boot a (hopefully working) system, |
| 257 | // copy our log file to cache as well (for the system to read), and |
| 258 | // record any intent we were asked to communicate back to the system. |
| 259 | // this function is idempotent: call it as many times as you like. |
| 260 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 261 | finish_recovery(const char *send_intent) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 262 | // By this point, we're ready to return to the main system... |
| 263 | if (send_intent != NULL) { |
| 264 | FILE *fp = fopen_root_path(INTENT_FILE, "w"); |
Jay Freeman (saurik) | 619ec2f | 2008-11-17 01:56:05 +0000 | [diff] [blame] | 265 | if (fp == NULL) { |
| 266 | LOGE("Can't open %s\n", INTENT_FILE); |
| 267 | } else { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 268 | fputs(send_intent, fp); |
| 269 | check_and_fclose(fp, INTENT_FILE); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // Copy logs to cache so the system can find out what happened. |
| 274 | FILE *log = fopen_root_path(LOG_FILE, "a"); |
Jay Freeman (saurik) | 619ec2f | 2008-11-17 01:56:05 +0000 | [diff] [blame] | 275 | if (log == NULL) { |
| 276 | LOGE("Can't open %s\n", LOG_FILE); |
| 277 | } else { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 278 | FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r"); |
| 279 | if (tmplog == NULL) { |
| 280 | LOGE("Can't open %s\n", TEMPORARY_LOG_FILE); |
| 281 | } else { |
| 282 | static long tmplog_offset = 0; |
| 283 | fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write |
| 284 | char buf[4096]; |
| 285 | while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log); |
| 286 | tmplog_offset = ftell(tmplog); |
| 287 | check_and_fclose(tmplog, TEMPORARY_LOG_FILE); |
| 288 | } |
| 289 | check_and_fclose(log, LOG_FILE); |
| 290 | } |
| 291 | |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 292 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 293 | // Reset to mormal system boot so recovery won't cycle indefinitely. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 294 | struct bootloader_message boot; |
| 295 | memset(&boot, 0, sizeof(boot)); |
| 296 | set_bootloader_message(&boot); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 297 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 298 | |
| 299 | // Remove the command file, so recovery won't repeat indefinitely. |
| 300 | char path[PATH_MAX] = ""; |
| 301 | if (ensure_root_path_mounted(COMMAND_FILE) != 0 || |
| 302 | translate_root_path(COMMAND_FILE, path, sizeof(path)) == NULL || |
| 303 | (unlink(path) && errno != ENOENT)) { |
| 304 | LOGW("Can't unlink %s\n", COMMAND_FILE); |
| 305 | } |
| 306 | |
| 307 | sync(); // For good measure. |
| 308 | } |
| 309 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 310 | static int |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 311 | erase_root(const char *root) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 312 | ui_set_background(BACKGROUND_ICON_INSTALLING); |
| 313 | ui_show_indeterminate_progress(); |
| 314 | ui_print("Formatting %s...\n", root); |
| 315 | return format_root_device(root); |
| 316 | } |
| 317 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 318 | static char** |
| 319 | prepend_title(char** headers) { |
Koushik K. Dutta | 581bd86 | 2010-03-20 01:08:55 -0700 | [diff] [blame] | 320 | char* title[] = { EXPAND(RECOVERY_VERSION), |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 321 | "", |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 322 | NULL }; |
| 323 | |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 324 | // count the number of lines in our title, plus the |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 325 | // caller-provided headers. |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 326 | int count = 0; |
| 327 | char** p; |
| 328 | for (p = title; *p; ++p, ++count); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 329 | for (p = headers; *p; ++p, ++count); |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 330 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 331 | char** new_headers = malloc((count+1) * sizeof(char*)); |
| 332 | char** h = new_headers; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 333 | for (p = title; *p; ++p, ++h) *h = *p; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 334 | for (p = headers; *p; ++p, ++h) *h = *p; |
Doug Zongker | d683785 | 2009-06-17 22:07:13 -0700 | [diff] [blame] | 335 | *h = NULL; |
| 336 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 337 | return new_headers; |
| 338 | } |
| 339 | |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 340 | int |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 341 | get_menu_selection(char** headers, char** items, int menu_only) { |
| 342 | // throw away keys pressed previously, so user doesn't |
| 343 | // accidentally trigger menu items. |
| 344 | ui_clear_key_queue(); |
| 345 | |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 346 | int item_count = ui_start_menu(headers, items); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 347 | int selected = 0; |
| 348 | int chosen_item = -1; |
| 349 | |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 350 | // Some users with dead enter keys need a way to turn on power to select. |
| 351 | // Jiggering across the wrapping menu is one "secret" way to enable it. |
| 352 | // We can't rely on /cache or /sdcard since they may not be available. |
| 353 | int wrap_count = 0; |
| 354 | |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 355 | while (chosen_item < 0 && chosen_item != GO_BACK) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 356 | int key = ui_wait_key(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 357 | int visible = ui_text_visible(); |
| 358 | |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 359 | int action = device_handle_key(key, visible); |
| 360 | |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 361 | int old_selected = selected; |
| 362 | |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 363 | if (action < 0) { |
| 364 | switch (action) { |
| 365 | case HIGHLIGHT_UP: |
| 366 | --selected; |
| 367 | selected = ui_menu_select(selected); |
| 368 | break; |
| 369 | case HIGHLIGHT_DOWN: |
| 370 | ++selected; |
| 371 | selected = ui_menu_select(selected); |
| 372 | break; |
| 373 | case SELECT_ITEM: |
| 374 | chosen_item = selected; |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 375 | if (ui_get_showing_back_button()) { |
| 376 | if (chosen_item == item_count) { |
| 377 | chosen_item = GO_BACK; |
| 378 | } |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 379 | } |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 380 | break; |
| 381 | case NO_ACTION: |
| 382 | break; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 383 | case GO_BACK: |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 384 | chosen_item = GO_BACK; |
| 385 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 386 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 387 | } else if (!menu_only) { |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 388 | chosen_item = action; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 389 | } |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 390 | |
| 391 | if (abs(selected - old_selected) > 1) { |
| 392 | wrap_count++; |
| 393 | if (wrap_count == 3) { |
| 394 | wrap_count = 0; |
| 395 | if (ui_get_showing_back_button()) { |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 396 | ui_print("Back menu button disabled.\n"); |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 397 | ui_set_showing_back_button(0); |
| 398 | } |
| 399 | else { |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 400 | ui_print("Back menu button enabled.\n"); |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 401 | ui_set_showing_back_button(1); |
| 402 | } |
| 403 | } |
| 404 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 405 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 406 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 407 | ui_end_menu(); |
Koushik K. Dutta | 981b0cd | 2010-02-22 08:53:34 -0800 | [diff] [blame] | 408 | ui_clear_key_queue(); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 409 | return chosen_item; |
| 410 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 411 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 412 | static void |
| 413 | wipe_data(int confirm) { |
| 414 | if (confirm) { |
| 415 | static char** title_headers = NULL; |
Doug Zongker | ddd6a28 | 2009-06-09 12:22:33 -0700 | [diff] [blame] | 416 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 417 | if (title_headers == NULL) { |
| 418 | char* headers[] = { "Confirm wipe of all user data?", |
| 419 | " THIS CAN NOT BE UNDONE.", |
| 420 | "", |
| 421 | NULL }; |
| 422 | title_headers = prepend_title(headers); |
| 423 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 424 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 425 | char* items[] = { " No", |
| 426 | " No", |
| 427 | " No", |
| 428 | " No", |
| 429 | " No", |
| 430 | " No", |
| 431 | " No", |
| 432 | " Yes -- delete all user data", // [7] |
| 433 | " No", |
| 434 | " No", |
| 435 | " No", |
| 436 | NULL }; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 437 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 438 | int chosen_item = get_menu_selection(title_headers, items, 1); |
| 439 | if (chosen_item != 7) { |
| 440 | return; |
| 441 | } |
| 442 | } |
Doug Zongker | 1066d2c | 2009-04-01 13:57:40 -0700 | [diff] [blame] | 443 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 444 | ui_print("\n-- Wiping data...\n"); |
| 445 | device_wipe_data(); |
| 446 | erase_root("DATA:"); |
Koushik Dutta | 63e0476 | 2010-06-15 12:56:17 -0700 | [diff] [blame] | 447 | #ifdef HAS_DATADATA |
| 448 | erase_root("DATADATA:"); |
| 449 | #endif |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 450 | erase_root("CACHE:"); |
Koushik Dutta | 2f73e58 | 2010-04-18 16:00:21 -0700 | [diff] [blame] | 451 | erase_root("SDEXT:"); |
Koushik Dutta | 82c2ca2 | 2010-07-03 13:54:21 -0700 | [diff] [blame] | 452 | erase_root("SDCARD:/.android_secure"); |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 453 | ui_print("Data wipe complete.\n"); |
| 454 | } |
| 455 | |
| 456 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 457 | prompt_and_wait() { |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 458 | char** headers = prepend_title(MENU_HEADERS); |
Koushik K. Dutta | 261dde9 | 2010-02-25 16:51:45 -0800 | [diff] [blame] | 459 | |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 460 | for (;;) { |
| 461 | finish_recovery(NULL); |
| 462 | ui_reset_progress(); |
| 463 | |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 464 | allow_display_toggle = 1; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 465 | int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0); |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 466 | allow_display_toggle = 0; |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 467 | |
| 468 | // device-specific code may take some action here. It may |
| 469 | // return one of the core actions handled in the switch |
| 470 | // statement below. |
| 471 | chosen_item = device_perform_action(chosen_item); |
| 472 | |
| 473 | switch (chosen_item) { |
| 474 | case ITEM_REBOOT: |
| 475 | return; |
| 476 | |
| 477 | case ITEM_WIPE_DATA: |
| 478 | wipe_data(ui_text_visible()); |
| 479 | if (!ui_text_visible()) return; |
| 480 | break; |
| 481 | |
| 482 | case ITEM_WIPE_CACHE: |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 483 | if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache")) |
| 484 | { |
| 485 | ui_print("\n-- Wiping cache...\n"); |
| 486 | erase_root("CACHE:"); |
| 487 | ui_print("Cache wipe complete.\n"); |
| 488 | if (!ui_text_visible()) return; |
| 489 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 490 | break; |
| 491 | |
| 492 | case ITEM_APPLY_SDCARD: |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 493 | if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip")) |
| 494 | { |
| 495 | ui_print("\n-- Install from sdcard...\n"); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 496 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 497 | set_sdcard_update_bootloader_message(); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 498 | #endif |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 499 | int status = install_package(SDCARD_PACKAGE_FILE); |
| 500 | if (status != INSTALL_SUCCESS) { |
| 501 | ui_set_background(BACKGROUND_ICON_ERROR); |
| 502 | ui_print("Installation aborted.\n"); |
| 503 | } else if (!ui_text_visible()) { |
| 504 | return; // reboot if logs aren't visible |
| 505 | } else { |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 506 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
Koushik Dutta | d63eaef | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 507 | if (firmware_update_pending()) { |
| 508 | ui_print("\nReboot via menu to complete\n" |
| 509 | "installation.\n"); |
| 510 | } else { |
| 511 | ui_print("\nInstall from sdcard complete.\n"); |
| 512 | } |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 513 | #else |
Koushik Dutta | 9565424 | 2010-07-14 21:01:21 -0700 | [diff] [blame] | 514 | ui_print("\nInstall from sdcard complete.\n"); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 515 | #endif |
Koushik Dutta | ef83d3e | 2010-07-19 08:54:23 -0700 | [diff] [blame] | 516 | } |
Doug Zongker | f93d816 | 2009-09-22 15:16:02 -0700 | [diff] [blame] | 517 | } |
| 518 | break; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 519 | case ITEM_INSTALL_ZIP: |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 520 | show_install_update_menu(); |
| 521 | break; |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 522 | case ITEM_NANDROID: |
| 523 | show_nandroid_menu(); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 524 | break; |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 525 | case ITEM_PARTITION: |
| 526 | show_partition_menu(); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 527 | break; |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 528 | case ITEM_ADVANCED: |
| 529 | show_advanced_menu(); |
Koushik K. Dutta | 1fa52ec | 2010-02-21 21:29:10 -0800 | [diff] [blame] | 530 | break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static void |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 536 | print_property(const char *key, const char *name, void *cookie) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 537 | fprintf(stderr, "%s=%s\n", key, name); |
| 538 | } |
| 539 | |
| 540 | int |
Oscar Montemayor | 0523156 | 2009-11-30 08:40:57 -0800 | [diff] [blame] | 541 | main(int argc, char **argv) { |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 542 | if (strstr(argv[0], "recovery") == NULL) |
| 543 | { |
| 544 | if (strstr(argv[0], "flash_image") != NULL) |
| 545 | return flash_image_main(argc, argv); |
| 546 | if (strstr(argv[0], "dump_image") != NULL) |
| 547 | return dump_image_main(argc, argv); |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 548 | if (strstr(argv[0], "erase_image") != NULL) |
| 549 | return erase_image_main(argc, argv); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 550 | if (strstr(argv[0], "mkyaffs2image") != NULL) |
| 551 | return mkyaffs2image_main(argc, argv); |
| 552 | if (strstr(argv[0], "unyaffs") != NULL) |
| 553 | return unyaffs_main(argc, argv); |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 554 | if (strstr(argv[0], "amend")) |
| 555 | return amend_main(argc, argv); |
Koushik Dutta | d3cc60b | 2010-07-03 13:56:45 -0700 | [diff] [blame] | 556 | if (strstr(argv[0], "nandroid")) |
| 557 | return nandroid_main(argc, argv); |
Koushik Dutta | 852bb42 | 2010-07-24 11:18:00 -0700 | [diff] [blame] | 558 | if (strstr(argv[0], "reboot")) |
| 559 | return reboot_main(argc, argv); |
| 560 | if (strstr(argv[0], "setprop")) |
| 561 | return setprop_main(argc, argv); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 562 | return busybox_driver(argc, argv); |
| 563 | } |
Koushik Dutta | f8b21c2 | 2010-06-14 12:49:47 -0700 | [diff] [blame] | 564 | __system("/sbin/postrecoveryboot.sh"); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 565 | create_fstab(); |
Koushik Dutta | fd1579b | 2010-05-01 12:46:55 -0700 | [diff] [blame] | 566 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 567 | int is_user_initiated_recovery = 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 568 | time_t start = time(NULL); |
| 569 | |
| 570 | // If these fail, there's not really anywhere to complain... |
| 571 | freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); |
| 572 | freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); |
| 573 | fprintf(stderr, "Starting recovery on %s", ctime(&start)); |
| 574 | |
| 575 | ui_init(); |
Koushik Dutta | fdda0d6 | 2010-07-01 12:52:34 -0700 | [diff] [blame] | 576 | ui_print(EXPAND(RECOVERY_VERSION)"\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 577 | get_args(&argc, &argv); |
| 578 | |
| 579 | int previous_runs = 0; |
| 580 | const char *send_intent = NULL; |
| 581 | const char *update_package = NULL; |
| 582 | int wipe_data = 0, wipe_cache = 0; |
| 583 | |
| 584 | int arg; |
| 585 | while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { |
| 586 | switch (arg) { |
| 587 | case 'p': previous_runs = atoi(optarg); break; |
| 588 | case 's': send_intent = optarg; break; |
| 589 | case 'u': update_package = optarg; break; |
| 590 | case 'w': wipe_data = wipe_cache = 1; break; |
| 591 | case 'c': wipe_cache = 1; break; |
| 592 | case '?': |
| 593 | LOGE("Invalid command argument\n"); |
| 594 | continue; |
| 595 | } |
| 596 | } |
| 597 | |
Doug Zongker | efa1bab | 2010-02-01 15:59:12 -0800 | [diff] [blame] | 598 | device_recovery_start(); |
| 599 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 600 | fprintf(stderr, "Command:"); |
| 601 | for (arg = 0; arg < argc; arg++) { |
| 602 | fprintf(stderr, " \"%s\"", argv[arg]); |
| 603 | } |
| 604 | fprintf(stderr, "\n\n"); |
| 605 | |
| 606 | property_list(print_property, NULL); |
| 607 | fprintf(stderr, "\n"); |
| 608 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 609 | int status = INSTALL_SUCCESS; |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 610 | |
| 611 | RecoveryCommandContext ctx = { NULL }; |
| 612 | if (register_update_commands(&ctx)) { |
| 613 | LOGE("Can't install update commands\n"); |
| 614 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 615 | |
| 616 | if (update_package != NULL) { |
Chris Soyars | a1749d9 | 2010-02-26 02:45:55 -0500 | [diff] [blame] | 617 | if (wipe_data && erase_root("DATA:")) status = INSTALL_ERROR; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 618 | status = install_package(update_package); |
| 619 | if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 620 | } else if (wipe_data) { |
| 621 | if (device_wipe_data()) status = INSTALL_ERROR; |
| 622 | if (erase_root("DATA:")) status = INSTALL_ERROR; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 623 | if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; |
| 624 | if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n"); |
Doug Zongker | b128f54 | 2009-06-18 15:07:14 -0700 | [diff] [blame] | 625 | } else if (wipe_cache) { |
| 626 | if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR; |
| 627 | if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 628 | } else { |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 629 | LOGI("Checking for extendedcommand...\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 630 | status = INSTALL_ERROR; // No command specified |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 631 | // we are starting up in user initiated recovery here |
| 632 | // let's set up some default options |
| 633 | signature_check_enabled = 0; |
Koushik K. Dutta | 2bda3e9 | 2010-03-06 16:40:52 -0800 | [diff] [blame] | 634 | script_assert_enabled = 0; |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 635 | is_user_initiated_recovery = 1; |
| 636 | ui_set_show_text(1); |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 637 | |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 638 | if (extendedcommand_file_exists()) { |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 639 | LOGI("Running extendedcommand...\n"); |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 640 | int ret; |
| 641 | if (0 == (ret = run_and_remove_extendedcommand())) { |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 642 | status = INSTALL_SUCCESS; |
Koushik K. Dutta | 13d8fcc | 2010-03-07 14:15:14 -0800 | [diff] [blame] | 643 | ui_set_show_text(0); |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 644 | } |
Koushik Dutta | 598cfc7 | 2010-06-20 09:42:47 -0700 | [diff] [blame] | 645 | else { |
| 646 | handle_failure(ret); |
| 647 | } |
Koushik Dutta | f4e3a67 | 2010-06-09 12:19:41 -0700 | [diff] [blame] | 648 | } else { |
| 649 | LOGI("Skipping execution of extendedcommand, file not found...\n"); |
Koushik K. Dutta | 32e4111 | 2010-03-07 14:11:56 -0800 | [diff] [blame] | 650 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 653 | if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) ui_set_background(BACKGROUND_ICON_ERROR); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 654 | if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait(); |
| 655 | |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 656 | #ifndef BOARD_HAS_NO_MISC_PARTITION |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 657 | // If there is a radio image pending, reboot now to install it. |
| 658 | maybe_install_firmware_update(send_intent); |
Koushik Dutta | 5aaa823 | 2010-07-20 16:23:18 -0700 | [diff] [blame] | 659 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 660 | |
| 661 | // Otherwise, get ready to boot the main system... |
| 662 | finish_recovery(send_intent); |
| 663 | ui_print("Rebooting...\n"); |
| 664 | sync(); |
| 665 | reboot(RB_AUTOBOOT); |
| 666 | return EXIT_SUCCESS; |
| 667 | } |
Koushik K. Dutta | a3c2f73 | 2010-02-19 14:17:22 -0800 | [diff] [blame] | 668 | |
| 669 | int get_allow_toggle_display() { |
| 670 | return allow_display_toggle; |
Chris Soyars | a1749d9 | 2010-02-26 02:45:55 -0500 | [diff] [blame] | 671 | } |