update.zip somewhat working now...
This commit is contained in:
parent
4c1eed2573
commit
6060e5c6df
@ -5,9 +5,12 @@ LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
commands_recovery_local_path := $(LOCAL_PATH)
|
||||
# LOCAL_CPP_EXTENSION := .c
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
extendedcommands.c \
|
||||
legacy.c \
|
||||
commands.c \
|
||||
recovery.c \
|
||||
bootloader.c \
|
||||
firmware.c \
|
||||
|
@ -125,6 +125,19 @@ cmd_copy_dir(const char *name, void *cookie, int argc, const char *argv[],
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* delete <srcdir> <dstdir>
|
||||
*/
|
||||
static int
|
||||
cmd_delete(const char *name, void *cookie, int argc, const char *argv[],
|
||||
PermissionRequestList *permissions)
|
||||
{
|
||||
UNUSED(name);
|
||||
UNUSED(cookie);
|
||||
CHECK_WORDS();
|
||||
//xxx
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mark <resource> dirty|clean
|
||||
*/
|
||||
static int
|
||||
@ -165,6 +178,9 @@ registerUpdateCommands()
|
||||
ret = registerCommand("copy_dir", CMD_ARGS_WORDS, cmd_copy_dir, NULL);
|
||||
if (ret < 0) return ret;
|
||||
|
||||
ret = registerCommand("delete", CMD_ARGS_WORDS, cmd_delete, NULL);
|
||||
if (ret < 0) return ret;
|
||||
|
||||
ret = registerCommand("format", CMD_ARGS_WORDS, cmd_format, NULL);
|
||||
if (ret < 0) return ret;
|
||||
|
||||
|
1154
commands.c
Normal file
1154
commands.c
Normal file
File diff suppressed because it is too large
Load Diff
28
commands.h
Normal file
28
commands.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RECOVERY_COMMANDS_H_
|
||||
#define RECOVERY_COMMANDS_H_
|
||||
|
||||
#include "minzip/Zip.h"
|
||||
|
||||
typedef struct {
|
||||
ZipArchive *package;
|
||||
} RecoveryCommandContext;
|
||||
|
||||
int register_update_commands(RecoveryCommandContext *ctx);
|
||||
|
||||
#endif // RECOVERY_COMMANDS_H_
|
@ -27,6 +27,8 @@ char* MENU_ITEMS[] = { "reboot system now",
|
||||
"apply sdcard:update.zip",
|
||||
"wipe data/factory reset",
|
||||
"wipe cache partition",
|
||||
"toggle signature verification",
|
||||
"toggle script asserts",
|
||||
NULL };
|
||||
|
||||
int device_toggle_display(volatile char* key_pressed, int key_code) {
|
||||
|
39
extendedcommands.c
Normal file
39
extendedcommands.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <linux/input.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bootloader.h"
|
||||
#include "common.h"
|
||||
#include "cutils/properties.h"
|
||||
#include "firmware.h"
|
||||
#include "install.h"
|
||||
#include "minui/minui.h"
|
||||
#include "minzip/DirUtil.h"
|
||||
#include "roots.h"
|
||||
#include "recovery_ui.h"
|
||||
|
||||
int signature_check_enabled = 1;
|
||||
int script_assert_enabled = 1;
|
||||
|
||||
void
|
||||
toggle_signature_check()
|
||||
{
|
||||
signature_check_enabled = !signature_check_enabled;
|
||||
ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
void toggle_script_asserts()
|
||||
{
|
||||
script_assert_enabled = !script_assert_enabled;
|
||||
ui_print("Script Asserts: %s\n", signature_check_enabled ? "Enabled" : "Disabled");
|
||||
}
|
5
extendedcommands.h
Normal file
5
extendedcommands.h
Normal file
@ -0,0 +1,5 @@
|
||||
extern int signature_check_enabled;
|
||||
extern int script_assert_enabled;
|
||||
|
||||
void
|
||||
toggle_signature_check();
|
45
install.c
45
install.c
@ -35,6 +35,8 @@
|
||||
#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"
|
||||
|
||||
@ -347,27 +349,30 @@ install_package(const char *root_path)
|
||||
ui_print("Opening update package...\n");
|
||||
LOGI("Update file path: %s\n", path);
|
||||
|
||||
int numKeys;
|
||||
RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
|
||||
if (loadedKeys == NULL) {
|
||||
LOGE("Failed to load keys\n");
|
||||
return INSTALL_CORRUPT;
|
||||
}
|
||||
LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);
|
||||
|
||||
// Give verification half the progress bar...
|
||||
ui_print("Verifying update package...\n");
|
||||
ui_show_progress(
|
||||
VERIFICATION_PROGRESS_FRACTION,
|
||||
VERIFICATION_PROGRESS_TIME);
|
||||
|
||||
int err;
|
||||
err = verify_file(path, loadedKeys, numKeys);
|
||||
free(loadedKeys);
|
||||
LOGI("verify_file returned %d\n", err);
|
||||
if (err != VERIFY_SUCCESS) {
|
||||
LOGE("signature verification failed\n");
|
||||
return INSTALL_CORRUPT;
|
||||
|
||||
if (signature_check_enabled) {
|
||||
int numKeys;
|
||||
RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
|
||||
if (loadedKeys == NULL) {
|
||||
LOGE("Failed to load keys\n");
|
||||
return INSTALL_CORRUPT;
|
||||
}
|
||||
LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);
|
||||
|
||||
// Give verification half the progress bar...
|
||||
ui_print("Verifying update package...\n");
|
||||
ui_show_progress(
|
||||
VERIFICATION_PROGRESS_FRACTION,
|
||||
VERIFICATION_PROGRESS_TIME);
|
||||
|
||||
err = verify_file(path, loadedKeys, numKeys);
|
||||
free(loadedKeys);
|
||||
LOGI("verify_file returned %d\n", err);
|
||||
if (err != VERIFY_SUCCESS) {
|
||||
LOGE("signature verification failed\n");
|
||||
return INSTALL_CORRUPT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try to open the package.
|
||||
|
35
legacy.c
35
legacy.c
@ -46,9 +46,44 @@
|
||||
#include "roots.h"
|
||||
#include "verifier.h"
|
||||
|
||||
static int read_data(ZipArchive *zip, const ZipEntry *entry,
|
||||
char** ppData, int* pLength) {
|
||||
int len = (int)mzGetZipEntryUncompLen(entry);
|
||||
if (len <= 0) {
|
||||
LOGE("Bad data length %d\n", len);
|
||||
return -1;
|
||||
}
|
||||
char *data = malloc(len + 1);
|
||||
if (data == NULL) {
|
||||
LOGE("Can't allocate %d bytes for data\n", len + 1);
|
||||
return -2;
|
||||
}
|
||||
bool ok = mzReadZipEntry(zip, entry, data, len);
|
||||
if (!ok) {
|
||||
LOGE("Error while reading data\n");
|
||||
free(data);
|
||||
return -3;
|
||||
}
|
||||
data[len] = '\0'; // not necessary, but just to be safe
|
||||
*ppData = data;
|
||||
if (pLength) {
|
||||
*pLength = len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
handle_update_script(ZipArchive *zip, const ZipEntry *update_script_entry)
|
||||
{
|
||||
// This is bizarre. The build fails with "undefined reference"
|
||||
// unless the following two functions are referenced from somewhere to
|
||||
// force them to be linked. This seems to be a problem with yacc/lex.
|
||||
if (zip == 1)
|
||||
{
|
||||
fwrite(NULL, 0, 0, NULL);
|
||||
fileno(NULL);
|
||||
}
|
||||
|
||||
/* Read the entire script into a buffer.
|
||||
*/
|
||||
int script_len;
|
||||
|
14
recovery.c
14
recovery.c
@ -38,6 +38,9 @@
|
||||
#include "roots.h"
|
||||
#include "recovery_ui.h"
|
||||
|
||||
#include "extendedcommands.h"
|
||||
#include "commands.h"
|
||||
|
||||
static const struct option OPTIONS[] = {
|
||||
{ "send_intent", required_argument, NULL, 's' },
|
||||
{ "update_package", required_argument, NULL, 'u' },
|
||||
@ -430,6 +433,12 @@ prompt_and_wait()
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ITEM_SIG_CHECK:
|
||||
toggle_signature_check();
|
||||
break;
|
||||
case ITEM_ASSERTS:
|
||||
toggle_script_asserts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -482,6 +491,11 @@ main(int argc, char **argv)
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
int status = INSTALL_SUCCESS;
|
||||
|
||||
RecoveryCommandContext ctx = { NULL };
|
||||
if (register_update_commands(&ctx)) {
|
||||
LOGE("Can't install update commands\n");
|
||||
}
|
||||
|
||||
if (update_package != NULL) {
|
||||
status = install_package(update_package);
|
||||
|
@ -66,6 +66,8 @@ int device_wipe_data();
|
||||
#define ITEM_APPLY_SDCARD 1
|
||||
#define ITEM_WIPE_DATA 2
|
||||
#define ITEM_WIPE_CACHE 3
|
||||
#define ITEM_SIG_CHECK 4
|
||||
#define ITEM_ASSERTS 5
|
||||
|
||||
// Header text to display above the main menu.
|
||||
extern char* MENU_HEADERS[];
|
||||
|
Loading…
Reference in New Issue
Block a user