Merge "recovery: Handle devices without /cache partition." am: 479d9dc2f2
am: f2726712ea
* commit 'f2726712ea1e02fdabf595ece1cfeab9a6147386':
recovery: Handle devices without /cache partition.
This commit is contained in:
commit
c36b919525
1 changed files with 29 additions and 10 deletions
37
recovery.cpp
37
recovery.cpp
|
@ -101,6 +101,7 @@ char* locale = NULL;
|
||||||
char* stage = NULL;
|
char* stage = NULL;
|
||||||
char* reason = NULL;
|
char* reason = NULL;
|
||||||
bool modified_flash = false;
|
bool modified_flash = false;
|
||||||
|
static bool has_cache = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The recovery tool communicates with the main system through /cache files.
|
* The recovery tool communicates with the main system through /cache files.
|
||||||
|
@ -313,8 +314,8 @@ get_args(int *argc, char ***argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- if that doesn't work, try the command file
|
// --- if that doesn't work, try the command file (if we have /cache).
|
||||||
if (*argc <= 1) {
|
if (*argc <= 1 && has_cache) {
|
||||||
FILE *fp = fopen_path(COMMAND_FILE, "r");
|
FILE *fp = fopen_path(COMMAND_FILE, "r");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
char *token;
|
char *token;
|
||||||
|
@ -436,6 +437,11 @@ static void rotate_logs(int max) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_logs() {
|
static void copy_logs() {
|
||||||
|
// We can do nothing for now if there's no /cache partition.
|
||||||
|
if (!has_cache) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We only rotate and record the log of the current session if there are
|
// We only rotate and record the log of the current session if there are
|
||||||
// actual attempts to modify the flash, such as wipes, installs from BCB
|
// actual attempts to modify the flash, such as wipes, installs from BCB
|
||||||
// or menu selections. This is to avoid unnecessary rotation (and
|
// or menu selections. This is to avoid unnecessary rotation (and
|
||||||
|
@ -467,7 +473,7 @@ static void copy_logs() {
|
||||||
static void
|
static void
|
||||||
finish_recovery(const char *send_intent) {
|
finish_recovery(const char *send_intent) {
|
||||||
// By this point, we're ready to return to the main system...
|
// By this point, we're ready to return to the main system...
|
||||||
if (send_intent != NULL) {
|
if (send_intent != NULL && has_cache) {
|
||||||
FILE *fp = fopen_path(INTENT_FILE, "w");
|
FILE *fp = fopen_path(INTENT_FILE, "w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
LOGE("Can't open %s\n", INTENT_FILE);
|
LOGE("Can't open %s\n", INTENT_FILE);
|
||||||
|
@ -480,7 +486,7 @@ finish_recovery(const char *send_intent) {
|
||||||
// Save the locale to cache, so if recovery is next started up
|
// Save the locale to cache, so if recovery is next started up
|
||||||
// without a --locale argument (eg, directly from the bootloader)
|
// without a --locale argument (eg, directly from the bootloader)
|
||||||
// it will use the last-known locale.
|
// it will use the last-known locale.
|
||||||
if (locale != NULL) {
|
if (locale != NULL && has_cache) {
|
||||||
LOGI("Saving locale \"%s\"\n", locale);
|
LOGI("Saving locale \"%s\"\n", locale);
|
||||||
FILE* fp = fopen_path(LOCALE_FILE, "w");
|
FILE* fp = fopen_path(LOCALE_FILE, "w");
|
||||||
fwrite(locale, 1, strlen(locale), fp);
|
fwrite(locale, 1, strlen(locale), fp);
|
||||||
|
@ -497,12 +503,13 @@ finish_recovery(const char *send_intent) {
|
||||||
set_bootloader_message(&boot);
|
set_bootloader_message(&boot);
|
||||||
|
|
||||||
// Remove the command file, so recovery won't repeat indefinitely.
|
// Remove the command file, so recovery won't repeat indefinitely.
|
||||||
if (ensure_path_mounted(COMMAND_FILE) != 0 ||
|
if (has_cache) {
|
||||||
(unlink(COMMAND_FILE) && errno != ENOENT)) {
|
if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) {
|
||||||
LOGW("Can't unlink %s\n", COMMAND_FILE);
|
LOGW("Can't unlink %s\n", COMMAND_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_path_unmounted(CACHE_ROOT);
|
ensure_path_unmounted(CACHE_ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
sync(); // For good measure.
|
sync(); // For good measure.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,7 +800,7 @@ static bool wipe_data(int should_confirm, Device* device) {
|
||||||
bool success =
|
bool success =
|
||||||
device->PreWipeData() &&
|
device->PreWipeData() &&
|
||||||
erase_volume("/data") &&
|
erase_volume("/data") &&
|
||||||
erase_volume("/cache") &&
|
(has_cache ? erase_volume("/cache") : true) &&
|
||||||
device->PostWipeData();
|
device->PostWipeData();
|
||||||
ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
|
ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
|
||||||
return success;
|
return success;
|
||||||
|
@ -801,6 +808,11 @@ static bool wipe_data(int should_confirm, Device* device) {
|
||||||
|
|
||||||
// Return true on success.
|
// Return true on success.
|
||||||
static bool wipe_cache(bool should_confirm, Device* device) {
|
static bool wipe_cache(bool should_confirm, Device* device) {
|
||||||
|
if (!has_cache) {
|
||||||
|
ui->Print("No /cache partition found.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) {
|
if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -814,6 +826,11 @@ static bool wipe_cache(bool should_confirm, Device* device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void choose_recovery_file(Device* device) {
|
static void choose_recovery_file(Device* device) {
|
||||||
|
if (!has_cache) {
|
||||||
|
ui->Print("No /cache partition found.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// "Back" + KEEP_LOG_COUNT * 2 + terminating nullptr entry
|
// "Back" + KEEP_LOG_COUNT * 2 + terminating nullptr entry
|
||||||
char* entries[1 + KEEP_LOG_COUNT * 2 + 1];
|
char* entries[1 + KEEP_LOG_COUNT * 2 + 1];
|
||||||
memset(entries, 0, sizeof(entries));
|
memset(entries, 0, sizeof(entries));
|
||||||
|
@ -1167,6 +1184,8 @@ int main(int argc, char **argv) {
|
||||||
printf("Starting recovery (pid %d) on %s", getpid(), ctime(&start));
|
printf("Starting recovery (pid %d) on %s", getpid(), ctime(&start));
|
||||||
|
|
||||||
load_volume_table();
|
load_volume_table();
|
||||||
|
has_cache = volume_for_path(CACHE_ROOT) != nullptr;
|
||||||
|
|
||||||
get_args(&argc, &argv);
|
get_args(&argc, &argv);
|
||||||
|
|
||||||
const char *send_intent = NULL;
|
const char *send_intent = NULL;
|
||||||
|
@ -1207,7 +1226,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locale == NULL) {
|
if (locale == nullptr && has_cache) {
|
||||||
load_locale_from_cache();
|
load_locale_from_cache();
|
||||||
}
|
}
|
||||||
printf("locale is [%s]\n", locale);
|
printf("locale is [%s]\n", locale);
|
||||||
|
|
Loading…
Reference in a new issue