am 56c5105b: support for ext4/EMMC filesystems in updater binary

Merge commit '56c5105bd7096704eaed35329b2c8c84cc282867' into gingerbread-plus-aosp

* commit '56c5105bd7096704eaed35329b2c8c84cc282867':
  support for ext4/EMMC filesystems in updater binary
This commit is contained in:
Doug Zongker 2010-09-15 11:14:51 -07:00 committed by Android Git Automerger
commit 9f89b0e467
6 changed files with 76 additions and 37 deletions

View file

@ -73,12 +73,12 @@ void ui_show_indeterminate_progress();
void ui_reset_progress(); void ui_reset_progress();
#define LOGE(...) ui_print("E:" __VA_ARGS__) #define LOGE(...) ui_print("E:" __VA_ARGS__)
#define LOGW(...) fprintf(stderr, "W:" __VA_ARGS__) #define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__)
#define LOGI(...) fprintf(stderr, "I:" __VA_ARGS__) #define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__)
#if 0 #if 0
#define LOGV(...) fprintf(stderr, "V:" __VA_ARGS__) #define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__)
#define LOGD(...) fprintf(stderr, "D:" __VA_ARGS__) #define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__)
#else #else
#define LOGV(...) do {} while (0) #define LOGV(...) do {} while (0)
#define LOGD(...) do {} while (0) #define LOGD(...) do {} while (0)

View file

@ -112,7 +112,7 @@ try_update_binary(const char *path, ZipArchive *zip) {
if (pid == 0) { if (pid == 0) {
close(pipefd[0]); close(pipefd[0]);
execv(binary, args); execv(binary, args);
fprintf(stderr, "E:Can't run %s (%s)\n", binary, strerror(errno)); fprintf(stdout, "E:Can't run %s (%s)\n", binary, strerror(errno));
_exit(-1); _exit(-1);
} }
close(pipefd[1]); close(pipefd[1]);

View file

@ -673,7 +673,7 @@ prompt_and_wait() {
static void static void
print_property(const char *key, const char *name, void *cookie) { print_property(const char *key, const char *name, void *cookie) {
fprintf(stderr, "%s=%s\n", key, name); printf("%s=%s\n", key, name);
} }
int int
@ -683,7 +683,7 @@ main(int argc, char **argv) {
// If these fail, there's not really anywhere to complain... // If these fail, there's not really anywhere to complain...
freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
fprintf(stderr, "Starting recovery on %s", ctime(&start)); printf("Starting recovery on %s", ctime(&start));
ui_init(); ui_init();
get_args(&argc, &argv); get_args(&argc, &argv);
@ -714,14 +714,14 @@ main(int argc, char **argv) {
device_recovery_start(); device_recovery_start();
fprintf(stderr, "Command:"); printf("Command:");
for (arg = 0; arg < argc; arg++) { for (arg = 0; arg < argc; arg++) {
fprintf(stderr, " \"%s\"", argv[arg]); printf(" \"%s\"", argv[arg]);
} }
fprintf(stderr, "\n\n"); printf("\n\n");
property_list(print_property, NULL); property_list(print_property, NULL);
fprintf(stderr, "\n"); printf("\n");
int status = INSTALL_SUCCESS; int status = INSTALL_SUCCESS;

2
ui.c
View file

@ -404,7 +404,7 @@ void ui_print(const char *fmt, ...)
vsnprintf(buf, 256, fmt, ap); vsnprintf(buf, 256, fmt, ap);
va_end(ap); va_end(ap);
fputs(buf, stderr); fputs(buf, stdout);
// This can get called before ui_init(), so be careful. // This can get called before ui_init(), so be careful.
pthread_mutex_lock(&gUpdateMutex); pthread_mutex_lock(&gUpdateMutex);

View file

@ -18,7 +18,13 @@ LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES := $(updater_src_files) LOCAL_SRC_FILES := $(updater_src_files)
LOCAL_STATIC_LIBRARIES := $(TARGET_RECOVERY_UPDATER_LIBS) $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS) ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
LOCAL_CFLAGS += -DUSE_EXT4
LOCAL_C_INCLUDES += system/extras/ext4_utils
LOCAL_STATIC_LIBRARIES += libext4_utils libz
endif
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UPDATER_LIBS) $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS)
LOCAL_STATIC_LIBRARIES += libapplypatch libedify libmtdutils libminzip libz LOCAL_STATIC_LIBRARIES += libapplypatch libedify libmtdutils libminzip libz
LOCAL_STATIC_LIBRARIES += libmincrypt libbz LOCAL_STATIC_LIBRARIES += libmincrypt libbz
LOCAL_STATIC_LIBRARIES += libcutils libstdc++ libc LOCAL_STATIC_LIBRARIES += libcutils libstdc++ libc

View file

@ -36,24 +36,35 @@
#include "updater.h" #include "updater.h"
#include "applypatch/applypatch.h" #include "applypatch/applypatch.h"
// mount(type, location, mount_point) #ifdef USE_EXT4
#include "make_ext4fs.h"
#endif
// mount(fs_type, partition_type, location, mount_point)
// //
// what: type="MTD" location="<partition>" to mount a yaffs2 filesystem // fs_type="yaffs2" partition_type="MTD" location=partition
// type="vfat" location="/dev/block/<whatever>" to mount a device // fs_type="ext4" partition_type="EMMC" location=device
Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) { Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
char* result = NULL; char* result = NULL;
if (argc != 3) { if (argc != 4) {
return ErrorAbort(state, "%s() expects 3 args, got %d", name, argc); return ErrorAbort(state, "%s() expects 4 args, got %d", name, argc);
} }
char* type; char* fs_type;
char* partition_type;
char* location; char* location;
char* mount_point; char* mount_point;
if (ReadArgs(state, argv, 3, &type, &location, &mount_point) < 0) { if (ReadArgs(state, argv, 4, &fs_type, &partition_type,
&location, &mount_point) < 0) {
return NULL; return NULL;
} }
if (strlen(type) == 0) { if (strlen(fs_type) == 0) {
ErrorAbort(state, "type argument to %s() can't be empty", name); ErrorAbort(state, "fs_type argument to %s() can't be empty", name);
goto done;
}
if (strlen(partition_type) == 0) {
ErrorAbort(state, "partition_type argument to %s() can't be empty",
name);
goto done; goto done;
} }
if (strlen(location) == 0) { if (strlen(location) == 0) {
@ -67,7 +78,7 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
mkdir(mount_point, 0755); mkdir(mount_point, 0755);
if (strcmp(type, "MTD") == 0) { if (strcmp(partition_type, "MTD") == 0) {
mtd_scan_partitions(); mtd_scan_partitions();
const MtdPartition* mtd; const MtdPartition* mtd;
mtd = mtd_find_partition_by_name(location); mtd = mtd_find_partition_by_name(location);
@ -77,7 +88,7 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
result = strdup(""); result = strdup("");
goto done; goto done;
} }
if (mtd_mount_partition(mtd, mount_point, "yaffs2", 0 /* rw */) != 0) { if (mtd_mount_partition(mtd, mount_point, fs_type, 0 /* rw */) != 0) {
fprintf(stderr, "mtd mount of %s failed: %s\n", fprintf(stderr, "mtd mount of %s failed: %s\n",
location, strerror(errno)); location, strerror(errno));
result = strdup(""); result = strdup("");
@ -85,7 +96,7 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
} }
result = mount_point; result = mount_point;
} else { } else {
if (mount(location, mount_point, type, if (mount(location, mount_point, fs_type,
MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) { MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
fprintf(stderr, "%s: failed to mount %s at %s: %s\n", fprintf(stderr, "%s: failed to mount %s at %s: %s\n",
name, location, mount_point, strerror(errno)); name, location, mount_point, strerror(errno));
@ -96,7 +107,8 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
} }
done: done:
free(type); free(fs_type);
free(partition_type);
free(location); free(location);
if (result != mount_point) free(mount_point); if (result != mount_point) free(mount_point);
return StringValue(result); return StringValue(result);
@ -162,22 +174,29 @@ done:
} }
// format(type, location) // format(fs_type, partition_type, location)
// //
// type="MTD" location=partition // fs_type="yaffs2" partition_type="MTD" location=partition
// fs_type="ext4" partition_type="EMMC" location=device
Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) { Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) {
char* result = NULL; char* result = NULL;
if (argc != 2) { if (argc != 3) {
return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); return ErrorAbort(state, "%s() expects 3 args, got %d", name, argc);
} }
char* type; char* fs_type;
char* partition_type;
char* location; char* location;
if (ReadArgs(state, argv, 2, &type, &location) < 0) { if (ReadArgs(state, argv, 3, &fs_type, &partition_type, &location) < 0) {
return NULL; return NULL;
} }
if (strlen(type) == 0) { if (strlen(fs_type) == 0) {
ErrorAbort(state, "type argument to %s() can't be empty", name); ErrorAbort(state, "fs_type argument to %s() can't be empty", name);
goto done;
}
if (strlen(partition_type) == 0) {
ErrorAbort(state, "partition_type argument to %s() can't be empty",
name);
goto done; goto done;
} }
if (strlen(location) == 0) { if (strlen(location) == 0) {
@ -185,7 +204,7 @@ Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) {
goto done; goto done;
} }
if (strcmp(type, "MTD") == 0) { if (strcmp(partition_type, "MTD") == 0) {
mtd_scan_partitions(); mtd_scan_partitions();
const MtdPartition* mtd = mtd_find_partition_by_name(location); const MtdPartition* mtd = mtd_find_partition_by_name(location);
if (mtd == NULL) { if (mtd == NULL) {
@ -212,12 +231,26 @@ Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) {
goto done; goto done;
} }
result = location; result = location;
#ifdef USE_EXT4
} else if (strcmp(fs_type, "ext4") == 0) {
reset_ext4fs_info();
int status = make_ext4fs(location, NULL, NULL, 0, 0);
if (status != 0) {
fprintf(stderr, "%s: make_ext4fs failed (%d) on %s",
name, status, location);
result = strdup("");
goto done;
}
result = location;
#endif
} else { } else {
fprintf(stderr, "%s: unsupported type \"%s\"", name, type); fprintf(stderr, "%s: unsupported fs_type \"%s\" partition_type \"%s\"",
name, fs_type, partition_type);
} }
done: done:
free(type); free(fs_type);
free(partition_type);
if (result != location) free(location); if (result != location) free(location);
return StringValue(result); return StringValue(result);
} }