Skip to content

Commit

Permalink
cwr 5
Browse files Browse the repository at this point in the history
Change-Id: I70cbb4df78b0bbc9d227d19aa6d9434eba2b540d
  • Loading branch information
koush committed Sep 6, 2011
1 parent bf5a60a commit 30a937a
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 34 deletions.
6 changes: 5 additions & 1 deletion Android.mk
Expand Up @@ -22,17 +22,21 @@ LOCAL_SRC_FILES := \
edifyscripting.c \
setprop.c

ADDITIONAL_RECOVERY_FILES := $(shell echo $$ADDITIONAL_RECOVERY_FILES)
LOCAL_SRC_FILES += $(ADDITIONAL_RECOVERY_FILES)

LOCAL_MODULE := recovery

LOCAL_FORCE_STATIC_EXECUTABLE := true

ifdef I_AM_KOUSH
RECOVERY_NAME := ClockworkMod Recovery
LOCAL_CFLAGS += -DI_AM_KOUSH
else
RECOVERY_NAME := CWM-based Recovery
endif

RECOVERY_VERSION := $(RECOVERY_NAME) v4.0.1.5
RECOVERY_VERSION := $(RECOVERY_NAME) v5.0.2.1

LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)"
RECOVERY_API_VERSION := 2
Expand Down
17 changes: 17 additions & 0 deletions edifyscripting.c
Expand Up @@ -233,7 +233,24 @@ Value* InstallZipFn(const char* name, State* state, int argc, Expr* argv[]) {
return StringValue(strdup(path));
}

Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
char* result = NULL;
if (argc != 1) {
return ErrorAbort(state, "%s() expects 1 args, got %d", name, argc);
}
char* path;
if (ReadArgs(state, argv, 1, &path) < 0) {
return NULL;
}

if (0 != ensure_path_mounted(path))
return StringValue(strdup(""));

return StringValue(strdup(path));
}

void RegisterRecoveryHooks() {
RegisterFunction("mount", MountFn);
RegisterFunction("format", FormatFn);
RegisterFunction("ui_print", UIPrintFn);
RegisterFunction("run_program", RunProgramFn);
Expand Down
111 changes: 105 additions & 6 deletions extendedcommands.c
Expand Up @@ -40,6 +40,7 @@
#include "flashutils/flashutils.h"
#include "edify/expr.h"
#include <libgen.h>
#include "mtdutils/mtdutils.h"


int signature_check_enabled = 1;
Expand Down Expand Up @@ -81,18 +82,24 @@ char* INSTALL_MENU_ITEMS[] = { "choose zip from sdcard",
"apply /sdcard/update.zip",
"toggle signature verification",
"toggle script asserts",
"choose zip from internal sdcard",
NULL };
#define ITEM_CHOOSE_ZIP 0
#define ITEM_APPLY_SDCARD 1
#define ITEM_SIG_CHECK 2
#define ITEM_ASSERTS 3
#define ITEM_CHOOSE_ZIP_INT 4

void show_install_update_menu()
{
static char* headers[] = { "Apply update from .zip file on SD card",
"",
NULL
};

if (volume_for_path("/emmc") == NULL)
INSTALL_MENU_ITEMS[ITEM_CHOOSE_ZIP_INT] = NULL;

for (;;)
{
int chosen_item = get_menu_selection(headers, INSTALL_MENU_ITEMS, 0, 0);
Expand All @@ -111,7 +118,10 @@ void show_install_update_menu()
break;
}
case ITEM_CHOOSE_ZIP:
show_choose_zip_menu();
show_choose_zip_menu("/sdcard/");
break;
case ITEM_CHOOSE_ZIP_INT:
show_choose_zip_menu("/emmc/");
break;
default:
return;
Expand Down Expand Up @@ -301,10 +311,10 @@ char* choose_file_menu(const char* directory, const char* fileExtensionOrDirecto
return return_value;
}

void show_choose_zip_menu()
void show_choose_zip_menu(const char *mount_point)
{
if (ensure_path_mounted("/sdcard") != 0) {
LOGE ("Can't mount /sdcard\n");
if (ensure_path_mounted(mount_point) != 0) {
LOGE ("Can't mount %s\n", mount_point);
return;
}

Expand All @@ -313,7 +323,7 @@ void show_choose_zip_menu()
NULL
};

char* file = choose_file_menu("/sdcard/", ".zip", headers);
char* file = choose_file_menu(mount_point, ".zip", headers);
if (file == NULL)
return;
static char* confirm_install = "Confirm install?";
Expand Down Expand Up @@ -419,6 +429,70 @@ int confirm_selection(const char* title, const char* confirm)
#define TUNE2FS_BIN "/sbin/tune2fs"
#define E2FSCK_BIN "/sbin/e2fsck"

int format_device(const char *device, const char *path, const char *fs_type) {
Volume* v = volume_for_path(path);
if (v == NULL) {
// no /sdcard? let's assume /data/media
if (strstr(path, "/sdcard") == path && is_data_media()) {
return format_unknown_device(NULL, path, NULL);
}
// silent failure for sd-ext
if (strcmp(path, "/sd-ext") == 0)
return -1;
LOGE("unknown volume \"%s\"\n", path);
return -1;
}
if (strcmp(fs_type, "ramdisk") == 0) {
// you can't format the ramdisk.
LOGE("can't format_volume \"%s\"", path);
return -1;
}

if (strcmp(v->mount_point, path) != 0) {
return format_unknown_device(v->device, path, NULL);
}

if (ensure_path_unmounted(path) != 0) {
LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point);
return -1;
}

if (strcmp(fs_type, "yaffs2") == 0 || strcmp(fs_type, "mtd") == 0) {
mtd_scan_partitions();
const MtdPartition* partition = mtd_find_partition_by_name(device);
if (partition == NULL) {
LOGE("format_volume: no MTD partition \"%s\"\n", device);
return -1;
}

MtdWriteContext *write = mtd_write_partition(partition);
if (write == NULL) {
LOGW("format_volume: can't open MTD \"%s\"\n", device);
return -1;
} else if (mtd_erase_blocks(write, -1) == (off_t) -1) {
LOGW("format_volume: can't erase MTD \"%s\"\n", device);
mtd_write_close(write);
return -1;
} else if (mtd_write_close(write)) {
LOGW("format_volume: can't close MTD \"%s\"\n",device);
return -1;
}
return 0;
}

if (strcmp(fs_type, "ext4") == 0) {
reset_ext4fs_info();
int result = make_ext4fs(device, NULL, NULL, 0, 0, 0);
if (result != 0) {
LOGE("format_volume: make_extf4fs failed on %s\n", device);
return -1;
}
return 0;
}

return format_unknown_device(device, path, fs_type);
}

int format_unknown_device(const char *device, const char* path, const char *fs_type)
{
LOGI("Formatting unknown device.\n");
Expand Down Expand Up @@ -738,7 +812,32 @@ int run_and_remove_extendedcommand()
ui_print("Timed out waiting for SD card... continuing anyways.");
}

ui_print("Verifying SD Card marker...\n");
struct stat st;
if (stat("/sdcard/clockworkmod/.salted_hash", &st) != 0) {
ui_print("SD Card marker not found...\n");
if (volume_for_path("/emmc") != NULL) {
ui_print("Checking Internal SD Card marker...\n");
ensure_path_unmounted("/sdcard");
if (ensure_path_mounted_at_mount_point("/emmc", "/sdcard") != 0) {
ui_print("Internal SD Card marker not found... continuing anyways.\n");
// unmount everything, and remount as normal
ensure_path_unmounted("/emmc");
ensure_path_unmounted("/sdcard");

ensure_path_mounted("/sdcard");
}
}
}

sprintf(tmp, "/tmp/%s", basename(EXTENDEDCOMMAND_SCRIPT));
int ret;
#ifdef I_AM_KOUSH
if (0 != (ret = before_run_script(tmp))) {
ui_print("Error processing ROM Manager script. Please verify you have ROM Manager v4.4.0.0 or higher installed.\n");
return ret;
}
#endif
return run_script(tmp);
}

Expand Down Expand Up @@ -910,9 +1009,9 @@ void show_advanced_menu()
__system("rm -r /data/dalvik-cache");
__system("rm -r /cache/dalvik-cache");
__system("rm -r /sd-ext/dalvik-cache");
ui_print("Dalvik Cache wiped.\n");
}
ensure_path_unmounted("/data");
ui_print("Dalvik Cache wiped.\n");
break;
}
case 2:
Expand Down
12 changes: 10 additions & 2 deletions nandroid-md5.sh
@@ -1,4 +1,12 @@
#!/sbin/sh
cd $1
md5sum *img > nandroid.md5
return $?
rm -f /tmp/nandroid.md5
md5sum * .* > /tmp/nandroid.md5
cp /tmp/nandroid.md5 .
# need this because wildcard seems to cause md5sum to return 1
if [ -f nandroid.md5 ]
then
return 0
else
return 1
fi

0 comments on commit 30a937a

Please sign in to comment.