2010-02-12 06:27:06 +00:00
|
|
|
#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-02-12 08:43:24 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <dirent.h>
|
2010-02-25 22:51:05 +00:00
|
|
|
#include <sys/stat.h>
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-02-25 19:39:07 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2010-02-12 06:27:06 +00:00
|
|
|
#include "bootloader.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "cutils/properties.h"
|
|
|
|
#include "firmware.h"
|
|
|
|
#include "install.h"
|
|
|
|
#include "minui/minui.h"
|
|
|
|
#include "minzip/DirUtil.h"
|
|
|
|
#include "roots.h"
|
|
|
|
#include "recovery_ui.h"
|
|
|
|
|
2010-03-07 21:39:21 +00:00
|
|
|
#include "commands.h"
|
|
|
|
#include "amend/amend.h"
|
|
|
|
|
2010-06-14 22:02:48 +00:00
|
|
|
#include "mtdutils/mtdutils.h"
|
2010-03-13 01:00:58 +00:00
|
|
|
#include "mtdutils/dump_image.h"
|
|
|
|
#include "../../external/yaffs2/yaffs2/utils/mkyaffs2image.h"
|
2010-03-13 01:43:26 +00:00
|
|
|
#include "../../external/yaffs2/yaffs2/utils/unyaffs.h"
|
2010-03-13 01:00:58 +00:00
|
|
|
|
2010-03-13 07:21:12 +00:00
|
|
|
#include "extendedcommands.h"
|
|
|
|
#include "nandroid.h"
|
|
|
|
|
2010-02-12 06:27:06 +00:00
|
|
|
int signature_check_enabled = 1;
|
|
|
|
int script_assert_enabled = 1;
|
2010-02-22 05:10:25 +00:00
|
|
|
static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip";
|
2010-02-12 06:27:06 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
toggle_signature_check()
|
|
|
|
{
|
|
|
|
signature_check_enabled = !signature_check_enabled;
|
|
|
|
ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggle_script_asserts()
|
|
|
|
{
|
|
|
|
script_assert_enabled = !script_assert_enabled;
|
2010-02-12 08:43:24 +00:00
|
|
|
ui_print("Script Asserts: %s\n", script_assert_enabled ? "Enabled" : "Disabled");
|
|
|
|
}
|
|
|
|
|
2010-03-08 10:58:04 +00:00
|
|
|
int install_zip(const char* packagefilepath)
|
2010-02-22 05:10:25 +00:00
|
|
|
{
|
|
|
|
ui_print("\n-- Installing: %s\n", packagefilepath);
|
2010-07-20 23:23:18 +00:00
|
|
|
#ifndef BOARD_HAS_NO_MISC_PARTITION
|
2010-02-22 05:10:25 +00:00
|
|
|
set_sdcard_update_bootloader_message();
|
2010-07-20 23:23:18 +00:00
|
|
|
#endif
|
2010-02-22 05:10:25 +00:00
|
|
|
int status = install_package(packagefilepath);
|
2010-04-19 01:06:24 +00:00
|
|
|
ui_reset_progress();
|
2010-02-22 05:10:25 +00:00
|
|
|
if (status != INSTALL_SUCCESS) {
|
|
|
|
ui_set_background(BACKGROUND_ICON_ERROR);
|
|
|
|
ui_print("Installation aborted.\n");
|
2010-03-08 10:58:04 +00:00
|
|
|
return 1;
|
2010-02-25 20:03:17 +00:00
|
|
|
}
|
2010-07-20 23:23:18 +00:00
|
|
|
#ifndef BOARD_HAS_NO_MISC_PARTITION
|
2010-02-25 20:03:17 +00:00
|
|
|
if (firmware_update_pending()) {
|
|
|
|
ui_print("\nReboot via menu to complete\ninstallation.\n");
|
2010-02-25 22:53:57 +00:00
|
|
|
}
|
2010-07-20 23:23:18 +00:00
|
|
|
#endif
|
2010-02-25 22:53:57 +00:00
|
|
|
ui_set_background(BACKGROUND_ICON_NONE);
|
2010-03-03 08:42:58 +00:00
|
|
|
ui_print("\nInstall from sdcard complete.\n");
|
2010-03-08 10:58:04 +00:00
|
|
|
return 0;
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char* INSTALL_MENU_ITEMS[] = { "apply sdcard:update.zip",
|
|
|
|
"choose zip from sdcard",
|
|
|
|
"toggle signature verification",
|
|
|
|
"toggle script asserts",
|
|
|
|
NULL };
|
|
|
|
#define ITEM_APPLY_SDCARD 0
|
|
|
|
#define ITEM_CHOOSE_ZIP 1
|
|
|
|
#define ITEM_SIG_CHECK 2
|
|
|
|
#define ITEM_ASSERTS 3
|
|
|
|
|
|
|
|
void show_install_update_menu()
|
|
|
|
{
|
|
|
|
static char* headers[] = { "Apply update from .zip file on SD card",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int chosen_item = get_menu_selection(headers, INSTALL_MENU_ITEMS, 0);
|
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case ITEM_ASSERTS:
|
|
|
|
toggle_script_asserts();
|
|
|
|
break;
|
|
|
|
case ITEM_SIG_CHECK:
|
|
|
|
toggle_signature_check();
|
|
|
|
break;
|
|
|
|
case ITEM_APPLY_SDCARD:
|
2010-07-15 04:01:21 +00:00
|
|
|
{
|
|
|
|
if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip"))
|
|
|
|
install_zip(SDCARD_PACKAGE_FILE);
|
2010-02-22 05:10:25 +00:00
|
|
|
break;
|
2010-07-15 04:01:21 +00:00
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
case ITEM_CHOOSE_ZIP:
|
|
|
|
show_choose_zip_menu();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
void free_string_array(char** array)
|
|
|
|
{
|
|
|
|
if (array == NULL)
|
|
|
|
return;
|
|
|
|
char* cursor = array[0];
|
|
|
|
int i = 0;
|
|
|
|
while (cursor != NULL)
|
|
|
|
{
|
|
|
|
free(cursor);
|
|
|
|
cursor = array[++i];
|
|
|
|
}
|
|
|
|
free(array);
|
|
|
|
}
|
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
char** gather_files(const char* directory, const char* fileExtensionOrDirectory, int* numFiles)
|
2010-02-12 08:43:24 +00:00
|
|
|
{
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
int total = 0;
|
|
|
|
int i;
|
2010-03-13 07:21:12 +00:00
|
|
|
char** files = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
int pass;
|
|
|
|
*numFiles = 0;
|
|
|
|
int dirLen = strlen(directory);
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
dir = opendir(directory);
|
2010-02-12 08:43:24 +00:00
|
|
|
if (dir == NULL) {
|
2010-02-22 05:10:25 +00:00
|
|
|
ui_print("Couldn't open directory.\n");
|
|
|
|
return NULL;
|
2010-02-12 08:43:24 +00:00
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
|
2010-03-13 07:21:12 +00:00
|
|
|
int extension_length = 0;
|
2010-02-25 22:53:57 +00:00
|
|
|
if (fileExtensionOrDirectory != NULL)
|
|
|
|
extension_length = strlen(fileExtensionOrDirectory);
|
2010-02-22 05:10:25 +00:00
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
int isCounting = 1;
|
|
|
|
i = 0;
|
|
|
|
for (pass = 0; pass < 2; pass++) {
|
|
|
|
while ((de=readdir(dir)) != NULL) {
|
|
|
|
// skip hidden files
|
|
|
|
if (de->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// NULL means that we are gathering directories, so skip this
|
|
|
|
if (fileExtensionOrDirectory != NULL)
|
|
|
|
{
|
|
|
|
// make sure that we can have the desired extension (prevent seg fault)
|
|
|
|
if (strlen(de->d_name) < extension_length)
|
|
|
|
continue;
|
|
|
|
// compare the extension
|
|
|
|
if (strcmp(de->d_name + strlen(de->d_name) - extension_length, fileExtensionOrDirectory) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct stat info;
|
2010-04-02 23:46:21 +00:00
|
|
|
char fullFileName[PATH_MAX];
|
2010-02-25 22:53:57 +00:00
|
|
|
strcpy(fullFileName, directory);
|
|
|
|
strcat(fullFileName, de->d_name);
|
|
|
|
stat(fullFileName, &info);
|
|
|
|
// make sure it is a directory
|
|
|
|
if (!(S_ISDIR(info.st_mode)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
total++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
files[i] = (char*) malloc(dirLen + strlen(de->d_name) + 2);
|
|
|
|
strcpy(files[i], directory);
|
|
|
|
strcat(files[i], de->d_name);
|
2010-02-25 22:53:57 +00:00
|
|
|
if (fileExtensionOrDirectory == NULL)
|
|
|
|
strcat(files[i], "/");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (pass == 1)
|
|
|
|
break;
|
|
|
|
if (total == 0)
|
|
|
|
break;
|
|
|
|
rewinddir(dir);
|
|
|
|
*numFiles = total;
|
|
|
|
files = (char**) malloc((total+1)*sizeof(char*));
|
|
|
|
files[total]=NULL;
|
|
|
|
}
|
2010-02-25 22:51:05 +00:00
|
|
|
|
|
|
|
if(closedir(dir) < 0) {
|
|
|
|
LOGE("Failed to close directory.");
|
2010-02-12 08:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (total==0) {
|
2010-02-22 05:10:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-07-01 07:23:25 +00:00
|
|
|
// sort the result
|
|
|
|
if (files != NULL) {
|
|
|
|
for (i = 0; i < total; i++) {
|
|
|
|
int curMax = -1;
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < total - i; j++) {
|
|
|
|
if (curMax == -1 || strcmp(files[curMax], files[j]) < 0)
|
|
|
|
curMax = j;
|
|
|
|
}
|
|
|
|
char* temp = files[curMax];
|
|
|
|
files[curMax] = files[total - i - 1];
|
|
|
|
files[total - i - 1] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
return files;
|
2010-02-25 22:51:05 +00:00
|
|
|
}
|
2010-02-12 08:43:24 +00:00
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
// pass in NULL for fileExtensionOrDirectory and you will get a directory chooser
|
|
|
|
char* choose_file_menu(const char* directory, const char* fileExtensionOrDirectory, const char* headers[])
|
|
|
|
{
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
int numFiles = 0;
|
2010-02-25 22:53:57 +00:00
|
|
|
int numDirs = 0;
|
2010-02-25 22:51:05 +00:00
|
|
|
int i;
|
2010-04-02 23:46:21 +00:00
|
|
|
char* return_value = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
int dir_len = strlen(directory);
|
|
|
|
|
|
|
|
char** files = gather_files(directory, fileExtensionOrDirectory, &numFiles);
|
2010-03-13 07:21:12 +00:00
|
|
|
char** dirs = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
if (fileExtensionOrDirectory != NULL)
|
|
|
|
dirs = gather_files(directory, NULL, &numDirs);
|
|
|
|
int total = numDirs + numFiles;
|
|
|
|
if (total == 0)
|
|
|
|
{
|
|
|
|
ui_print("No files found.\n");
|
|
|
|
}
|
2010-04-02 23:46:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char** list = (char**) malloc((total + 1) * sizeof(char*));
|
|
|
|
list[total] = NULL;
|
2010-02-25 22:53:57 +00:00
|
|
|
|
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
for (i = 0 ; i < numDirs; i++)
|
|
|
|
{
|
|
|
|
list[i] = strdup(dirs[i] + dir_len);
|
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
for (i = 0 ; i < numFiles; i++)
|
|
|
|
{
|
|
|
|
list[numDirs + i] = strdup(files[i] + dir_len);
|
|
|
|
}
|
2010-02-22 05:10:25 +00:00
|
|
|
|
2010-04-02 23:46:21 +00:00
|
|
|
for (;;)
|
2010-02-25 22:53:57 +00:00
|
|
|
{
|
2010-04-02 23:46:21 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0);
|
|
|
|
if (chosen_item == GO_BACK)
|
|
|
|
break;
|
|
|
|
static char ret[PATH_MAX];
|
|
|
|
if (chosen_item < numDirs)
|
|
|
|
{
|
|
|
|
char* subret = choose_file_menu(dirs[chosen_item], fileExtensionOrDirectory, headers);
|
|
|
|
if (subret != NULL)
|
|
|
|
{
|
|
|
|
strcpy(ret, subret);
|
|
|
|
return_value = ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strcpy(ret, files[chosen_item - numDirs]);
|
|
|
|
return_value = ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free_string_array(list);
|
2010-02-22 16:53:34 +00:00
|
|
|
}
|
2010-04-02 23:46:21 +00:00
|
|
|
|
|
|
|
free_string_array(files);
|
|
|
|
free_string_array(dirs);
|
|
|
|
return return_value;
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_choose_zip_menu()
|
|
|
|
{
|
|
|
|
if (ensure_root_path_mounted("SDCARD:") != 0) {
|
|
|
|
LOGE ("Can't mount /sdcard\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* headers[] = { "Choose a zip to apply",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
char* file = choose_file_menu("/sdcard/", ".zip", headers);
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
char sdcard_package_file[1024];
|
|
|
|
strcpy(sdcard_package_file, "SDCARD:");
|
|
|
|
strcat(sdcard_package_file, file + strlen("/sdcard/"));
|
2010-07-15 04:01:21 +00:00
|
|
|
static char* confirm_install = "Confirm install?";
|
|
|
|
static char confirm[PATH_MAX];
|
|
|
|
sprintf(confirm, "Yes - Install %s", basename(file));
|
|
|
|
if (confirm_selection(confirm_install, confirm))
|
|
|
|
install_zip(sdcard_package_file);
|
2010-02-22 05:10:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 19:39:07 +00:00
|
|
|
// This was pulled from bionic: The default system command always looks
|
|
|
|
// for shell in /system/bin/sh. This is bad.
|
|
|
|
#define _PATH_BSHELL "/sbin/sh"
|
2010-03-13 07:21:12 +00:00
|
|
|
|
2010-02-25 19:39:07 +00:00
|
|
|
extern char **environ;
|
|
|
|
int
|
2010-03-13 07:21:12 +00:00
|
|
|
__system(const char *command)
|
2010-02-25 19:39:07 +00:00
|
|
|
{
|
|
|
|
pid_t pid;
|
2010-02-25 22:53:57 +00:00
|
|
|
sig_t intsave, quitsave;
|
|
|
|
sigset_t mask, omask;
|
|
|
|
int pstat;
|
|
|
|
char *argp[] = {"sh", "-c", NULL, NULL};
|
|
|
|
|
|
|
|
if (!command) /* just checking... */
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
argp[2] = (char *)command;
|
|
|
|
|
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGCHLD);
|
|
|
|
sigprocmask(SIG_BLOCK, &mask, &omask);
|
|
|
|
switch (pid = vfork()) {
|
|
|
|
case -1: /* error */
|
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
|
|
|
return(-1);
|
|
|
|
case 0: /* child */
|
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
|
|
|
execve(_PATH_BSHELL, argp, environ);
|
2010-02-25 19:39:07 +00:00
|
|
|
_exit(127);
|
|
|
|
}
|
|
|
|
|
2010-02-25 22:53:57 +00:00
|
|
|
intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN);
|
|
|
|
quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
|
|
|
|
pid = waitpid(pid, (int *)&pstat, 0);
|
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
|
|
|
(void)bsd_signal(SIGINT, intsave);
|
|
|
|
(void)bsd_signal(SIGQUIT, quitsave);
|
|
|
|
return (pid == -1 ? -1 : pstat);
|
2010-02-25 19:39:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
void show_nandroid_restore_menu()
|
|
|
|
{
|
2010-03-13 01:43:26 +00:00
|
|
|
if (ensure_root_path_mounted("SDCARD:") != 0) {
|
|
|
|
LOGE ("Can't mount /sdcard\n");
|
2010-03-13 07:21:12 +00:00
|
|
|
return;
|
2010-03-13 01:43:26 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 05:10:25 +00:00
|
|
|
static char* headers[] = { "Choose an image to restore",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-02-25 22:51:05 +00:00
|
|
|
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers);
|
2010-02-22 05:10:25 +00:00
|
|
|
if (file == NULL)
|
|
|
|
return;
|
2010-07-15 04:01:21 +00:00
|
|
|
|
|
|
|
if (confirm_selection("Confirm restore?", "Yes - Restore"))
|
|
|
|
nandroid_restore(file, 1, 1, 1, 1, 1);
|
2010-02-26 22:14:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 05:42:30 +00:00
|
|
|
void show_mount_usb_storage_menu()
|
2010-02-26 22:14:23 +00:00
|
|
|
{
|
2010-06-20 16:42:47 +00:00
|
|
|
char command[PATH_MAX];
|
|
|
|
sprintf(command, "echo %s > /sys/devices/platform/usb_mass_storage/lun0/file", SDCARD_DEVICE_PRIMARY);
|
|
|
|
__system(command);
|
2010-02-26 22:14:23 +00:00
|
|
|
static char* headers[] = { "USB Mass Storage device",
|
|
|
|
"Leaving this menu unmount",
|
|
|
|
"your SD card from your PC.",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static char* list[] = { "Unmount", NULL };
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int chosen_item = get_menu_selection(headers, list, 0);
|
|
|
|
if (chosen_item == GO_BACK || chosen_item == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-16 20:34:51 +00:00
|
|
|
__system("echo '' > /sys/devices/platform/usb_mass_storage/lun0/file");
|
|
|
|
__system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable");
|
2010-02-27 01:44:33 +00:00
|
|
|
}
|
2010-03-07 21:39:21 +00:00
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
int confirm_selection(const char* title, const char* confirm)
|
2010-03-19 21:37:11 +00:00
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
struct stat info;
|
|
|
|
if (0 == stat("/sdcard/clockworkmod/.no_confirm", &info))
|
|
|
|
return 1;
|
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
char* confirm_headers[] = { title, " THIS CAN NOT BE UNDONE.", "", NULL };
|
|
|
|
char* items[] = { "No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
2010-07-15 01:38:02 +00:00
|
|
|
confirm, //" Yes -- wipe partition", // [7
|
2010-07-15 04:01:21 +00:00
|
|
|
"No",
|
|
|
|
"No",
|
|
|
|
"No",
|
2010-03-19 21:37:11 +00:00
|
|
|
NULL };
|
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
int chosen_item = get_menu_selection(confirm_headers, items, 0);
|
2010-03-19 21:37:11 +00:00
|
|
|
return chosen_item == 7;
|
|
|
|
}
|
|
|
|
|
2010-04-18 23:00:21 +00:00
|
|
|
int format_non_mtd_device(const char* root)
|
2010-03-31 06:29:43 +00:00
|
|
|
{
|
2010-04-19 01:06:24 +00:00
|
|
|
// if this is SDEXT:, don't worry about it.
|
|
|
|
if (0 == strcmp(root, "SDEXT:"))
|
|
|
|
{
|
|
|
|
struct stat st;
|
2010-06-20 16:42:47 +00:00
|
|
|
if (0 != stat(SDEXT_DEVICE, &st))
|
2010-04-19 01:06:24 +00:00
|
|
|
{
|
|
|
|
ui_print("No app2sd partition found. Skipping format of /sd-ext.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-04-18 23:00:21 +00:00
|
|
|
|
2010-03-31 06:29:43 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
translate_root_path(root, path, PATH_MAX);
|
|
|
|
if (0 != ensure_root_path_mounted(root))
|
|
|
|
{
|
|
|
|
ui_print("Error mounting %s!\n", path);
|
2010-06-23 07:02:14 +00:00
|
|
|
ui_print("Skipping format...\n");
|
|
|
|
return 0;
|
2010-03-31 06:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char tmp[PATH_MAX];
|
|
|
|
sprintf(tmp, "rm -rf %s/*", path);
|
|
|
|
__system(tmp);
|
|
|
|
sprintf(tmp, "rm -rf %s/.*", path);
|
|
|
|
__system(tmp);
|
|
|
|
|
|
|
|
ensure_root_path_unmounted(root);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MOUNTABLE_COUNT 5
|
|
|
|
#define MTD_COUNT 4
|
|
|
|
#define MMC_COUNT 2
|
2010-03-15 05:42:30 +00:00
|
|
|
|
2010-03-19 20:34:36 +00:00
|
|
|
void show_partition_menu()
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
static char* headers[] = { "Mounts and Storage Menu",
|
2010-03-15 05:42:30 +00:00
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef char* string;
|
2010-03-19 21:37:11 +00:00
|
|
|
string mounts[MOUNTABLE_COUNT][3] = {
|
|
|
|
{ "mount /system", "unmount /system", "SYSTEM:" },
|
|
|
|
{ "mount /data", "unmount /data", "DATA:" },
|
|
|
|
{ "mount /cache", "unmount /cache", "CACHE:" },
|
2010-03-31 06:29:43 +00:00
|
|
|
{ "mount /sdcard", "unmount /sdcard", "SDCARD:" },
|
|
|
|
{ "mount /sd-ext", "unmount /sd-ext", "SDEXT:" }
|
2010-03-15 05:42:30 +00:00
|
|
|
};
|
|
|
|
|
2010-03-19 21:37:11 +00:00
|
|
|
string mtds[MTD_COUNT][2] = {
|
2010-03-31 06:29:43 +00:00
|
|
|
{ "format boot", "BOOT:" },
|
|
|
|
{ "format system", "SYSTEM:" },
|
|
|
|
{ "format data", "DATA:" },
|
|
|
|
{ "format cache", "CACHE:" },
|
|
|
|
};
|
|
|
|
|
|
|
|
string mmcs[MMC_COUNT][3] = {
|
|
|
|
{ "format sdcard", "SDCARD:" },
|
2010-04-05 22:44:57 +00:00
|
|
|
{ "format sd-ext", "SDEXT:" }
|
2010-03-19 21:37:11 +00:00
|
|
|
};
|
2010-07-15 01:38:02 +00:00
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
static char* confirm_format = "Confirm format?";
|
2010-07-15 01:38:02 +00:00
|
|
|
static char* confirm = "Yes - Format";
|
2010-03-19 21:37:11 +00:00
|
|
|
|
2010-03-15 05:42:30 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2010-03-19 20:34:36 +00:00
|
|
|
int ismounted[MOUNTABLE_COUNT];
|
2010-03-15 05:42:30 +00:00
|
|
|
int i;
|
2010-03-31 06:29:43 +00:00
|
|
|
static string options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT + 1 + 1]; // mountables, format mtds, format mmcs, usb storage, null
|
2010-03-19 20:34:36 +00:00
|
|
|
for (i = 0; i < MOUNTABLE_COUNT; i++)
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
2010-03-19 21:37:11 +00:00
|
|
|
ismounted[i] = is_root_path_mounted(mounts[i][2]);
|
2010-03-15 05:42:30 +00:00
|
|
|
options[i] = ismounted[i] ? mounts[i][1] : mounts[i][0];
|
|
|
|
}
|
2010-03-19 20:34:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MTD_COUNT; i++)
|
|
|
|
{
|
2010-03-19 21:37:11 +00:00
|
|
|
options[MOUNTABLE_COUNT + i] = mtds[i][0];
|
2010-03-19 20:34:36 +00:00
|
|
|
}
|
2010-03-31 06:29:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MMC_COUNT; i++)
|
|
|
|
{
|
|
|
|
options[MOUNTABLE_COUNT + MTD_COUNT + i] = mmcs[i][0];
|
|
|
|
}
|
2010-03-15 05:42:30 +00:00
|
|
|
|
2010-03-31 06:29:43 +00:00
|
|
|
options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT] = "mount USB storage";
|
|
|
|
options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT + 1] = NULL;
|
2010-03-15 05:42:30 +00:00
|
|
|
|
|
|
|
int chosen_item = get_menu_selection(headers, options, 0);
|
|
|
|
if (chosen_item == GO_BACK)
|
|
|
|
break;
|
2010-03-31 06:29:43 +00:00
|
|
|
if (chosen_item == MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT)
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
|
|
|
show_mount_usb_storage_menu();
|
|
|
|
}
|
2010-03-19 20:34:36 +00:00
|
|
|
else if (chosen_item < MOUNTABLE_COUNT)
|
2010-03-15 05:42:30 +00:00
|
|
|
{
|
|
|
|
if (ismounted[chosen_item])
|
|
|
|
{
|
2010-03-19 21:37:11 +00:00
|
|
|
if (0 != ensure_root_path_unmounted(mounts[chosen_item][2]))
|
|
|
|
ui_print("Error unmounting %s!\n", mounts[chosen_item][2]);
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-19 21:37:11 +00:00
|
|
|
if (0 != ensure_root_path_mounted(mounts[chosen_item][2]))
|
|
|
|
ui_print("Error mounting %s!\n", mounts[chosen_item][2]);
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-19 20:34:36 +00:00
|
|
|
else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT)
|
|
|
|
{
|
|
|
|
chosen_item = chosen_item - MOUNTABLE_COUNT;
|
2010-07-15 01:38:02 +00:00
|
|
|
if (!confirm_selection(confirm_format, confirm))
|
2010-03-19 21:37:11 +00:00
|
|
|
continue;
|
|
|
|
ui_print("Formatting %s...\n", mtds[chosen_item][1]);
|
2010-03-31 06:29:43 +00:00
|
|
|
if (0 != format_root_device(mtds[chosen_item][1]))
|
|
|
|
ui_print("Error formatting %s!\n", mtds[chosen_item][1]);
|
|
|
|
else
|
|
|
|
ui_print("Done.\n");
|
|
|
|
}
|
|
|
|
else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT)
|
|
|
|
{
|
|
|
|
chosen_item = chosen_item - MOUNTABLE_COUNT - MTD_COUNT;
|
2010-07-15 01:38:02 +00:00
|
|
|
if (!confirm_selection(confirm_format, confirm))
|
2010-03-31 06:29:43 +00:00
|
|
|
continue;
|
|
|
|
ui_print("Formatting %s...\n", mmcs[chosen_item][1]);
|
2010-04-18 23:00:21 +00:00
|
|
|
if (0 != format_non_mtd_device(mmcs[chosen_item][1]))
|
2010-03-31 06:29:43 +00:00
|
|
|
ui_print("Error formatting %s!\n", mmcs[chosen_item][1]);
|
|
|
|
else
|
|
|
|
ui_print("Done.\n");
|
2010-03-19 20:34:36 +00:00
|
|
|
}
|
2010-03-15 05:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-07 22:10:26 +00:00
|
|
|
#define EXTENDEDCOMMAND_SCRIPT "/cache/recovery/extendedcommand"
|
2010-03-07 21:39:21 +00:00
|
|
|
|
2010-03-07 22:10:26 +00:00
|
|
|
int extendedcommand_file_exists()
|
|
|
|
{
|
|
|
|
struct stat file_info;
|
|
|
|
return 0 == stat(EXTENDEDCOMMAND_SCRIPT, &file_info);
|
|
|
|
}
|
2010-03-07 21:39:21 +00:00
|
|
|
|
2010-03-12 06:17:43 +00:00
|
|
|
int run_script_from_buffer(char* script_data, int script_len, char* filename)
|
2010-03-07 22:10:26 +00:00
|
|
|
{
|
2010-03-07 21:39:21 +00:00
|
|
|
/* Parse the script. Note that the script and parse tree are never freed.
|
|
|
|
*/
|
|
|
|
const AmCommandList *commands = parseAmendScript(script_data, script_len);
|
|
|
|
if (commands == NULL) {
|
|
|
|
printf("Syntax error in update script\n");
|
|
|
|
return 1;
|
|
|
|
} else {
|
2010-03-07 22:10:26 +00:00
|
|
|
printf("Parsed %.*s\n", script_len, filename);
|
2010-03-07 21:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute the script.
|
|
|
|
*/
|
|
|
|
int ret = execCommandList((ExecContext *)1, commands);
|
|
|
|
if (ret != 0) {
|
|
|
|
int num = ret;
|
2010-03-13 07:21:12 +00:00
|
|
|
char *line = NULL, *next = script_data;
|
2010-03-07 21:39:21 +00:00
|
|
|
while (next != NULL && ret-- > 0) {
|
|
|
|
line = next;
|
|
|
|
next = memchr(line, '\n', script_data + script_len - line);
|
|
|
|
if (next != NULL) *next++ = '\0';
|
|
|
|
}
|
|
|
|
printf("Failure at line %d:\n%s\n", num, next ? line : "(not found)");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-07 22:10:26 +00:00
|
|
|
|
2010-04-04 06:28:39 +00:00
|
|
|
int run_script(char* filename)
|
2010-03-12 06:17:43 +00:00
|
|
|
{
|
|
|
|
struct stat file_info;
|
|
|
|
if (0 != stat(filename, &file_info)) {
|
|
|
|
printf("Error executing stat on file: %s\n", filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int script_len = file_info.st_size;
|
2010-03-23 18:44:33 +00:00
|
|
|
char* script_data = (char*)malloc(script_len + 1);
|
2010-03-12 06:17:43 +00:00
|
|
|
FILE *file = fopen(filename, "rb");
|
|
|
|
fread(script_data, script_len, 1, file);
|
2010-03-23 18:44:33 +00:00
|
|
|
// supposedly not necessary, but let's be safe.
|
|
|
|
script_data[script_len] = '\0';
|
2010-03-12 06:17:43 +00:00
|
|
|
fclose(file);
|
2010-06-21 15:16:19 +00:00
|
|
|
LOGI("Running script:\n");
|
|
|
|
LOGI("\n%s\n", script_data);
|
2010-03-12 06:17:43 +00:00
|
|
|
|
2010-04-19 01:06:24 +00:00
|
|
|
int ret = run_script_from_buffer(script_data, script_len, filename);
|
2010-04-02 23:46:21 +00:00
|
|
|
free(script_data);
|
|
|
|
return ret;
|
2010-03-12 06:17:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 22:10:26 +00:00
|
|
|
int run_and_remove_extendedcommand()
|
|
|
|
{
|
2010-04-04 06:28:39 +00:00
|
|
|
char tmp[PATH_MAX];
|
|
|
|
sprintf(tmp, "cp %s /tmp/%s", EXTENDEDCOMMAND_SCRIPT, basename(EXTENDEDCOMMAND_SCRIPT));
|
|
|
|
__system(tmp);
|
|
|
|
remove(EXTENDEDCOMMAND_SCRIPT);
|
2010-03-09 03:22:41 +00:00
|
|
|
int i = 0;
|
|
|
|
for (i = 20; i > 0; i--) {
|
|
|
|
ui_print("Waiting for SD Card to mount (%ds)\n", i);
|
|
|
|
if (ensure_root_path_mounted("SDCARD:") == 0) {
|
|
|
|
ui_print("SD Card mounted...\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
2010-07-15 07:10:08 +00:00
|
|
|
remove("/sdcard/clockworkmod/.recoverycheckpoint");
|
2010-03-09 03:22:41 +00:00
|
|
|
if (i == 0) {
|
|
|
|
ui_print("Timed out waiting for SD card... continuing anyways.");
|
|
|
|
}
|
|
|
|
|
2010-04-04 06:28:39 +00:00
|
|
|
sprintf(tmp, "/tmp/%s", basename(EXTENDEDCOMMAND_SCRIPT));
|
|
|
|
return run_script(tmp);
|
2010-03-07 22:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int amend_main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
printf("Usage: amend <script>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RecoveryCommandContext ctx = { NULL };
|
|
|
|
if (register_update_commands(&ctx)) {
|
|
|
|
LOGE("Can't install update commands\n");
|
|
|
|
}
|
2010-04-04 06:28:39 +00:00
|
|
|
return run_script(argv[1]);
|
2010-03-08 22:09:35 +00:00
|
|
|
}
|
2010-03-19 20:34:36 +00:00
|
|
|
|
2010-03-26 01:19:23 +00:00
|
|
|
void show_nandroid_advanced_restore_menu()
|
|
|
|
{
|
|
|
|
if (ensure_root_path_mounted("SDCARD:") != 0) {
|
|
|
|
LOGE ("Can't mount /sdcard\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* advancedheaders[] = { "Choose an image to restore",
|
|
|
|
"",
|
|
|
|
"Choose an image to restore",
|
|
|
|
"first. The next menu will",
|
|
|
|
"you more options.",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, advancedheaders);
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static char* headers[] = { "Nandroid Advanced Restore",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static char* list[] = { "Restore boot",
|
|
|
|
"Restore system",
|
|
|
|
"Restore data",
|
|
|
|
"Restore cache",
|
2010-04-01 19:20:39 +00:00
|
|
|
"Restore sd-ext",
|
2010-03-26 01:19:23 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-07-15 04:01:21 +00:00
|
|
|
|
|
|
|
static char* confirm_restore = "Confirm restore?";
|
|
|
|
|
2010-03-26 01:19:23 +00:00
|
|
|
int chosen_item = get_menu_selection(headers, list, 0);
|
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore boot"))
|
|
|
|
nandroid_restore(file, 1, 0, 0, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore system"))
|
|
|
|
nandroid_restore(file, 0, 1, 0, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore data"))
|
|
|
|
nandroid_restore(file, 0, 0, 1, 0, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore cache"))
|
|
|
|
nandroid_restore(file, 0, 0, 0, 1, 0);
|
2010-03-26 01:19:23 +00:00
|
|
|
break;
|
2010-04-18 23:00:21 +00:00
|
|
|
case 4:
|
2010-07-15 04:01:21 +00:00
|
|
|
if (confirm_selection(confirm_restore, "Yes - Restore sd-ext"))
|
|
|
|
nandroid_restore(file, 0, 0, 0, 0, 1);
|
2010-04-18 23:00:21 +00:00
|
|
|
break;
|
2010-03-26 01:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-19 20:34:36 +00:00
|
|
|
void show_nandroid_menu()
|
|
|
|
{
|
|
|
|
static char* headers[] = { "Nandroid",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static char* list[] = { "Backup",
|
|
|
|
"Restore",
|
2010-03-26 01:19:23 +00:00
|
|
|
"Advanced Restore",
|
2010-03-19 20:34:36 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int chosen_item = get_menu_selection(headers, list, 0);
|
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
char backup_path[PATH_MAX];
|
2010-03-27 22:26:11 +00:00
|
|
|
time_t t = time(NULL);
|
|
|
|
struct tm *tmp = localtime(&t);
|
|
|
|
if (tmp == NULL)
|
|
|
|
{
|
|
|
|
struct timeval tp;
|
|
|
|
gettimeofday(&tp, NULL);
|
|
|
|
sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
|
|
|
|
}
|
2010-03-19 20:34:36 +00:00
|
|
|
nandroid_backup(backup_path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
show_nandroid_restore_menu();
|
|
|
|
break;
|
2010-03-26 01:19:23 +00:00
|
|
|
case 2:
|
|
|
|
show_nandroid_advanced_restore_menu();
|
|
|
|
break;
|
2010-03-19 20:34:36 +00:00
|
|
|
}
|
2010-03-19 21:51:45 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 19:46:55 +00:00
|
|
|
void wipe_battery_stats()
|
|
|
|
{
|
|
|
|
ensure_root_path_mounted("DATA:");
|
|
|
|
remove("/data/system/batterystats.bin");
|
|
|
|
ensure_root_path_unmounted("DATA:");
|
|
|
|
}
|
|
|
|
|
2010-03-19 21:51:45 +00:00
|
|
|
void show_advanced_menu()
|
|
|
|
{
|
|
|
|
static char* headers[] = { "Advanced and Debugging Menu",
|
|
|
|
"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-04-07 06:04:52 +00:00
|
|
|
static char* list[] = { "Reboot Recovery",
|
2010-06-21 20:45:51 +00:00
|
|
|
"Wipe Dalvik Cache",
|
2010-05-01 19:46:55 +00:00
|
|
|
"Wipe Battery Stats",
|
2010-06-20 16:42:47 +00:00
|
|
|
"Report Error",
|
2010-04-07 06:04:52 +00:00
|
|
|
"Key Test",
|
2010-08-23 23:13:14 +00:00
|
|
|
"Partition SD Card",
|
|
|
|
"Fix Permissions",
|
2010-03-19 21:51:45 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int chosen_item = get_menu_selection(headers, list, 0);
|
|
|
|
if (chosen_item == GO_BACK)
|
|
|
|
break;
|
|
|
|
switch (chosen_item)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-04-07 06:04:52 +00:00
|
|
|
__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "recovery");
|
|
|
|
break;
|
|
|
|
case 1:
|
2010-07-15 04:01:21 +00:00
|
|
|
{
|
2010-06-21 20:45:51 +00:00
|
|
|
if (0 != ensure_root_path_mounted("DATA:"))
|
|
|
|
break;
|
2010-08-07 19:17:13 +00:00
|
|
|
ensure_root_path_mounted("SDEXT:");
|
|
|
|
ensure_root_path_mounted("CACHE:");
|
|
|
|
if (confirm_selection( "Confirm wipe?", "Yes - Wipe Dalvik Cache")) {
|
2010-07-15 04:01:21 +00:00
|
|
|
__system("rm -r /data/dalvik-cache");
|
2010-08-07 19:17:13 +00:00
|
|
|
__system("rm -r /cache/dalvik-cache");
|
|
|
|
__system("rm -r /sd-ext/dalvik-cache");
|
|
|
|
}
|
2010-06-21 20:45:51 +00:00
|
|
|
ensure_root_path_unmounted("DATA:");
|
2010-08-07 19:17:13 +00:00
|
|
|
ui_print("Dalvik Cache wiped.\n");
|
2010-05-01 19:46:55 +00:00
|
|
|
break;
|
2010-07-15 04:01:21 +00:00
|
|
|
}
|
2010-05-01 19:46:55 +00:00
|
|
|
case 2:
|
2010-07-15 04:01:21 +00:00
|
|
|
{
|
|
|
|
if (confirm_selection( "Confirm wipe?", "Yes - Wipe Battery Stats"))
|
|
|
|
wipe_battery_stats();
|
2010-06-20 16:42:47 +00:00
|
|
|
break;
|
2010-07-15 04:01:21 +00:00
|
|
|
}
|
2010-06-20 16:42:47 +00:00
|
|
|
case 3:
|
2010-06-21 20:45:51 +00:00
|
|
|
handle_failure(1);
|
|
|
|
break;
|
|
|
|
case 4:
|
2010-03-19 21:51:45 +00:00
|
|
|
{
|
|
|
|
ui_print("Outputting key codes.\n");
|
|
|
|
ui_print("Go back to end debugging.\n");
|
|
|
|
int key;
|
|
|
|
int action;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
key = ui_wait_key();
|
|
|
|
action = device_handle_key(key, 1);
|
|
|
|
ui_print("Key: %d\n", key);
|
|
|
|
}
|
|
|
|
while (action != GO_BACK);
|
|
|
|
}
|
2010-08-17 23:55:38 +00:00
|
|
|
case 5:
|
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
static char* ext_sizes[] = { "128M",
|
|
|
|
"256M",
|
|
|
|
"512M",
|
|
|
|
"1024M",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
static char* swap_sizes[] = { "0M",
|
|
|
|
"32M",
|
|
|
|
"64M",
|
|
|
|
"128M",
|
|
|
|
"256M",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
static char* ext_headers[] = { "Ext Size", "", NULL };
|
|
|
|
static char* swap_headers[] = { "Swap Size", "", NULL };
|
|
|
|
|
|
|
|
int ext_size = get_menu_selection(ext_headers, ext_sizes, 0);
|
|
|
|
if (ext_size == GO_BACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int swap_size = get_menu_selection(swap_headers, swap_sizes, 0);
|
|
|
|
if (swap_size == GO_BACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char sddevice[256];
|
|
|
|
const RootInfo *ri = get_root_info_for_path("SDCARD:");
|
|
|
|
strcpy(sddevice, ri->device);
|
|
|
|
// we only want the mmcblk, not the partition
|
|
|
|
sddevice[strlen("/dev/block/mmcblkX")] = NULL;
|
|
|
|
char cmd[PATH_MAX];
|
|
|
|
setenv("SDPATH", sddevice, 1);
|
|
|
|
sprintf(cmd, "sdparted -es %s -ss %s -efs ext3 -s", ext_sizes[ext_size], swap_sizes[swap_size]);
|
|
|
|
ui_print("Partitioning SD Card... please wait...\n");
|
|
|
|
if (0 == __system(cmd))
|
|
|
|
ui_print("Done!\n");
|
|
|
|
else
|
|
|
|
ui_print("An error occured while partitioning your SD Card. Please see /tmp/recovery.log for more details.\n");
|
2010-08-17 23:55:38 +00:00
|
|
|
}
|
2010-08-18 05:21:53 +00:00
|
|
|
case 6:
|
|
|
|
{
|
2010-08-23 23:13:14 +00:00
|
|
|
ensure_root_path_mounted("SYSTEM:");
|
|
|
|
ensure_root_path_mounted("DATA:");
|
|
|
|
ui_print("Fixing permissions...\n");
|
|
|
|
__system("fix_permissions");
|
|
|
|
ui_print("Done!\n");
|
2010-08-18 05:21:53 +00:00
|
|
|
}
|
2010-03-19 21:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 22:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_fstab_root(char *root_path, FILE *file)
|
|
|
|
{
|
|
|
|
RootInfo *info = get_root_info_for_path(root_path);
|
2010-06-20 20:16:06 +00:00
|
|
|
if (info == NULL) {
|
|
|
|
LOGW("Unable to get root info for %s during fstab generation!", root_path);
|
2010-06-20 16:42:47 +00:00
|
|
|
return;
|
2010-06-20 20:16:06 +00:00
|
|
|
}
|
2010-06-14 22:02:48 +00:00
|
|
|
MtdPartition *mtd = get_root_mtd_partition(root_path);
|
|
|
|
if (mtd != NULL)
|
|
|
|
{
|
|
|
|
fprintf(file, "/dev/block/mtdblock%d ", mtd->device_index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-21 19:27:43 +00:00
|
|
|
// only SDCARD: seems to be using device2.
|
|
|
|
// and mmcblkXp1 is the fallback/device2.
|
|
|
|
// However, generally, mmcblkXp1 is usually where the
|
|
|
|
// FAT partition is located... so favor that.
|
|
|
|
if (NULL == info->device2)
|
|
|
|
fprintf(file, "%s ", info->device);
|
|
|
|
else
|
|
|
|
fprintf(file, "%s ", info->device2);
|
2010-06-14 22:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(file, "%s ", info->mount_point);
|
2010-07-23 03:14:44 +00:00
|
|
|
fprintf(file, "%s %s\n", info->filesystem, info->filesystem_options == NULL ? "rw" : info->filesystem_options);
|
2010-06-14 22:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void create_fstab()
|
|
|
|
{
|
2010-06-23 07:02:14 +00:00
|
|
|
__system("touch /etc/mtab");
|
2010-06-14 22:02:48 +00:00
|
|
|
FILE *file = fopen("/etc/fstab", "w");
|
2010-06-20 20:16:06 +00:00
|
|
|
if (file == NULL) {
|
|
|
|
LOGW("Unable to create /etc/fstab!");
|
2010-06-20 16:42:47 +00:00
|
|
|
return;
|
2010-06-20 20:16:06 +00:00
|
|
|
}
|
2010-06-14 22:02:48 +00:00
|
|
|
write_fstab_root("CACHE:", file);
|
|
|
|
write_fstab_root("DATA:", file);
|
2010-06-20 20:16:06 +00:00
|
|
|
#ifdef HAS_DATADATA
|
|
|
|
write_fstab_root("DATADATA:", file);
|
|
|
|
#endif
|
2010-06-14 22:02:48 +00:00
|
|
|
write_fstab_root("SYSTEM:", file);
|
|
|
|
write_fstab_root("SDCARD:", file);
|
|
|
|
write_fstab_root("SDEXT:", file);
|
|
|
|
fclose(file);
|
2010-06-20 16:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_failure(int ret)
|
|
|
|
{
|
|
|
|
if (ret == 0)
|
|
|
|
return;
|
|
|
|
if (0 != ensure_root_path_mounted("SDCARD:"))
|
|
|
|
return;
|
2010-06-20 20:16:06 +00:00
|
|
|
mkdir("/sdcard/clockworkmod", S_IRWXU);
|
|
|
|
__system("cp /tmp/recovery.log /sdcard/clockworkmod/recovery.log");
|
2010-08-18 05:21:53 +00:00
|
|
|
ui_print("/tmp/recovery.log was copied to /sdcard/clockworkmod/recovery.log. Please open ROM Manager to report the issue.\n");
|
2010-03-19 20:34:36 +00:00
|
|
|
}
|