recovery: Autodetection of device flash type

Detect flash type at runtime rather than requiring this to be set in the
device configuration. The detection is based on the existence of /proc/mtd,
/proc/emmc, or /dev/block/bml1.

Change-Id: I464962a567022c5862c249f06d36c2d1cddeacba
This commit is contained in:
Steve Kondik 2010-11-14 03:18:40 -05:00
parent 158d25cae4
commit 4123b58299
11 changed files with 298 additions and 146 deletions

View File

@ -73,16 +73,7 @@ else
endif
LOCAL_STATIC_LIBRARIES += libbusybox libclearsilverregex libmkyaffs2image libunyaffs liberase_image libdump_image libflash_image
ifdef BOARD_USES_BMLUTILS
BOARD_FLASH_LIBRARY := libbmlutils
else ifdef BOARD_USES_MMCUTILS
BOARD_FLASH_LIBRARY := libmmcutils
else
LOCAL_CFLAGS += -DBOARD_USES_MTDUTILS
BOARD_FLASH_LIBRARY := libmtdutils
endif
LOCAL_STATIC_LIBRARIES += $(BOARD_FLASH_LIBRARY)
LOCAL_STATIC_LIBRARIES += libflashutils libmtdutils libmmcutils libbmlutils
LOCAL_STATIC_LIBRARIES += libamend
LOCAL_STATIC_LIBRARIES += libminzip libunz libmincrypt

View File

@ -20,40 +20,39 @@
#include <signal.h>
#include <sys/wait.h>
int
__system(const char *command);
extern int __system(const char *command);
int restore_raw_partition(const char *partition, const char *filename)
int cmd_bml_restore_raw_partition(const char *partition, const char *filename)
{
char tmp[PATH_MAX];
sprintf("dd if=%s of=/dev/block/bml7 bs=4096", filename);
return __system(tmp);
}
int backup_raw_partition(const char *partition, const char *filename)
int cmd_bml_backup_raw_partition(const char *partition, const char *filename)
{
char tmp[PATH_MAX];
sprintf("dd of=%s if=/dev/block/bml7 bs=4096", filename);
return __system(tmp);
}
int erase_raw_partition(const char *partition)
int cmd_bml_erase_raw_partition(const char *partition)
{
// TODO: implement raw wipe
return 0;
}
int erase_partition(const char *partition, const char *filesystem)
int cmd_bml_erase_partition(const char *partition, const char *filesystem)
{
return -1;
}
int mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
int cmd_bml_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
{
return -1;
}
int get_partition_device(const char *partition, char *device)
int cmd_bml_get_partition_device(const char *partition, char *device)
{
return -1;
}

View File

@ -68,7 +68,7 @@ int install_zip(const char* packagefilepath)
ui_set_background(BACKGROUND_ICON_ERROR);
ui_print("Installation aborted.\n");
return 1;
}
}
#ifndef BOARD_HAS_NO_MISC_PARTITION
if (firmware_update_pending()) {
ui_print("\nReboot via menu to complete\ninstallation.\n");
@ -93,7 +93,7 @@ void show_install_update_menu()
{
static char* headers[] = { "Apply update from .zip file on SD card",
"",
NULL
NULL
};
for (;;)
{
@ -118,7 +118,7 @@ void show_install_update_menu()
default:
return;
}
}
}
@ -153,11 +153,11 @@ char** gather_files(const char* directory, const char* fileExtensionOrDirectory,
ui_print("Couldn't open directory.\n");
return NULL;
}
int extension_length = 0;
if (fileExtensionOrDirectory != NULL)
extension_length = strlen(fileExtensionOrDirectory);
int isCounting = 1;
i = 0;
for (pass = 0; pass < 2; pass++) {
@ -165,7 +165,7 @@ char** gather_files(const char* directory, const char* fileExtensionOrDirectory,
// skip hidden files
if (de->d_name[0] == '.')
continue;
// NULL means that we are gathering directories, so skip this
if (fileExtensionOrDirectory != NULL)
{
@ -187,13 +187,13 @@ char** gather_files(const char* directory, const char* fileExtensionOrDirectory,
if (!(S_ISDIR(info.st_mode)))
continue;
}
if (pass == 0)
{
total++;
continue;
}
files[i] = (char*) malloc(dirLen + strlen(de->d_name) + 2);
strcpy(files[i], directory);
strcat(files[i], de->d_name);
@ -290,7 +290,7 @@ char* choose_file_menu(const char* directory, const char* fileExtensionOrDirecto
break;
}
continue;
}
}
strcpy(ret, files[chosen_item - numDirs]);
return_value = ret;
break;
@ -312,9 +312,9 @@ void show_choose_zip_menu()
static char* headers[] = { "Choose a zip to apply",
"",
NULL
NULL
};
char* file = choose_file_menu("/sdcard/", ".zip", headers);
if (file == NULL)
return;
@ -328,57 +328,16 @@ void show_choose_zip_menu()
install_zip(sdcard_package_file);
}
// 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"
extern char **environ;
int
__system(const char *command)
{
pid_t pid;
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);
_exit(127);
}
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);
}
void show_nandroid_restore_menu()
{
if (ensure_root_path_mounted("SDCARD:") != 0) {
LOGE ("Can't mount /sdcard\n");
return;
}
static char* headers[] = { "Choose an image to restore",
"",
NULL
NULL
};
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers);
@ -398,18 +357,18 @@ void show_mount_usb_storage_menu()
"Leaving this menu unmount",
"your SD card from your PC.",
"",
NULL
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;
}
__system("echo '' > /sys/devices/platform/usb_mass_storage/lun0/file");
__system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable");
}
@ -465,7 +424,7 @@ int format_unknown_device(const char* root)
__system(tmp);
sprintf(tmp, "rm -rf %s/.*", path);
__system(tmp);
ensure_root_path_unmounted(root);
return 0;
}
@ -478,33 +437,33 @@ void show_partition_menu()
{
static char* headers[] = { "Mounts and Storage Menu",
"",
NULL
NULL
};
typedef char* string;
string mounts[MOUNTABLE_COUNT][3] = {
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:" },
{ "mount /sd-ext", "unmount /sd-ext", "SDEXT:" }
};
string mtds[MTD_COUNT][2] = {
{ "format boot", "BOOT:" },
{ "format system", "SYSTEM:" },
{ "format data", "DATA:" },
{ "format cache", "CACHE:" },
};
string mmcs[MMC_COUNT][3] = {
{ "format sdcard", "SDCARD:" },
{ "format sd-ext", "SDEXT:" }
{ "format sd-ext", "SDEXT:" }
};
static char* confirm_format = "Confirm format?";
static char* confirm = "Yes - Format";
for (;;)
{
int ismounted[MOUNTABLE_COUNT];
@ -515,20 +474,20 @@ void show_partition_menu()
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] = mtds[i][0];
}
for (i = 0; i < MMC_COUNT; i++)
{
options[MOUNTABLE_COUNT + MTD_COUNT + i] = mmcs[i][0];
}
options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT] = "mount USB storage";
options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT + 1] = NULL;
int chosen_item = get_menu_selection(headers, options, 0);
if (chosen_item == GO_BACK)
break;
@ -607,8 +566,8 @@ int run_script_from_buffer(char* script_data, int script_len, char* filename)
}
printf("Failure at line %d:\n%s\n", num, next ? line : "(not found)");
return 1;
}
}
return 0;
}
@ -619,7 +578,7 @@ int run_script(char* filename)
printf("Error executing stat on file: %s\n", filename);
return 1;
}
int script_len = file_info.st_size;
char* script_data = (char*)malloc(script_len + 1);
FILE *file = fopen(filename, "rb");
@ -654,14 +613,14 @@ int run_and_remove_extendedcommand()
if (i == 0) {
ui_print("Timed out waiting for SD card... continuing anyways.");
}
sprintf(tmp, "/tmp/%s", basename(EXTENDEDCOMMAND_SCRIPT));
return run_script(tmp);
}
int amend_main(int argc, char** argv)
{
if (argc != 2)
if (argc != 2)
{
printf("Usage: amend <script>\n");
return 0;
@ -740,10 +699,10 @@ void show_nandroid_menu()
{
static char* headers[] = { "Nandroid",
"",
NULL
NULL
};
static char* list[] = { "Backup",
static char* list[] = { "Backup",
"Restore",
"Advanced Restore",
NULL
@ -875,7 +834,7 @@ void show_advanced_menu()
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;
@ -925,9 +884,9 @@ void write_fstab_root(char *root_path, FILE *file)
{
fprintf(file, "%s ", info->device);
}
fprintf(file, "%s ", info->mount_point);
fprintf(file, "%s %s\n", info->filesystem, info->filesystem_options == NULL ? "rw" : info->filesystem_options);
fprintf(file, "%s %s\n", info->filesystem, info->filesystem_options == NULL ? "rw" : info->filesystem_options);
}
void create_fstab()
@ -958,4 +917,4 @@ void handle_failure(int ret)
mkdir("/sdcard/clockworkmod", S_IRWXU);
__system("cp /tmp/recovery.log /sdcard/clockworkmod/recovery.log");
ui_print("/tmp/recovery.log was copied to /sdcard/clockworkmod/recovery.log. Please open ROM Manager to report the issue.\n");
}
}

View File

@ -3,11 +3,19 @@ LOCAL_PATH := $(call my-dir)
ifneq ($(TARGET_SIMULATOR),true)
ifeq ($(TARGET_ARCH),arm)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := flashutils.c
LOCAL_MODULE := libflashutils
LOCAL_C_INCLUDES += bootable/recovery
LOCAL_STATIC_LIBRARIES := libmmcutils libmtdutils libbmlutils
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := flash_image.c
LOCAL_MODULE := flash_image
LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES := $(BOARD_FLASH_LIBRARY)
#LOCAL_STATIC_LIBRARIES += $(BOARD_FLASH_LIBRARY)
LOCAL_STATIC_LIBRARIES := libflashutils libmtdutils libmmcutils libbmlutils
LOCAL_SHARED_LIBRARIES := libcutils libc
include $(BUILD_EXECUTABLE)
@ -15,7 +23,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := dump_image.c
LOCAL_MODULE := dump_image
LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES := $(BOARD_FLASH_LIBRARY)
LOCAL_STATIC_LIBRARIES := libflashutils libmtdutils libmmcutils libbmlutils
LOCAL_SHARED_LIBRARIES := libcutils libc
include $(BUILD_EXECUTABLE)
@ -23,7 +31,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := erase_image.c
LOCAL_MODULE := erase_image
LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES := $(BOARD_FLASH_LIBRARY)
LOCAL_STATIC_LIBRARIES := libflashutils libmtdutils libmmcutils libbmlutils
LOCAL_SHARED_LIBRARIES := libcutils libc
include $(BUILD_EXECUTABLE)
@ -53,7 +61,7 @@ LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
LOCAL_MODULE_STEM := dump_image
LOCAL_STATIC_LIBRARIES := $(BOARD_FLASH_LIBRARY) libcutils libc
LOCAL_STATIC_LIBRARIES := libflashutils libmtdutils libmmcutils libbmlutils libcutils libc
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
@ -64,7 +72,7 @@ LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
LOCAL_MODULE_STEM := flash_image
LOCAL_STATIC_LIBRARIES := $(BOARD_FLASH_LIBRARY) libcutils libc
LOCAL_STATIC_LIBRARIES := libflashutils libmtdutils libmmcutils libbmlutils libcutils libc
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
@ -75,10 +83,9 @@ LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
LOCAL_MODULE_STEM := erase_image
LOCAL_STATIC_LIBRARIES := $(BOARD_FLASH_LIBRARY) libcutils libc
LOCAL_STATIC_LIBRARIES := libflashutils libmtdutils libmmcutils libbmlutils libcutils libc
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
endif # TARGET_ARCH == arm
endif # !TARGET_SIMULATOR

168
flashutils/flashutils.c Normal file
View File

@ -0,0 +1,168 @@
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include "flashutils/flashutils.h"
enum flash_type {
UNSUPPORTED = -1,
UNKNOWN = 0,
MTD = 1,
MMC = 2,
BML = 3
};
int the_flash_type = UNKNOWN;
int device_flash_type()
{
if (the_flash_type == UNKNOWN) {
if (access("/dev/block/bml1", F_OK) == 0) {
the_flash_type = BML;
} else if (access("/proc/emmc", F_OK) == 0) {
the_flash_type = MMC;
} else if (access("/proc/mtd", F_OK) == 0) {
the_flash_type = MTD;
} else {
the_flash_type = UNSUPPORTED;
}
}
return the_flash_type;
}
char* get_default_filesystem()
{
return device_flash_type() == MMC ? "ext3" : "yaffs2";
}
// 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"
extern char **environ;
int
__system(const char *command)
{
pid_t pid;
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);
_exit(127);
}
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);
}
int restore_raw_partition(const char *partition, const char *filename)
{
int type = device_flash_type();
switch (type) {
case MTD:
return cmd_mtd_restore_raw_partition(partition, filename);
case MMC:
return cmd_mmc_restore_raw_partition(partition, filename);
case BML:
return cmd_bml_restore_raw_partition(partition, filename);
default:
return -1;
}
}
int backup_raw_partition(const char *partition, const char *filename)
{
int type = device_flash_type();
switch (type) {
case MTD:
return cmd_mtd_backup_raw_partition(partition, filename);
case MMC:
return cmd_mmc_backup_raw_partition(partition, filename);
case BML:
return cmd_bml_backup_raw_partition(partition, filename);
default:
return -1;
}
}
int erase_raw_partition(const char *partition)
{
int type = device_flash_type();
switch (type) {
case MTD:
return cmd_mtd_erase_raw_partition(partition);
case MMC:
return cmd_mmc_erase_raw_partition(partition);
case BML:
return cmd_bml_erase_raw_partition(partition);
default:
return -1;
}
}
int erase_partition(const char *partition, const char *filesystem)
{
int type = device_flash_type();
switch (type) {
case MTD:
return cmd_mtd_erase_partition(partition, filesystem);
case MMC:
return cmd_mmc_erase_partition(partition, filesystem);
case BML:
return cmd_bml_erase_partition(partition, filesystem);
default:
return -1;
}
}
int mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
{
int type = device_flash_type();
switch (type) {
case MTD:
return cmd_mtd_mount_partition(partition, mount_point, filesystem, read_only);
case MMC:
return cmd_mmc_mount_partition(partition, mount_point, filesystem, read_only);
case BML:
return cmd_bml_mount_partition(partition, mount_point, filesystem, read_only);
default:
return -1;
}
}
int get_partition_device(const char *partition, char *device)
{
int type = device_flash_type();
switch (type) {
case MTD:
return cmd_mtd_get_partition_device(partition, device);
case MMC:
return cmd_mmc_get_partition_device(partition, device);
case BML:
return cmd_bml_get_partition_device(partition, device);
default:
return -1;
}
}

View File

@ -3,4 +3,36 @@ int backup_raw_partition(const char *partition, const char *filename);
int erase_raw_partition(const char *partition);
int erase_partition(const char *partition, const char *filesystem);
int mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only);
int get_partition_device(const char *partition, char *device);
int get_partition_device(const char *partition, char *device);
#define FLASH_MTD 0
#define FLASH_MMC 1
#define FLASH_BML 2
int is_mtd_device();
char* get_default_filesystem();
int __system(const char *command);
extern int cmd_mtd_restore_raw_partition(const char *partition, const char *filename);
extern int cmd_mtd_backup_raw_partition(const char *partition, const char *filename);
extern int cmd_mtd_erase_raw_partition(const char *partition);
extern int cmd_mtd_erase_partition(const char *partition, const char *filesystem);
extern int cmd_mtd_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only);
extern int cmd_mtd_get_partition_device(const char *partition, char *device);
extern int cmd_mmc_restore_raw_partition(const char *partition, const char *filename);
extern int cmd_mmc_backup_raw_partition(const char *partition, const char *filename);
extern int cmd_mmc_erase_raw_partition(const char *partition);
extern int cmd_mmc_erase_partition(const char *partition, const char *filesystem);
extern int cmd_mmc_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only);
extern int cmd_mmc_get_partition_device(const char *partition, char *device);
extern int cmd_bml_restore_raw_partition(const char *partition, const char *filename);
extern int cmd_bml_backup_raw_partition(const char *partition, const char *filename);
extern int cmd_bml_erase_raw_partition(const char *partition);
extern int cmd_bml_erase_partition(const char *partition, const char *filesystem);
extern int cmd_bml_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only);
extern int cmd_bml_get_partition_device(const char *partition, char *device);

View File

@ -527,7 +527,7 @@ ERROR3:
}
int restore_raw_partition(const char *partition, const char *filename)
int cmd_mmc_restore_raw_partition(const char *partition, const char *filename)
{
mmc_scan_partitions();
const MmcPartition *p;
@ -537,7 +537,7 @@ int restore_raw_partition(const char *partition, const char *filename)
return mmc_raw_copy(p, filename);
}
int backup_raw_partition(const char *partition, const char *filename)
int cmd_mmc_backup_raw_partition(const char *partition, const char *filename)
{
mmc_scan_partitions();
const MmcPartition *p;
@ -547,19 +547,19 @@ int backup_raw_partition(const char *partition, const char *filename)
return mmc_raw_dump(p, filename);
}
int erase_raw_partition(const char *partition)
int cmd_mmc_erase_raw_partition(const char *partition)
{
mmc_scan_partitions();
const MmcPartition *p;
p = mmc_find_partition_by_name(partition);
if (p == NULL)
return -1;
// TODO: implement raw wipe
return 0;
}
int erase_partition(const char *partition, const char *filesystem)
int cmd_mmc_erase_partition(const char *partition, const char *filesystem)
{
mmc_scan_partitions();
const MmcPartition *p;
@ -569,7 +569,7 @@ int erase_partition(const char *partition, const char *filesystem)
return mmc_format_ext3 (p);
}
int mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
int cmd_mmc_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
{
mmc_scan_partitions();
const MmcPartition *p;
@ -579,7 +579,7 @@ int mount_partition(const char *partition, const char *mount_point, const char *
return mmc_mount_partition(p, mount_point, read_only);
}
int get_partition_device(const char *partition, char *device)
int cmd_mmc_get_partition_device(const char *partition, char *device)
{
mmc_scan_partitions();
const MmcPartition *p;

View File

@ -562,7 +562,7 @@ off_t mtd_find_write_start(MtdWriteContext *ctx, off_t pos) {
#define SPARE_SIZE (BLOCK_SIZE >> 5)
#define HEADER_SIZE 2048
int restore_raw_partition(const char *partition_name, const char *filename)
int cmd_mtd_restore_raw_partition(const char *partition_name, const char *filename)
{
const MtdPartition *ptn;
MtdWriteContext *write;
@ -577,9 +577,9 @@ int restore_raw_partition(const char *partition_name, const char *filename)
const MtdPartition *partition = mtd_find_partition_by_name(partition_name);
if (partition == NULL)
{
printf("can't find %s partition", partition_name);
printf("can't find %s partition", partition_name);
return -1;
}
}
// If the first part of the file matches the partition, skip writing
@ -588,11 +588,11 @@ int restore_raw_partition(const char *partition_name, const char *filename)
{
printf("error opening %s", filename);
return -1;
}
}
char header[HEADER_SIZE];
int headerlen = read(fd, header, sizeof(header));
if (headerlen <= 0)
if (headerlen <= 0)
{
printf("error reading %s header", filename);
return -1;
@ -619,7 +619,7 @@ int restore_raw_partition(const char *partition_name, const char *filename)
printf("flashing %s from %s\n", partition_name, filename);
MtdWriteContext *out = mtd_write_partition(partition);
if (out == NULL)
if (out == NULL)
{
printf("error writing %s", partition_name);
return -1;
@ -628,7 +628,7 @@ int restore_raw_partition(const char *partition_name, const char *filename)
char buf[HEADER_SIZE];
memset(buf, 0, headerlen);
int wrote = mtd_write_data(out, buf, headerlen);
if (wrote != headerlen)
if (wrote != headerlen)
{
printf("error writing %s", partition_name);
return -1;
@ -643,13 +643,13 @@ int restore_raw_partition(const char *partition_name, const char *filename)
return -1;
}
}
if (len < 0)
if (len < 0)
{
printf("error reading %s", filename);
return -1;
}
if (mtd_write_close(out))
if (mtd_write_close(out))
{
printf("error closing %s", partition_name);
return -1;
@ -662,14 +662,14 @@ int restore_raw_partition(const char *partition_name, const char *filename)
{
printf("error re-opening %s", partition_name);
return -1;
}
}
wrote = mtd_write_data(out, header, headerlen);
if (wrote != headerlen)
{
printf("error re-writing %s", partition_name);
return -1;
}
}
// Need to write a complete block, so write the rest of the first block
size_t block_size;
@ -698,11 +698,11 @@ int restore_raw_partition(const char *partition_name, const char *filename)
printf("error writing %s", partition_name);
return -1;
}
left -= len;
}
if (mtd_write_close(out))
if (mtd_write_close(out))
{
printf("error closing %s", partition_name);
return -1;
@ -711,7 +711,7 @@ int restore_raw_partition(const char *partition_name, const char *filename)
}
int backup_raw_partition(const char *partition_name, const char *filename)
int cmd_mtd_backup_raw_partition(const char *partition_name, const char *filename)
{
MtdReadContext *in;
const MtdPartition *partition;
@ -722,10 +722,10 @@ int backup_raw_partition(const char *partition_name, const char *filename)
int fd;
int wrote;
int len;
if (mtd_scan_partitions() <= 0)
{
printf("error scanning partitions");
printf("error scanning partitions");
return -1;
}
@ -743,7 +743,7 @@ int backup_raw_partition(const char *partition_name, const char *filename)
if (!strcmp(filename, "-")) {
fd = fileno(stdout);
}
}
else {
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
}
@ -784,7 +784,7 @@ int backup_raw_partition(const char *partition_name, const char *filename)
return 0;
}
int erase_raw_partition(const char *partition_name)
int cmd_mtd_erase_raw_partition(const char *partition_name)
{
MtdWriteContext *out;
size_t erased;
@ -799,14 +799,14 @@ int erase_raw_partition(const char *partition_name)
const MtdPartition *p = mtd_find_partition_by_name(partition_name);
if (p == NULL)
{
printf("can't find %s partition", partition_name);
printf("can't find %s partition", partition_name);
return -1;
}
out = mtd_write_partition(p);
if (out == NULL)
{
printf("could not estabilish write context for %s", partition_name);
printf("could not estabilish write context for %s", partition_name);
return -1;
}
@ -823,13 +823,13 @@ int erase_raw_partition(const char *partition_name)
return 0;
}
int erase_partition(const char *partition, const char *filesystem)
int cmd_mtd_erase_partition(const char *partition, const char *filesystem)
{
return erase_raw_partition(partition);
return cmd_mtd_erase_raw_partition(partition);
}
int mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
int cmd_mtd_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only)
{
mtd_scan_partitions();
const MtdPartition *p;
@ -840,7 +840,7 @@ int mount_partition(const char *partition, const char *mount_point, const char *
return mtd_mount_partition(p, mount_point, filesystem, read_only);
}
int get_partition_device(const char *partition, char *device)
int cmd_mtd_get_partition_device(const char *partition, char *device)
{
mtd_scan_partitions();
MtdPartition *p = mtd_find_partition_by_name(partition);

View File

@ -19,6 +19,7 @@
#define RECOVERY_ROOTS_H_
#include "minzip/Zip.h"
#include "flashutils/flashutils.h"
#include "mtdutils/mtdutils.h"
#include "mmcutils/mmcutils.h"

View File

@ -19,7 +19,7 @@ LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES := $(updater_src_files)
LOCAL_STATIC_LIBRARIES += $(BOARD_FLASH_LIBRARY)
LOCAL_STATIC_LIBRARIES += libflashutils libmtdutils libmmcutils libbmlutils
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UPDATER_LIBS) $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS)
LOCAL_STATIC_LIBRARIES += libapplypatch libedify libminzip libz

View File

@ -33,17 +33,12 @@
#include "mincrypt/sha.h"
#include "minzip/DirUtil.h"
#include "mounts.h"
#include "flashutils/flashutils.h"
#include "mtdutils/mtdutils.h"
#include "mmcutils/mmcutils.h"
#include "updater.h"
#include "applypatch/applypatch.h"
#ifndef BOARD_USES_MMCUTILS
#define DEFAULT_FILESYSTEM "yaffs2"
#else
#define DEFAULT_FILESYSTEM "ext3"
#endif
// mount(type, location, mount_point)
//
// what: type="MTD" location="<partition>" to mount a yaffs2 filesystem
@ -76,7 +71,7 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
mkdir(mount_point, 0755);
if (strcmp(type, "MTD") == 0 || strcmp(type, "MMC") == 0) {
if (0 == mount_partition(location, mount_point, DEFAULT_FILESYSTEM, 0))
if (0 == mount_partition(location, mount_point, get_default_filesystem(), 0))
result = mount_point;
else
result = strdup("");