2009-03-04 03:28:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2010-06-11 07:49:49 +00:00
|
|
|
#include <sys/stat.h>
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
#include "bootloader.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "cutils/properties.h"
|
|
|
|
#include "install.h"
|
|
|
|
#include "minui/minui.h"
|
|
|
|
#include "minzip/DirUtil.h"
|
|
|
|
#include "roots.h"
|
2009-06-09 19:22:33 +00:00
|
|
|
#include "recovery_ui.h"
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2010-02-12 06:27:06 +00:00
|
|
|
#include "extendedcommands.h"
|
|
|
|
#include "commands.h"
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
static const struct option OPTIONS[] = {
|
|
|
|
{ "send_intent", required_argument, NULL, 's' },
|
|
|
|
{ "update_package", required_argument, NULL, 'u' },
|
|
|
|
{ "wipe_data", no_argument, NULL, 'w' },
|
|
|
|
{ "wipe_cache", no_argument, NULL, 'c' },
|
2009-10-06 21:41:38 +00:00
|
|
|
{ NULL, 0, NULL, 0 },
|
2009-03-04 03:28:42 +00:00
|
|
|
};
|
|
|
|
|
2010-02-19 22:17:22 +00:00
|
|
|
static int allow_display_toggle = 1;
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
static const char *COMMAND_FILE = "CACHE:recovery/command";
|
|
|
|
static const char *INTENT_FILE = "CACHE:recovery/intent";
|
|
|
|
static const char *LOG_FILE = "CACHE:recovery/log";
|
|
|
|
static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip";
|
|
|
|
static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The recovery tool communicates with the main system through /cache files.
|
|
|
|
* /cache/recovery/command - INPUT - command line for tool, one arg per line
|
|
|
|
* /cache/recovery/log - OUTPUT - combined log file from recovery run(s)
|
|
|
|
* /cache/recovery/intent - OUTPUT - intent that was passed in
|
|
|
|
*
|
|
|
|
* The arguments which may be supplied in the recovery.command file:
|
|
|
|
* --send_intent=anystring - write the text out to recovery.intent
|
|
|
|
* --update_package=root:path - verify install an OTA package file
|
|
|
|
* --wipe_data - erase user data (and cache), then reboot
|
|
|
|
* --wipe_cache - wipe cache (but not user data), then reboot
|
2009-11-30 16:40:57 +00:00
|
|
|
* --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
|
2009-03-04 03:28:42 +00:00
|
|
|
*
|
|
|
|
* After completing, we remove /cache/recovery/command and reboot.
|
|
|
|
* Arguments may also be supplied in the bootloader control block (BCB).
|
|
|
|
* These important scenarios must be safely restartable at any point:
|
|
|
|
*
|
|
|
|
* FACTORY RESET
|
|
|
|
* 1. user selects "factory reset"
|
|
|
|
* 2. main system writes "--wipe_data" to /cache/recovery/command
|
|
|
|
* 3. main system reboots into recovery
|
|
|
|
* 4. get_args() writes BCB with "boot-recovery" and "--wipe_data"
|
|
|
|
* -- after this, rebooting will restart the erase --
|
|
|
|
* 5. erase_root() reformats /data
|
|
|
|
* 6. erase_root() reformats /cache
|
|
|
|
* 7. finish_recovery() erases BCB
|
|
|
|
* -- after this, rebooting will restart the main system --
|
|
|
|
* 8. main() calls reboot() to boot main system
|
|
|
|
*
|
|
|
|
* OTA INSTALL
|
|
|
|
* 1. main system downloads OTA package to /cache/some-filename.zip
|
|
|
|
* 2. main system writes "--update_package=CACHE:some-filename.zip"
|
|
|
|
* 3. main system reboots into recovery
|
|
|
|
* 4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
|
|
|
|
* -- after this, rebooting will attempt to reinstall the update --
|
|
|
|
* 5. install_package() attempts to install the update
|
|
|
|
* NOTE: the package install must itself be restartable from any point
|
|
|
|
* 6. finish_recovery() erases BCB
|
|
|
|
* -- after this, rebooting will (try to) restart the main system --
|
|
|
|
* 7. ** if install failed **
|
|
|
|
* 7a. prompt_and_wait() shows an error icon and waits for the user
|
|
|
|
* 7b; the user reboots (pulling the battery, etc) into the main system
|
|
|
|
* 8. main() calls maybe_install_firmware_update()
|
|
|
|
* ** if the update contained radio/hboot firmware **:
|
|
|
|
* 8a. m_i_f_u() writes BCB with "boot-recovery" and "--wipe_cache"
|
|
|
|
* -- after this, rebooting will reformat cache & restart main system --
|
|
|
|
* 8b. m_i_f_u() writes firmware image into raw cache partition
|
|
|
|
* 8c. m_i_f_u() writes BCB with "update-radio/hboot" and "--wipe_cache"
|
|
|
|
* -- after this, rebooting will attempt to reinstall firmware --
|
|
|
|
* 8d. bootloader tries to flash firmware
|
|
|
|
* 8e. bootloader writes BCB with "boot-recovery" (keeping "--wipe_cache")
|
|
|
|
* -- after this, rebooting will reformat cache & restart main system --
|
|
|
|
* 8f. erase_root() reformats /cache
|
|
|
|
* 8g. finish_recovery() erases BCB
|
|
|
|
* -- after this, rebooting will (try to) restart the main system --
|
|
|
|
* 9. main() calls reboot() to boot main system
|
2009-11-30 16:40:57 +00:00
|
|
|
*
|
|
|
|
* ENCRYPTED FILE SYSTEMS ENABLE/DISABLE
|
|
|
|
* 1. user selects "enable encrypted file systems"
|
|
|
|
* 2. main system writes "--set_encrypted_filesystem=on|off" to
|
|
|
|
* /cache/recovery/command
|
|
|
|
* 3. main system reboots into recovery
|
|
|
|
* 4. get_args() writes BCB with "boot-recovery" and
|
|
|
|
* "--set_encrypted_filesystems=on|off"
|
|
|
|
* -- after this, rebooting will restart the transition --
|
|
|
|
* 5. read_encrypted_fs_info() retrieves encrypted file systems settings from /data
|
|
|
|
* Settings include: property to specify the Encrypted FS istatus and
|
|
|
|
* FS encryption key if enabled (not yet implemented)
|
|
|
|
* 6. erase_root() reformats /data
|
|
|
|
* 7. erase_root() reformats /cache
|
|
|
|
* 8. restore_encrypted_fs_info() writes required encrypted file systems settings to /data
|
|
|
|
* Settings include: property to specify the Encrypted FS status and
|
|
|
|
* FS encryption key if enabled (not yet implemented)
|
|
|
|
* 9. finish_recovery() erases BCB
|
|
|
|
* -- after this, rebooting will restart the main system --
|
|
|
|
* 10. main() calls reboot() to boot main system
|
2009-03-04 03:28:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const int MAX_ARG_LENGTH = 4096;
|
|
|
|
static const int MAX_ARGS = 100;
|
|
|
|
|
|
|
|
// open a file given in root:path format, mounting partitions as necessary
|
|
|
|
static FILE*
|
|
|
|
fopen_root_path(const char *root_path, const char *mode) {
|
|
|
|
if (ensure_root_path_mounted(root_path) != 0) {
|
|
|
|
LOGE("Can't mount %s\n", root_path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
if (translate_root_path(root_path, path, sizeof(path)) == NULL) {
|
|
|
|
LOGE("Bad path %s\n", root_path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When writing, try to create the containing directory, if necessary.
|
|
|
|
// Use generous permissions, the system (init.rc) will reset them.
|
|
|
|
if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1);
|
|
|
|
|
|
|
|
FILE *fp = fopen(path, mode);
|
2010-02-26 00:51:45 +00:00
|
|
|
if (fp == NULL && root_path != COMMAND_FILE) LOGE("Can't open %s\n", path);
|
2009-03-04 03:28:42 +00:00
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// close a file, log an error if the error indicator is set
|
|
|
|
static void
|
|
|
|
check_and_fclose(FILE *fp, const char *name) {
|
|
|
|
fflush(fp);
|
|
|
|
if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno));
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// command line args come from, in decreasing precedence:
|
|
|
|
// - the actual command line
|
|
|
|
// - the bootloader control block (one per line, after "recovery")
|
|
|
|
// - the contents of COMMAND_FILE (one per line)
|
|
|
|
static void
|
|
|
|
get_args(int *argc, char ***argv) {
|
|
|
|
struct bootloader_message boot;
|
|
|
|
memset(&boot, 0, sizeof(boot));
|
|
|
|
get_bootloader_message(&boot); // this may fail, leaving a zeroed structure
|
|
|
|
|
|
|
|
if (boot.command[0] != 0 && boot.command[0] != 255) {
|
|
|
|
LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boot.status[0] != 0 && boot.status[0] != 255) {
|
|
|
|
LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status);
|
|
|
|
}
|
|
|
|
|
2010-06-11 07:49:49 +00:00
|
|
|
struct stat file_info;
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
// --- if arguments weren't supplied, look in the bootloader control block
|
2010-06-11 07:49:49 +00:00
|
|
|
if (*argc <= 1 && 0 != stat("/tmp/.ignorebootmessage", &file_info)) {
|
2009-03-04 03:28:42 +00:00
|
|
|
boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination
|
|
|
|
const char *arg = strtok(boot.recovery, "\n");
|
|
|
|
if (arg != NULL && !strcmp(arg, "recovery")) {
|
|
|
|
*argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
|
|
|
|
(*argv)[0] = strdup(arg);
|
|
|
|
for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
|
|
|
|
if ((arg = strtok(NULL, "\n")) == NULL) break;
|
|
|
|
(*argv)[*argc] = strdup(arg);
|
|
|
|
}
|
|
|
|
LOGI("Got arguments from boot message\n");
|
|
|
|
} else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) {
|
|
|
|
LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- if that doesn't work, try the command file
|
|
|
|
if (*argc <= 1) {
|
|
|
|
FILE *fp = fopen_root_path(COMMAND_FILE, "r");
|
|
|
|
if (fp != NULL) {
|
|
|
|
char *argv0 = (*argv)[0];
|
|
|
|
*argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
|
|
|
|
(*argv)[0] = argv0; // use the same program name
|
|
|
|
|
|
|
|
char buf[MAX_ARG_LENGTH];
|
|
|
|
for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
|
|
|
|
if (!fgets(buf, sizeof(buf), fp)) break;
|
|
|
|
(*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline.
|
|
|
|
}
|
|
|
|
|
|
|
|
check_and_fclose(fp, COMMAND_FILE);
|
|
|
|
LOGI("Got arguments from %s\n", COMMAND_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --> write the arguments we have back into the bootloader control block
|
|
|
|
// always boot into recovery after this (until finish_recovery() is called)
|
|
|
|
strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
|
|
|
|
strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < *argc; ++i) {
|
|
|
|
strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery));
|
|
|
|
strlcat(boot.recovery, "\n", sizeof(boot.recovery));
|
|
|
|
}
|
|
|
|
set_bootloader_message(&boot);
|
|
|
|
}
|
|
|
|
|
2010-02-12 08:43:24 +00:00
|
|
|
void
|
2009-11-30 16:40:57 +00:00
|
|
|
set_sdcard_update_bootloader_message() {
|
2009-08-18 19:05:45 +00:00
|
|
|
struct bootloader_message boot;
|
|
|
|
memset(&boot, 0, sizeof(boot));
|
|
|
|
strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
|
|
|
|
strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
|
|
|
|
set_bootloader_message(&boot);
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
// clear the recovery command and prepare to boot a (hopefully working) system,
|
|
|
|
// copy our log file to cache as well (for the system to read), and
|
|
|
|
// record any intent we were asked to communicate back to the system.
|
|
|
|
// this function is idempotent: call it as many times as you like.
|
|
|
|
static void
|
2009-11-30 16:40:57 +00:00
|
|
|
finish_recovery(const char *send_intent) {
|
2009-03-04 03:28:42 +00:00
|
|
|
// By this point, we're ready to return to the main system...
|
|
|
|
if (send_intent != NULL) {
|
|
|
|
FILE *fp = fopen_root_path(INTENT_FILE, "w");
|
2008-11-17 01:56:05 +00:00
|
|
|
if (fp == NULL) {
|
|
|
|
LOGE("Can't open %s\n", INTENT_FILE);
|
|
|
|
} else {
|
2009-03-04 03:28:42 +00:00
|
|
|
fputs(send_intent, fp);
|
|
|
|
check_and_fclose(fp, INTENT_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy logs to cache so the system can find out what happened.
|
|
|
|
FILE *log = fopen_root_path(LOG_FILE, "a");
|
2008-11-17 01:56:05 +00:00
|
|
|
if (log == NULL) {
|
|
|
|
LOGE("Can't open %s\n", LOG_FILE);
|
|
|
|
} else {
|
2009-03-04 03:28:42 +00:00
|
|
|
FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r");
|
|
|
|
if (tmplog == NULL) {
|
|
|
|
LOGE("Can't open %s\n", TEMPORARY_LOG_FILE);
|
|
|
|
} else {
|
|
|
|
static long tmplog_offset = 0;
|
|
|
|
fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write
|
|
|
|
char buf[4096];
|
|
|
|
while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log);
|
|
|
|
tmplog_offset = ftell(tmplog);
|
|
|
|
check_and_fclose(tmplog, TEMPORARY_LOG_FILE);
|
|
|
|
}
|
|
|
|
check_and_fclose(log, LOG_FILE);
|
|
|
|
}
|
|
|
|
|
2009-11-30 16:40:57 +00:00
|
|
|
// Reset to mormal system boot so recovery won't cycle indefinitely.
|
2009-03-04 03:28:42 +00:00
|
|
|
struct bootloader_message boot;
|
|
|
|
memset(&boot, 0, sizeof(boot));
|
|
|
|
set_bootloader_message(&boot);
|
|
|
|
|
|
|
|
// Remove the command file, so recovery won't repeat indefinitely.
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
if (ensure_root_path_mounted(COMMAND_FILE) != 0 ||
|
|
|
|
translate_root_path(COMMAND_FILE, path, sizeof(path)) == NULL ||
|
|
|
|
(unlink(path) && errno != ENOENT)) {
|
|
|
|
LOGW("Can't unlink %s\n", COMMAND_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
sync(); // For good measure.
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-11-30 16:40:57 +00:00
|
|
|
erase_root(const char *root) {
|
2009-03-04 03:28:42 +00:00
|
|
|
ui_set_background(BACKGROUND_ICON_INSTALLING);
|
|
|
|
ui_show_indeterminate_progress();
|
|
|
|
ui_print("Formatting %s...\n", root);
|
|
|
|
return format_root_device(root);
|
|
|
|
}
|
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
static char**
|
|
|
|
prepend_title(char** headers) {
|
2010-03-20 08:08:55 +00:00
|
|
|
char* title[] = { EXPAND(RECOVERY_VERSION),
|
2009-06-18 05:07:13 +00:00
|
|
|
"",
|
2009-03-04 03:28:42 +00:00
|
|
|
NULL };
|
|
|
|
|
2009-06-18 05:07:13 +00:00
|
|
|
// count the number of lines in our title, plus the
|
2009-09-22 22:16:02 +00:00
|
|
|
// caller-provided headers.
|
2009-06-18 05:07:13 +00:00
|
|
|
int count = 0;
|
|
|
|
char** p;
|
|
|
|
for (p = title; *p; ++p, ++count);
|
2009-09-22 22:16:02 +00:00
|
|
|
for (p = headers; *p; ++p, ++count);
|
2009-06-18 05:07:13 +00:00
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
char** new_headers = malloc((count+1) * sizeof(char*));
|
|
|
|
char** h = new_headers;
|
2009-06-18 05:07:13 +00:00
|
|
|
for (p = title; *p; ++p, ++h) *h = *p;
|
2009-09-22 22:16:02 +00:00
|
|
|
for (p = headers; *p; ++p, ++h) *h = *p;
|
2009-06-18 05:07:13 +00:00
|
|
|
*h = NULL;
|
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
return new_headers;
|
|
|
|
}
|
|
|
|
|
2010-02-12 08:43:24 +00:00
|
|
|
int
|
2009-09-22 22:16:02 +00:00
|
|
|
get_menu_selection(char** headers, char** items, int menu_only) {
|
|
|
|
// throw away keys pressed previously, so user doesn't
|
|
|
|
// accidentally trigger menu items.
|
|
|
|
ui_clear_key_queue();
|
|
|
|
|
2010-06-09 19:19:41 +00:00
|
|
|
int item_count = ui_start_menu(headers, items);
|
2009-03-04 03:28:42 +00:00
|
|
|
int selected = 0;
|
|
|
|
int chosen_item = -1;
|
|
|
|
|
2010-07-15 01:37:33 +00:00
|
|
|
// Some users with dead enter keys need a way to turn on power to select.
|
|
|
|
// Jiggering across the wrapping menu is one "secret" way to enable it.
|
|
|
|
// We can't rely on /cache or /sdcard since they may not be available.
|
|
|
|
int wrap_count = 0;
|
|
|
|
|
2010-02-19 22:17:22 +00:00
|
|
|
while (chosen_item < 0 && chosen_item != GO_BACK) {
|
2009-03-04 03:28:42 +00:00
|
|
|
int key = ui_wait_key();
|
|
|
|
int visible = ui_text_visible();
|
|
|
|
|
2009-06-09 19:22:33 +00:00
|
|
|
int action = device_handle_key(key, visible);
|
|
|
|
|
2010-07-15 01:37:33 +00:00
|
|
|
int old_selected = selected;
|
|
|
|
|
2009-06-09 19:22:33 +00:00
|
|
|
if (action < 0) {
|
|
|
|
switch (action) {
|
|
|
|
case HIGHLIGHT_UP:
|
|
|
|
--selected;
|
|
|
|
selected = ui_menu_select(selected);
|
|
|
|
break;
|
|
|
|
case HIGHLIGHT_DOWN:
|
|
|
|
++selected;
|
|
|
|
selected = ui_menu_select(selected);
|
|
|
|
break;
|
|
|
|
case SELECT_ITEM:
|
|
|
|
chosen_item = selected;
|
2010-07-15 01:37:33 +00:00
|
|
|
if (ui_get_showing_back_button()) {
|
|
|
|
if (chosen_item == item_count) {
|
|
|
|
chosen_item = GO_BACK;
|
|
|
|
}
|
2010-06-09 19:19:41 +00:00
|
|
|
}
|
2009-06-09 19:22:33 +00:00
|
|
|
break;
|
|
|
|
case NO_ACTION:
|
|
|
|
break;
|
2010-02-12 08:43:24 +00:00
|
|
|
case GO_BACK:
|
2010-02-19 22:17:22 +00:00
|
|
|
chosen_item = GO_BACK;
|
|
|
|
break;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
2009-09-22 22:16:02 +00:00
|
|
|
} else if (!menu_only) {
|
2009-06-09 19:22:33 +00:00
|
|
|
chosen_item = action;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
2010-07-15 01:37:33 +00:00
|
|
|
|
|
|
|
if (abs(selected - old_selected) > 1) {
|
|
|
|
wrap_count++;
|
|
|
|
if (wrap_count == 3) {
|
|
|
|
wrap_count = 0;
|
|
|
|
if (ui_get_showing_back_button()) {
|
2010-07-15 04:01:21 +00:00
|
|
|
ui_print("Back menu button disabled.\n");
|
2010-07-15 01:37:33 +00:00
|
|
|
ui_set_showing_back_button(0);
|
|
|
|
}
|
|
|
|
else {
|
2010-07-15 04:01:21 +00:00
|
|
|
ui_print("Back menu button enabled.\n");
|
2010-07-15 01:37:33 +00:00
|
|
|
ui_set_showing_back_button(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-22 22:16:02 +00:00
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
ui_end_menu();
|
2010-02-22 16:53:34 +00:00
|
|
|
ui_clear_key_queue();
|
2009-09-22 22:16:02 +00:00
|
|
|
return chosen_item;
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
static void
|
|
|
|
wipe_data(int confirm) {
|
|
|
|
if (confirm) {
|
|
|
|
static char** title_headers = NULL;
|
|
|
|
|
|
|
|
if (title_headers == NULL) {
|
|
|
|
char* headers[] = { "Confirm wipe of all user data?",
|
|
|
|
" THIS CAN NOT BE UNDONE.",
|
|
|
|
"",
|
|
|
|
NULL };
|
|
|
|
title_headers = prepend_title(headers);
|
|
|
|
}
|
2009-04-01 20:57:40 +00:00
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
char* items[] = { " No",
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
" Yes -- delete all user data", // [7]
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
" No",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
int chosen_item = get_menu_selection(title_headers, items, 1);
|
|
|
|
if (chosen_item != 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_print("\n-- Wiping data...\n");
|
|
|
|
device_wipe_data();
|
|
|
|
erase_root("DATA:");
|
2010-06-15 19:56:17 +00:00
|
|
|
#ifdef HAS_DATADATA
|
|
|
|
erase_root("DATADATA:");
|
|
|
|
#endif
|
2009-09-22 22:16:02 +00:00
|
|
|
erase_root("CACHE:");
|
2010-04-18 23:00:21 +00:00
|
|
|
erase_root("SDEXT:");
|
2010-07-03 20:54:21 +00:00
|
|
|
erase_root("SDCARD:/.android_secure");
|
2009-09-22 22:16:02 +00:00
|
|
|
ui_print("Data wipe complete.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-30 16:40:57 +00:00
|
|
|
prompt_and_wait() {
|
2009-09-22 22:16:02 +00:00
|
|
|
char** headers = prepend_title(MENU_HEADERS);
|
2010-02-26 00:51:45 +00:00
|
|
|
|
2009-09-22 22:16:02 +00:00
|
|
|
for (;;) {
|
|
|
|
finish_recovery(NULL);
|
|
|
|
ui_reset_progress();
|
|
|
|
|
2010-02-19 22:17:22 +00:00
|
|
|
allow_display_toggle = 1;
|
2009-09-22 22:16:02 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0);
|
2010-02-19 22:17:22 +00:00
|
|
|
allow_display_toggle = 0;
|
2009-09-22 22:16:02 +00:00
|
|
|
|
|
|
|
// device-specific code may take some action here. It may
|
|
|
|
// return one of the core actions handled in the switch
|
|
|
|
// statement below.
|
|
|
|
chosen_item = device_perform_action(chosen_item);
|
|
|
|
|
|
|
|
switch (chosen_item) {
|
|
|
|
case ITEM_REBOOT:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ITEM_WIPE_DATA:
|
|
|
|
wipe_data(ui_text_visible());
|
|
|
|
if (!ui_text_visible()) return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_WIPE_CACHE:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache"))
|
|
|
|
{
|
|
|
|
ui_print("\n-- Wiping cache...\n");
|
|
|
|
erase_root("CACHE:");
|
|
|
|
ui_print("Cache wipe complete.\n");
|
|
|
|
if (!ui_text_visible()) return;
|
|
|
|
}
|
2009-09-22 22:16:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_APPLY_SDCARD:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip"))
|
|
|
|
{
|
|
|
|
ui_print("\n-- Install from sdcard...\n");
|
|
|
|
set_sdcard_update_bootloader_message();
|
|
|
|
int status = install_package(SDCARD_PACKAGE_FILE);
|
|
|
|
if (status != INSTALL_SUCCESS) {
|
|
|
|
ui_set_background(BACKGROUND_ICON_ERROR);
|
|
|
|
ui_print("Installation aborted.\n");
|
|
|
|
} else if (!ui_text_visible()) {
|
|
|
|
return; // reboot if logs aren't visible
|
|
|
|
} else {
|
|
|
|
ui_print("\nInstall from sdcard complete.\n");
|
2009-09-22 22:16:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-02-22 05:10:25 +00:00
|
|
|
case ITEM_INSTALL_ZIP:
|
|
|
|
show_install_update_menu();
|
2010-02-12 06:27:06 +00:00
|
|
|
break;
|
2010-03-19 20:34:36 +00:00
|
|
|
case ITEM_NANDROID:
|
|
|
|
show_nandroid_menu();
|
2010-02-12 08:43:24 +00:00
|
|
|
break;
|
2010-03-19 20:34:36 +00:00
|
|
|
case ITEM_PARTITION:
|
|
|
|
show_partition_menu();
|
2010-03-15 05:42:30 +00:00
|
|
|
break;
|
2010-03-19 21:51:45 +00:00
|
|
|
case ITEM_ADVANCED:
|
|
|
|
show_advanced_menu();
|
2010-02-22 05:29:10 +00:00
|
|
|
break;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-30 16:40:57 +00:00
|
|
|
print_property(const char *key, const char *name, void *cookie) {
|
2009-03-04 03:28:42 +00:00
|
|
|
fprintf(stderr, "%s=%s\n", key, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-11-30 16:40:57 +00:00
|
|
|
main(int argc, char **argv) {
|
2010-03-03 08:42:58 +00:00
|
|
|
if (strstr(argv[0], "recovery") == NULL)
|
|
|
|
{
|
|
|
|
if (strstr(argv[0], "flash_image") != NULL)
|
|
|
|
return flash_image_main(argc, argv);
|
|
|
|
if (strstr(argv[0], "dump_image") != NULL)
|
|
|
|
return dump_image_main(argc, argv);
|
2010-03-19 21:37:11 +00:00
|
|
|
if (strstr(argv[0], "erase_image") != NULL)
|
|
|
|
return erase_image_main(argc, argv);
|
2010-03-03 08:42:58 +00:00
|
|
|
if (strstr(argv[0], "mkyaffs2image") != NULL)
|
|
|
|
return mkyaffs2image_main(argc, argv);
|
|
|
|
if (strstr(argv[0], "unyaffs") != NULL)
|
|
|
|
return unyaffs_main(argc, argv);
|
2010-03-07 21:39:21 +00:00
|
|
|
if (strstr(argv[0], "amend"))
|
|
|
|
return amend_main(argc, argv);
|
2010-07-03 20:56:45 +00:00
|
|
|
if (strstr(argv[0], "nandroid"))
|
|
|
|
return nandroid_main(argc, argv);
|
2010-03-03 08:42:58 +00:00
|
|
|
return busybox_driver(argc, argv);
|
|
|
|
}
|
2010-06-20 20:16:06 +00:00
|
|
|
create_fstab();
|
2010-06-14 19:49:47 +00:00
|
|
|
__system("/sbin/postrecoveryboot.sh");
|
2010-05-01 19:46:55 +00:00
|
|
|
|
2010-02-26 22:14:23 +00:00
|
|
|
int is_user_initiated_recovery = 0;
|
2009-03-04 03:28:42 +00:00
|
|
|
time_t start = time(NULL);
|
|
|
|
|
|
|
|
// If these fail, there's not really anywhere to complain...
|
|
|
|
freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
|
|
|
|
freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
|
|
|
|
fprintf(stderr, "Starting recovery on %s", ctime(&start));
|
|
|
|
|
|
|
|
ui_init();
|
2010-07-01 19:52:34 +00:00
|
|
|
ui_print(EXPAND(RECOVERY_VERSION)"\n");
|
2009-03-04 03:28:42 +00:00
|
|
|
get_args(&argc, &argv);
|
|
|
|
|
|
|
|
int previous_runs = 0;
|
|
|
|
const char *send_intent = NULL;
|
|
|
|
const char *update_package = NULL;
|
|
|
|
int wipe_data = 0, wipe_cache = 0;
|
|
|
|
|
|
|
|
int arg;
|
|
|
|
while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
|
|
|
|
switch (arg) {
|
|
|
|
case 'p': previous_runs = atoi(optarg); break;
|
|
|
|
case 's': send_intent = optarg; break;
|
|
|
|
case 'u': update_package = optarg; break;
|
|
|
|
case 'w': wipe_data = wipe_cache = 1; break;
|
|
|
|
case 'c': wipe_cache = 1; break;
|
|
|
|
case '?':
|
|
|
|
LOGE("Invalid command argument\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 23:59:12 +00:00
|
|
|
device_recovery_start();
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
fprintf(stderr, "Command:");
|
|
|
|
for (arg = 0; arg < argc; arg++) {
|
|
|
|
fprintf(stderr, " \"%s\"", argv[arg]);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n\n");
|
|
|
|
|
|
|
|
property_list(print_property, NULL);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
int status = INSTALL_SUCCESS;
|
2010-02-12 06:27:06 +00:00
|
|
|
|
|
|
|
RecoveryCommandContext ctx = { NULL };
|
|
|
|
if (register_update_commands(&ctx)) {
|
|
|
|
LOGE("Can't install update commands\n");
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
if (update_package != NULL) {
|
2010-02-26 07:45:55 +00:00
|
|
|
if (wipe_data && erase_root("DATA:")) status = INSTALL_ERROR;
|
2009-03-04 03:28:42 +00:00
|
|
|
status = install_package(update_package);
|
|
|
|
if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
|
2009-06-18 22:07:14 +00:00
|
|
|
} else if (wipe_data) {
|
|
|
|
if (device_wipe_data()) status = INSTALL_ERROR;
|
|
|
|
if (erase_root("DATA:")) status = INSTALL_ERROR;
|
2009-03-04 03:28:42 +00:00
|
|
|
if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR;
|
|
|
|
if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
|
2009-06-18 22:07:14 +00:00
|
|
|
} else if (wipe_cache) {
|
|
|
|
if (wipe_cache && erase_root("CACHE:")) status = INSTALL_ERROR;
|
|
|
|
if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n");
|
2009-03-04 03:28:42 +00:00
|
|
|
} else {
|
2010-06-09 19:19:41 +00:00
|
|
|
LOGI("Checking for extendedcommand...\n");
|
2009-03-04 03:28:42 +00:00
|
|
|
status = INSTALL_ERROR; // No command specified
|
2010-02-26 22:14:23 +00:00
|
|
|
// we are starting up in user initiated recovery here
|
|
|
|
// let's set up some default options
|
|
|
|
signature_check_enabled = 0;
|
2010-03-07 00:40:52 +00:00
|
|
|
script_assert_enabled = 0;
|
2010-02-26 22:14:23 +00:00
|
|
|
is_user_initiated_recovery = 1;
|
|
|
|
ui_set_show_text(1);
|
2010-03-07 22:10:26 +00:00
|
|
|
|
2010-03-07 22:11:56 +00:00
|
|
|
if (extendedcommand_file_exists()) {
|
2010-06-09 19:19:41 +00:00
|
|
|
LOGI("Running extendedcommand...\n");
|
2010-06-20 16:42:47 +00:00
|
|
|
int ret;
|
|
|
|
if (0 == (ret = run_and_remove_extendedcommand())) {
|
2010-03-07 22:11:56 +00:00
|
|
|
status = INSTALL_SUCCESS;
|
2010-03-07 22:15:14 +00:00
|
|
|
ui_set_show_text(0);
|
2010-03-07 22:11:56 +00:00
|
|
|
}
|
2010-06-20 16:42:47 +00:00
|
|
|
else {
|
|
|
|
handle_failure(ret);
|
|
|
|
}
|
2010-06-09 19:19:41 +00:00
|
|
|
} else {
|
|
|
|
LOGI("Skipping execution of extendedcommand, file not found...\n");
|
2010-03-07 22:11:56 +00:00
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 22:14:23 +00:00
|
|
|
if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) ui_set_background(BACKGROUND_ICON_ERROR);
|
2009-03-04 03:28:42 +00:00
|
|
|
if (status != INSTALL_SUCCESS || ui_text_visible()) prompt_and_wait();
|
|
|
|
|
|
|
|
// Otherwise, get ready to boot the main system...
|
|
|
|
finish_recovery(send_intent);
|
|
|
|
ui_print("Rebooting...\n");
|
|
|
|
sync();
|
|
|
|
reboot(RB_AUTOBOOT);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2010-02-19 22:17:22 +00:00
|
|
|
|
|
|
|
int get_allow_toggle_display() {
|
|
|
|
return allow_display_toggle;
|
2010-02-26 07:45:55 +00:00
|
|
|
}
|