aboutsummaryrefslogtreecommitdiffstats
path: root/install.c
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2010-06-23 17:38:05 -0700
committerKoushik Dutta <koushd@gmail.com>2010-06-23 17:38:05 -0700
commit0eb14b30e0203ba5758452f115786ee3d6dc97a1 (patch)
tree80bd67cd0333c25d0721288509a6197bf02edad5 /install.c
parentcd44ab973ebef327384ca5475f8276c37c2e8538 (diff)
parent2654f5aae18c67ad9aff6dbcdf9bc67b62e37d2d (diff)
downloadbootable_recovery-0eb14b30e0203ba5758452f115786ee3d6dc97a1.zip
bootable_recovery-0eb14b30e0203ba5758452f115786ee3d6dc97a1.tar.gz
bootable_recovery-0eb14b30e0203ba5758452f115786ee3d6dc97a1.tar.bz2
Merge from Froyo.
Diffstat (limited to 'install.c')
-rw-r--r--install.c100
1 files changed, 13 insertions, 87 deletions
diff --git a/install.c b/install.c
index bbdb854..088f976 100644
--- a/install.c
+++ b/install.c
@@ -32,74 +32,16 @@
#include "mtdutils/mtdutils.h"
#include "roots.h"
#include "verifier.h"
+
#include "firmware.h"
#include "legacy.h"
#include "extendedcommands.h"
+
#define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary"
#define PUBLIC_KEYS_FILE "/res/keys"
-// The update binary ask us to install a firmware file on reboot. Set
-// that up. Takes ownership of type and filename.
-static int
-handle_firmware_update(char* type, char* filename, ZipArchive* zip) {
- unsigned int data_size;
- const ZipEntry* entry = NULL;
-
- if (strncmp(filename, "PACKAGE:", 8) == 0) {
- entry = mzFindZipEntry(zip, filename+8);
- if (entry == NULL) {
- LOGE("Failed to find \"%s\" in package", filename+8);
- return INSTALL_ERROR;
- }
- data_size = entry->uncompLen;
- } else {
- struct stat st_data;
- if (stat(filename, &st_data) < 0) {
- LOGE("Error stat'ing %s: %s\n", filename, strerror(errno));
- return INSTALL_ERROR;
- }
- data_size = st_data.st_size;
- }
-
- LOGI("type is %s; size is %d; file is %s\n",
- type, data_size, filename);
-
- char* data = malloc(data_size);
- if (data == NULL) {
- LOGI("Can't allocate %d bytes for firmware data\n", data_size);
- return INSTALL_ERROR;
- }
-
- if (entry) {
- if (mzReadZipEntry(zip, entry, data, data_size) == false) {
- LOGE("Failed to read \"%s\" from package", filename+8);
- return INSTALL_ERROR;
- }
- } else {
- FILE* f = fopen(filename, "rb");
- if (f == NULL) {
- LOGE("Failed to open %s: %s\n", filename, strerror(errno));
- return INSTALL_ERROR;
- }
- if (fread(data, 1, data_size, f) != data_size) {
- LOGE("Failed to read firmware data: %s\n", strerror(errno));
- return INSTALL_ERROR;
- }
- fclose(f);
- }
-
- if (remember_firmware_update(type, data, data_size)) {
- LOGE("Can't store %s image\n", type);
- free(data);
- return INSTALL_ERROR;
- }
- free(filename);
-
- return INSTALL_SUCCESS;
-}
-
// If the package contains an update binary, extract it and run it.
static int
try_update_binary(const char *path, ZipArchive *zip) {
@@ -148,9 +90,12 @@ try_update_binary(const char *path, ZipArchive *zip) {
//
// firmware <"hboot"|"radio"> <filename>
// arrange to install the contents of <filename> in the
- // given partition on reboot. (API v2: <filename> may
- // start with "PACKAGE:" to indicate taking a file from
- // the OTA package.)
+ // given partition on reboot.
+ //
+ // (API v2: <filename> may start with "PACKAGE:" to
+ // indicate taking a file from the OTA package.)
+ //
+ // (API v3: this command no longer exists.)
//
// ui_print <string>
// display <string> on the screen.
@@ -175,9 +120,6 @@ try_update_binary(const char *path, ZipArchive *zip) {
}
close(pipefd[1]);
- char* firmware_type = NULL;
- char* firmware_filename = NULL;
-
char buffer[1024];
FILE* from_child = fdopen(pipefd[0], "r");
while (fgets(buffer, sizeof(buffer), from_child) != NULL) {
@@ -197,18 +139,6 @@ try_update_binary(const char *path, ZipArchive *zip) {
char* fraction_s = strtok(NULL, " \n");
float fraction = strtof(fraction_s, NULL);
ui_set_progress(fraction);
- } else if (strcmp(command, "firmware") == 0) {
- char* type = strtok(NULL, " \n");
- char* filename = strtok(NULL, " \n");
-
- if (type != NULL && filename != NULL) {
- if (firmware_type != NULL) {
- LOGE("ignoring attempt to do multiple firmware updates");
- } else {
- firmware_type = strdup(type);
- firmware_filename = strdup(filename);
- }
- }
} else if (strcmp(command, "ui_print") == 0) {
char* str = strtok(NULL, "\n");
if (str) {
@@ -229,11 +159,7 @@ try_update_binary(const char *path, ZipArchive *zip) {
return INSTALL_ERROR;
}
- if (firmware_type != NULL) {
- return handle_firmware_update(firmware_type, firmware_filename, zip);
- } else {
- return INSTALL_SUCCESS;
- }
+ return INSTALL_SUCCESS;
}
static int
@@ -295,7 +221,7 @@ load_keys(const char* filename, int* numKeys) {
++*numKeys;
out = realloc(out, *numKeys * sizeof(RSAPublicKey));
RSAPublicKey* key = out + (*numKeys - 1);
- if (fscanf(f, " { %i , %i , { %i",
+ if (fscanf(f, " { %i , 0x%x , { %u",
&(key->len), &(key->n0inv), &(key->n[0])) != 3) {
goto exit;
}
@@ -304,11 +230,11 @@ load_keys(const char* filename, int* numKeys) {
goto exit;
}
for (i = 1; i < key->len; ++i) {
- if (fscanf(f, " , %i", &(key->n[i])) != 1) goto exit;
+ if (fscanf(f, " , %u", &(key->n[i])) != 1) goto exit;
}
- if (fscanf(f, " } , { %i", &(key->rr[0])) != 1) goto exit;
+ if (fscanf(f, " } , { %u", &(key->rr[0])) != 1) goto exit;
for (i = 1; i < key->len; ++i) {
- if (fscanf(f, " , %i", &(key->rr[i])) != 1) goto exit;
+ if (fscanf(f, " , %u", &(key->rr[i])) != 1) goto exit;
}
fscanf(f, " } } ");