working erase_image and options in recovery now

This commit is contained in:
Koushik K. Dutta 2010-03-19 14:37:11 -07:00
parent 75b930f396
commit 16f0b49bea
5 changed files with 82 additions and 43 deletions

View File

@ -42,7 +42,7 @@ ifeq ($(TARGET_RECOVERY_UI_LIB),)
else
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UI_LIB)
endif
LOCAL_STATIC_LIBRARIES += libbusybox libclearsilverregex libmkyaffs2image libunyaffs libdump_image libflash_image libmtdutils
LOCAL_STATIC_LIBRARIES += libbusybox libclearsilverregex libmkyaffs2image libunyaffs liberase_image libdump_image libflash_image libmtdutils
LOCAL_STATIC_LIBRARIES += libamend
LOCAL_STATIC_LIBRARIES += libminzip libunz libmtdutils libmincrypt
LOCAL_STATIC_LIBRARIES += libminui libpixelflinger_static libpng libcutils
@ -50,7 +50,7 @@ LOCAL_STATIC_LIBRARIES += libstdc++ libc
include $(BUILD_EXECUTABLE)
RECOVERY_LINKS := amend busybox flash_image dump_image mkyaffs2image unyaffs
RECOVERY_LINKS := amend busybox flash_image dump_image mkyaffs2image unyaffs erase_image
# nc is provided by external/netcat
SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(RECOVERY_LINKS))
$(SYMLINKS): RECOVERY_BINARY := $(LOCAL_MODULE)

View File

@ -373,8 +373,33 @@ void show_mount_usb_storage_menu()
__system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable");
}
int confirm_format()
{
static char* title_headers[] = { "Confirm format?",
" THIS CAN NOT BE UNDONE.",
"",
NULL,
};
char* items[] = { " No",
" No",
" No",
" No",
" No",
" No",
" No",
" Yes -- wipe partition", // [7]
" No",
" No",
" No",
NULL };
int chosen_item = get_menu_selection(title_headers, items, 0);
return chosen_item == 7;
}
#define MOUNTABLE_COUNT 4
#define MTD_COUNT 3
#define MTD_COUNT 4
void show_partition_menu()
{
@ -384,13 +409,20 @@ void show_partition_menu()
};
typedef char* string;
string mounts[MOUNTABLE_COUNT][4] = {
{ "mount /system", "unmount /system", "format SYSTEM:", "SYSTEM:" },
{ "mount /data", "unmount /data", "format DATA:", "DATA:" },
{ "mount /cache", "unmount /cache", "format CACHE:", "CACHE:" },
{ "mount /sdcard", "unmount /sdcard", NULL, "SDCARD:" }
string mounts[MOUNTABLE_COUNT][3] = {
{ "mount /system", "unmount /system", "SYSTEM:" },
{ "mount /data", "unmount /data", "DATA:" },
{ "mount /cache", "unmount /cache", "CACHE:" },
{ "mount /sdcard", "unmount /sdcard", "SDCARD:" }
};
string mtds[MTD_COUNT][2] = {
{ "format system", "system" },
{ "format data", "data" },
{ "format cache", "cache" },
{ "format boot", "boot" }
};
for (;;)
{
int ismounted[MOUNTABLE_COUNT];
@ -398,13 +430,13 @@ void show_partition_menu()
static string options[MOUNTABLE_COUNT + MTD_COUNT + 1 + 1]; // mountables, format mtds, usb storage, null
for (i = 0; i < MOUNTABLE_COUNT; i++)
{
ismounted[i] = is_root_path_mounted(mounts[i][3]);
ismounted[i] = is_root_path_mounted(mounts[i][2]);
options[i] = ismounted[i] ? mounts[i][1] : mounts[i][0];
}
for (i = 0; i < MTD_COUNT; i++)
{
options[MOUNTABLE_COUNT + i] = mounts[i][2];
options[MOUNTABLE_COUNT + i] = mtds[i][0];
}
options[MOUNTABLE_COUNT + MTD_COUNT] = "mount USB storage";
@ -421,18 +453,24 @@ void show_partition_menu()
{
if (ismounted[chosen_item])
{
if (0 != ensure_root_path_unmounted(mounts[chosen_item][3]))
ui_print("Error unmounting %s!\n", mounts[chosen_item][3]);
if (0 != ensure_root_path_unmounted(mounts[chosen_item][2]))
ui_print("Error unmounting %s!\n", mounts[chosen_item][2]);
}
else
{
if (0 != ensure_root_path_mounted(mounts[chosen_item][3]))
ui_print("Error mounting %s!\n", mounts[chosen_item][3]);
if (0 != ensure_root_path_mounted(mounts[chosen_item][2]))
ui_print("Error mounting %s!\n", mounts[chosen_item][2]);
}
}
else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT)
{
chosen_item = chosen_item - MOUNTABLE_COUNT;
if (!confirm_format())
continue;
ui_print("Formatting %s...\n", mtds[chosen_item][1]);
if (0 != erase_image(mtds[chosen_item][1]))
ui_print("Error erasing %s!\n", mtds[chosen_item][1]);
ui_print("Done.\n");
}
}
}

View File

@ -29,8 +29,8 @@ LOCAL_SHARED_LIBRARIES := libcutils libc
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := erase_flash.c
LOCAL_MODULE := erase_flash
LOCAL_SRC_FILES := erase_image.c
LOCAL_MODULE := erase_image
LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES := libmtdutils
LOCAL_SHARED_LIBRARIES := libcutils libc
@ -42,24 +42,17 @@ LOCAL_MODULE := libflash_image
LOCAL_CFLAGS += -Dmain=flash_image_main
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := flash_image.c
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE := recovery_flash_image
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_STEM := flash_image
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_EXECUTABLES_UNSTRIPPED)
LOCAL_MODULE_PATH := $(TARGET_OUT)/utilities
LOCAL_STATIC_LIBRARIES := libmtdutils libcutils libc
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := dump_image.c
LOCAL_MODULE := libdump_image
LOCAL_CFLAGS += -Dmain=dump_image_main
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := erase_image.c
LOCAL_MODULE := liberase_image
LOCAL_CFLAGS += -Dmain=erase_image_main
include $(BUILD_STATIC_LIBRARY)
endif # TARGET_ARCH == arm
endif # !TARGET_SIMULATOR

View File

@ -32,9 +32,9 @@
#undef LOG_TAG
#endif
#define LOG_TAG "erase_flash"
#define LOG_TAG "erase_image"
void die(const char *msg, ...) {
static int die(const char *msg, ...) {
int err = errno;
va_list args;
va_start(args, msg);
@ -49,34 +49,40 @@ void die(const char *msg, ...) {
fprintf(stderr, "%s\n", buf);
LOGE("%s\n", buf);
exit(1);
return 3;
}
/* Erase a mtd partition */
int main(int argc, char **argv) {
int erase_image(char* partition_name) {
MtdWriteContext *out;
size_t erased;
size_t total_size;
size_t erase_size;
if (argc != 2) {
fprintf(stderr, "usage: %s <partition>\n", argv[0]);
return 2;
}
if (mtd_scan_partitions() <= 0) die("error scanning partitions");
const MtdPartition *partition = mtd_find_partition_by_name(argv[1]);
if (partition == NULL) die("can't find %s partition", argv[1]);
const MtdPartition *partition = mtd_find_partition_by_name(partition_name);
if (partition == NULL) return die("can't find %s partition", partition_name);
out = mtd_write_partition(partition);
if (out == NULL) die("could not estabilish write context for %s", argv[1]);
if (out == NULL) return die("could not estabilish write context for %s", partition_name);
// do the actual erase, -1 = full partition erase
erased = mtd_erase_blocks(out, -1);
// erased = bytes erased, if zero, something borked
if (!erased) die("error erasing %s", argv[1]);
if (!erased) return die("error erasing %s", partition_name);
return 0;
}
/* Erase a mtd partition */
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "usage: %s <partition>\n", argv[0]);
return 2;
}
return erase_image(argv[1]);
}

View File

@ -480,6 +480,8 @@ main(int argc, char **argv)
return flash_image_main(argc, argv);
if (strstr(argv[0], "dump_image") != NULL)
return dump_image_main(argc, argv);
if (strstr(argv[0], "erase_image") != NULL)
return erase_image_main(argc, argv);
if (strstr(argv[0], "mkyaffs2image") != NULL)
return mkyaffs2image_main(argc, argv);
if (strstr(argv[0], "unyaffs") != NULL)