summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
Diffstat (limited to 'updater')
-rw-r--r--updater/Android.mk15
-rw-r--r--updater/install.c62
-rw-r--r--updater/updater.c36
3 files changed, 52 insertions, 61 deletions
diff --git a/updater/Android.mk b/updater/Android.mk
index a3a900a80..5c2896963 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -24,14 +24,27 @@ LOCAL_CFLAGS += -DUSE_EXT4
LOCAL_CFLAGS += -Wno-unused-parameter
LOCAL_C_INCLUDES += system/extras/ext4_utils
LOCAL_STATIC_LIBRARIES += \
+ libext4_utils \
+ libz
+ifneq ($(wildcard system/core/libmincrypt/rsa_e_3.c),)
+LOCAL_STATIC_LIBRARIES = \
+ libext4_utils_static \
+ libsparse_static \
+ libz
+endif
+ifneq ($(wildcard system/core/include/mincrypt/sha256.h),)
+LOCAL_STATIC_LIBRARIES = \
libext4_utils_static \
libsparse_static \
libz
endif
+endif
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
+LOCAL_STATIC_LIBRARIES += libflashutils libmmcutils libbmlutils
+LOCAL_STATIC_LIBRARIES += libmincrypttwrp libbz
+LOCAL_STATIC_LIBRARIES += libminelf
LOCAL_STATIC_LIBRARIES += libcutils liblog libstdc++ libc
LOCAL_STATIC_LIBRARIES += libselinux
LOCAL_C_INCLUDES += $(LOCAL_PATH)/..
diff --git a/updater/install.c b/updater/install.c
index ff7de4793..003064799 100644
--- a/updater/install.c
+++ b/updater/install.c
@@ -45,6 +45,8 @@
#include "mtdutils/mounts.h"
#include "mtdutils/mtdutils.h"
#include "updater.h"
+#include "applypatch/applypatch.h"
+#include "flashutils/flashutils.h"
#include "install.h"
#ifdef USE_EXT4
@@ -1061,66 +1063,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) {
- printf("%s: no mtd partition named \"%s\"\n", name, partition);
- result = strdup("");
- goto done;
- }
-
- MtdWriteContext* ctx = mtd_write_partition(mtd);
- if (ctx == NULL) {
- printf("%s: can't write mtd partition \"%s\"\n",
- name, partition);
+ char* filename = contents->data;
+ if (0 == restore_raw_partition(NULL, partition, filename))
+ result = strdup(partition);
+ else {
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) {
- printf("%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) {
- printf("mtd_write_data to %s failed: %s\n",
- partition, strerror(errno));
- }
-
- if (mtd_erase_blocks(ctx, -1) == -1) {
- printf("%s: error erasing blocks of %s\n", name, partition);
- }
- if (mtd_write_close(ctx) != 0) {
- printf("%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);
diff --git a/updater/updater.c b/updater/updater.c
index 465e1238e..78c0dc1a6 100644
--- a/updater/updater.c
+++ b/updater/updater.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <fcntl.h>
#include "edify/expr.h"
#include "updater.h"
@@ -33,6 +34,8 @@
// Where in the package we expect to find the edify script to execute.
// (Note it's "updateR-script", not the older "update-script".)
#define SCRIPT_NAME "META-INF/com/google/android/updater-script"
+#define SELINUX_CONTEXTS_ZIP "file_contexts"
+#define SELINUX_CONTEXTS_TMP "/tmp/file_contexts"
struct selabel_handle *sehandle;
@@ -95,6 +98,23 @@ int main(int argc, char** argv) {
}
script[script_entry->uncompLen] = '\0';
+ const ZipEntry* file_contexts_entry = mzFindZipEntry(&za, SELINUX_CONTEXTS_ZIP);
+ if (file_contexts_entry != NULL) {
+ int file_contexts_fd = creat(SELINUX_CONTEXTS_TMP, 0644);
+ if (file_contexts_fd < 0) {
+ fprintf(stderr, "Could not extract %s to '%s'\n", SELINUX_CONTEXTS_ZIP, SELINUX_CONTEXTS_TMP);
+ return 3;
+ }
+
+ int ret_val = mzExtractZipEntryToFile(&za, file_contexts_entry, file_contexts_fd);
+ close(file_contexts_fd);
+
+ if (!ret_val) {
+ fprintf(stderr, "Could not extract '%s'\n", SELINUX_CONTEXTS_ZIP);
+ return 3;
+ }
+ }
+
// Configure edify's functions.
RegisterBuiltins();
@@ -113,11 +133,19 @@ int main(int argc, char** argv) {
return 6;
}
- struct selinux_opt seopts[] = {
- { SELABEL_OPT_PATH, "/file_contexts" }
- };
+ if (access(SELINUX_CONTEXTS_TMP, R_OK) == 0) {
+ struct selinux_opt seopts[] = {
+ { SELABEL_OPT_PATH, SELINUX_CONTEXTS_TMP }
+ };
- sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);
+ sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);
+ } else {
+ struct selinux_opt seopts[] = {
+ { SELABEL_OPT_PATH, "/file_contexts" }
+ };
+
+ sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);
+ }
if (!sehandle) {
fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n");