aboutsummaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2012-07-18 12:17:57 -0700
committerKoushik Dutta <koushd@gmail.com>2012-07-18 12:18:17 -0700
commite9692604a2ba69c1f1305b40780210f51c737570 (patch)
treef7452f37f344b541b43d6bb46f675025a2c643d3 /updater
parentb54fd836784bbb3d3778036c358ae7f5f76cf8ed (diff)
downloadbootable_recovery-e9692604a2ba69c1f1305b40780210f51c737570.zip
bootable_recovery-e9692604a2ba69c1f1305b40780210f51c737570.tar.gz
bootable_recovery-e9692604a2ba69c1f1305b40780210f51c737570.tar.bz2
Forward port write_raw_image changes to jellybean.
Change-Id: I124adeeed93f4ec97d1e14c1572e313024f11008
Diffstat (limited to 'updater')
-rw-r--r--updater/Android.mk2
-rw-r--r--updater/install.c63
2 files changed, 7 insertions, 58 deletions
diff --git a/updater/Android.mk b/updater/Android.mk
index 3e9c048..ab59f97 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -31,6 +31,8 @@ LOCAL_STATIC_LIBRARIES += libselinux
LOCAL_CFLAGS += -DHAVE_SELINUX
endif # HAVE_SELINUX
+LOCAL_STATIC_LIBRARIES += libflashutils libmtdutils libmmcutils libbmlutils
+
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UPDATER_LIBS) $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS)
LOCAL_STATIC_LIBRARIES += libapplypatch libedify libmtdutils libminzip libz
LOCAL_STATIC_LIBRARIES += libmincrypt libbz
diff --git a/updater/install.c b/updater/install.c
index f56df89..1ad6d81 100644
--- a/updater/install.c
+++ b/updater/install.c
@@ -712,12 +712,11 @@ Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) {
return NULL;
}
- char* partition = NULL;
if (partition_value->type != VAL_STRING) {
ErrorAbort(state, "partition argument to %s must be string", name);
goto done;
}
- partition = partition_value->data;
+ char* partition = partition_value->data;
if (strlen(partition) == 0) {
ErrorAbort(state, "partition argument to %s can't be empty", name);
goto done;
@@ -727,66 +726,14 @@ Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) {
goto done;
}
- mtd_scan_partitions();
- const MtdPartition* mtd = mtd_find_partition_by_name(partition);
- if (mtd == NULL) {
- fprintf(stderr, "%s: no mtd partition named \"%s\"\n", name, partition);
+ char* filename = contents->data;
+ if (0 == restore_raw_partition(NULL, partition, filename))
+ result = strdup(partition);
+ else {
result = strdup("");
goto done;
}
- MtdWriteContext* ctx = mtd_write_partition(mtd);
- if (ctx == NULL) {
- fprintf(stderr, "%s: can't write mtd partition \"%s\"\n",
- name, partition);
- result = strdup("");
- goto done;
- }
-
- bool success;
-
- if (contents->type == VAL_STRING) {
- // we're given a filename as the contents
- char* filename = contents->data;
- FILE* f = fopen(filename, "rb");
- if (f == NULL) {
- fprintf(stderr, "%s: can't open %s: %s\n",
- name, filename, strerror(errno));
- result = strdup("");
- goto done;
- }
-
- success = true;
- char* buffer = malloc(BUFSIZ);
- int read;
- while (success && (read = fread(buffer, 1, BUFSIZ, f)) > 0) {
- int wrote = mtd_write_data(ctx, buffer, read);
- success = success && (wrote == read);
- }
- free(buffer);
- fclose(f);
- } else {
- // we're given a blob as the contents
- ssize_t wrote = mtd_write_data(ctx, contents->data, contents->size);
- success = (wrote == contents->size);
- }
- if (!success) {
- fprintf(stderr, "mtd_write_data to %s failed: %s\n",
- partition, strerror(errno));
- }
-
- if (mtd_erase_blocks(ctx, -1) == -1) {
- fprintf(stderr, "%s: error erasing blocks of %s\n", name, partition);
- }
- if (mtd_write_close(ctx) != 0) {
- fprintf(stderr, "%s: error closing write of %s\n", name, partition);
- }
-
- printf("%s %s partition\n",
- success ? "wrote" : "failed to write", partition);
-
- result = success ? partition : strdup("");
-
done:
if (result != partition) FreeValue(partition_value);
FreeValue(contents);