Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2673cec0 authored by Dees_Troy's avatar Dees_Troy
Browse files

Move all AOSP code out of recovery binary

Improves license compatibility between GPL and Apache

Change-Id: I2b165aa575bb6213af6b07936f99610c113443f0
parent a13d74fc
Loading
Loading
Loading
Loading
+30 −26
Original line number Diff line number Diff line
@@ -16,25 +16,16 @@ LOCAL_PATH := $(call my-dir)

TARGET_RECOVERY_GUI := true

include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
    recovery.cpp \
    twbootloader.cpp \
    install.cpp \
    roots.cpp \
    ui.cpp \
    screen_ui.cpp \
    verifier.cpp \
    twrp.cpp \
    fixPermissions.cpp \
    twrpTar.cpp \
    twrpDigest.cpp \
    adb_install.cpp

LOCAL_SRC_FILES += \
    data.cpp \
    partition.cpp \
    partitionmanager.cpp \
    mtdutils/mtdutils.c \
    twinstall.cpp \
    twrp-functions.cpp \
    openrecoveryscript.cpp \
@@ -64,10 +55,8 @@ LOCAL_C_INCLUDES += bionic external/stlport/stlport
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=

LOCAL_STATIC_LIBRARIES += libmtdutils libcrecovery
LOCAL_STATIC_LIBRARIES += libminadbd libminzip libunz
LOCAL_STATIC_LIBRARIES += libminuitwrp libpixelflinger_static libpng libjpegtwrp libgui
LOCAL_SHARED_LIBRARIES += libz libc libstlport libcutils libstdc++ libmincrypt libext4_utils libtar libblkid
LOCAL_STATIC_LIBRARIES += libcrecovery libguitwrp
LOCAL_SHARED_LIBRARIES += libz libc libstlport libcutils libstdc++ libext4_utils libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libaosprecovery

ifneq ($(wildcard system/core/libsparse/Android.mk),)
LOCAL_SHARED_LIBRARIES += libsparse
@@ -80,9 +69,9 @@ ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
endif

ifeq ($(HAVE_SELINUX), true)
  LOCAL_C_INCLUDES += external/libselinux/include
  LOCAL_STATIC_LIBRARIES += libselinux
  LOCAL_CFLAGS += -DHAVE_SELINUX -g
  #LOCAL_C_INCLUDES += external/libselinux/include
  #LOCAL_STATIC_LIBRARIES += libselinux
  #LOCAL_CFLAGS += -DHAVE_SELINUX -g
endif # HAVE_SELINUX

# This binary is in the recovery ramdisk, which is otherwise a copy of root.
@@ -217,17 +206,16 @@ ifeq ($(TW_INCLUDE_CRYPTO_SAMSUNG), true)
    LOCAL_LDFLAGS += -ldl
    LOCAL_STATIC_LIBRARIES += libcrypt_samsung
endif
    LOCAL_SHARED_LIBRARIES += libcrypto
    LOCAL_SRC_FILES += crypto/ics/cryptfs.c
    LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
    LOCAL_SHARED_LIBRARIES += libcryptfsics
    #LOCAL_SRC_FILES += crypto/ics/cryptfs.c
    #LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
endif
ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
    LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO
    LOCAL_CFLAGS += -DTW_INCLUDE_JB_CRYPTO
    LOCAL_SHARED_LIBRARIES += libcrypto
    LOCAL_STATIC_LIBRARIES += libfs_mgrtwrp
    LOCAL_SRC_FILES += crypto/jb/cryptfs.c
    LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
    LOCAL_SHARED_LIBRARIES += libcryptfsjb
    #LOCAL_SRC_FILES += crypto/jb/cryptfs.c
    #LOCAL_C_INCLUDES += system/extras/ext4_utils external/openssl/include
endif
ifeq ($(TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID), true)
    LOCAL_CFLAGS += -DTW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
@@ -277,6 +265,18 @@ LOCAL_STATIC_LIBRARIES := \
    libc
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)

LOCAL_MODULE := libaosprecovery
LOCAL_MODULE_TAGS := eng
LOCAL_MODULES_TAGS = optional
LOCAL_CFLAGS = 
LOCAL_SRC_FILES = adb_install.cpp bootloader.cpp verifier.cpp
LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils
LOCAL_STATIC_LIBRARIES += libmincrypt

include $(BUILD_SHARED_LIBRARY)

commands_recovery_local_path := $(LOCAL_PATH)
include $(LOCAL_PATH)/minui/Android.mk \
    $(LOCAL_PATH)/minelf/Android.mk \
@@ -291,7 +291,6 @@ include $(LOCAL_PATH)/minui/Android.mk \
include $(commands_recovery_local_path)/libjpegtwrp/Android.mk \
    $(commands_recovery_local_path)/injecttwrp/Android.mk \
    $(commands_recovery_local_path)/htcdumlock/Android.mk \
    $(commands_recovery_local_path)/minuitwrp/Android.mk \
    $(commands_recovery_local_path)/gui/Android.mk \
    $(commands_recovery_local_path)/mmcutils/Android.mk \
    $(commands_recovery_local_path)/bmlutils/Android.mk \
@@ -305,13 +304,15 @@ include $(commands_recovery_local_path)/libjpegtwrp/Android.mk \
    $(commands_recovery_local_path)/crypto/cryptfs/Android.mk \
    $(commands_recovery_local_path)/libcrecovery/Android.mk \
    $(commands_recovery_local_path)/twmincrypt/Android.mk \
    $(commands_recovery_local_path)/libblkid/Android.mk
    $(commands_recovery_local_path)/libblkid/Android.mk \
    $(commands_recovery_local_path)/minuitwrp/Android.mk

ifeq ($(TW_INCLUDE_CRYPTO_SAMSUNG), true)
    include $(commands_recovery_local_path)/crypto/libcrypt_samsung/Android.mk
endif

ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
    include $(commands_recovery_local_path)/crypto/jb/Android.mk
    include $(commands_recovery_local_path)/crypto/fs_mgr/Android.mk
endif
ifeq ($(BUILD_ID), GINGERBREAD)
@@ -323,5 +324,8 @@ ifneq ($(TW_NO_EXFAT), true)
            $(commands_recovery_local_path)/fuse/Android.mk \
            $(commands_recovery_local_path)/exfat/libexfat/Android.mk
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
    include $(commands_recovery_local_path)/crypto/ics/Android.mk
endif

commands_recovery_local_path :=
+16 −20
Original line number Diff line number Diff line
@@ -24,17 +24,13 @@
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
#include <stdio.h>

#include "ui.h"
#include "cutils/properties.h"
#include "install.h"
#include "common.h"
#include "adb_install.h"
extern "C" {
#include "minadbd/adb.h"
#include "twinstall.h"
#include "data.h"
int TWinstall_zip(const char* path, int* wipe_cache);
}

static RecoveryUI* ui = NULL;
@@ -47,20 +43,20 @@ set_usb_driver(bool enabled) {
   It's not a critical error so we're disabling the error messages.
        ui->Print("failed to open driver control: %s\n", strerror(errno));
*/
		LOGI("failed to open driver control: %s\n", strerror(errno));
		printf("failed to open driver control: %s\n", strerror(errno));
        return;
    }
    if (write(fd, enabled ? "1" : "0", 1) < 0) {
/*
        ui->Print("failed to set driver control: %s\n", strerror(errno));
*/
		LOGI("failed to set driver control: %s\n", strerror(errno));
		printf("failed to set driver control: %s\n", strerror(errno));
    }
    if (close(fd) < 0) {
/*
        ui->Print("failed to close driver control: %s\n", strerror(errno));
*/
		LOGI("failed to close driver control: %s\n", strerror(errno));
		printf("failed to close driver control: %s\n", strerror(errno));
    }
}

@@ -76,28 +72,29 @@ maybe_restart_adbd() {
    char value[PROPERTY_VALUE_MAX+1];
    int len = property_get("ro.debuggable", value, NULL);
    if (len == 1 && value[0] == '1') {
        ui->Print("Restarting adbd...\n");
        printf("Restarting adbd...\n");
        set_usb_driver(true);
        property_set("ctl.start", "adbd");
    }
}

int
apply_from_adb(RecoveryUI* ui_, int* wipe_cache, const char* install_file) {
    ui = ui_;
apply_from_adb(const char* install_file) {

    stop_adbd();
    set_usb_driver(true);

/*
    ui->Print("\n\nNow send the package you want to apply\n"
              "to the device with \"adb sideload <filename>\"...\n");

*/
    pid_t child;
    if ((child = fork()) == 0) {
        execl("/sbin/recovery", "recovery", "--adbd", install_file, NULL);
        _exit(-1);
    }
	DataManager_SetIntValue("tw_child_pid", child);
	char child_prop[PROPERTY_VALUE_MAX];
	sprintf(child_prop, "%i", child);
	property_set("tw_child_pid", child_prop);
    int status;
    // TODO(dougz): there should be a way to cancel waiting for a
    // package (by pushing some button combo on the device).  For now
@@ -105,20 +102,19 @@ apply_from_adb(RecoveryUI* ui_, int* wipe_cache, const char* install_file) {
    // package, like "/dev/null".
    waitpid(child, &status, 0);
    if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
        ui->Print("status %d\n", WEXITSTATUS(status));
        printf("status %d\n", WEXITSTATUS(status));
    }
	DataManager_SetIntValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start
    set_usb_driver(false);
    maybe_restart_adbd();

    struct stat st;
    if (stat(install_file, &st) != 0) {
        if (errno == ENOENT) {
            ui->Print("No package received.\n");
            printf("No package received.\n");
        } else {
            ui->Print("Error reading package:\n  %s\n", strerror(errno));
            printf("Error reading package:\n  %s\n", strerror(errno));
        }
        return INSTALL_ERROR;
        return -1;
    }
	return TWinstall_zip(install_file, wipe_cache);
	return 0;
}
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
#ifndef _ADB_INSTALL_H
#define _ADB_INSTALL_H

class RecoveryUI;
//class RecoveryUI;

int apply_from_adb(RecoveryUI* h, int* wipe_cache, const char* install_file);
int apply_from_adb(const char* install_file);

#endif
+65 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ static int get_bootloader_message_block(struct bootloader_message *out, const Vo
static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v);

int get_bootloader_message(struct bootloader_message *out) {
    Volume* v = volume_for_path("/misc");
    Volume* v = NULL;//volume_for_path("/misc");
    if (v == NULL) {
      LOGE("Cannot load volume /misc!\n");
      return -1;
@@ -48,7 +48,7 @@ int get_bootloader_message(struct bootloader_message *out) {
}

int set_bootloader_message(const struct bootloader_message *in) {
    Volume* v = volume_for_path("/misc");
    Volume* v = NULL;//volume_for_path("/misc");
    if (v == NULL) {
      LOGE("Cannot load volume /misc!\n");
      return -1;
@@ -139,6 +139,49 @@ static int set_bootloader_message_mtd(const struct bootloader_message *in,
    return 0;
}

int set_bootloader_message_mtd_name(const struct bootloader_message *in,
                                      const char* mtd_name) {
    size_t write_size;
    mtd_scan_partitions();
    const MtdPartition *part = mtd_find_partition_by_name(mtd_name);
    if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
        printf("Can't find %s\n", mtd_name);
        return -1;
    }

    MtdReadContext *read = mtd_read_partition(part);
    if (read == NULL) {
        printf("Can't open %s\n(%s)\n", mtd_name, strerror(errno));
        return -1;
    }

    ssize_t size = write_size * MISC_PAGES;
    char data[size];
    ssize_t r = mtd_read_data(read, data, size);
    if (r != size) printf("Can't read %s\n(%s)\n", mtd_name, strerror(errno));
    mtd_read_close(read);
    if (r != size) return -1;

    memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));

    MtdWriteContext *write = mtd_write_partition(part);
    if (write == NULL) {
        printf("Can't open %s\n(%s)\n", mtd_name, strerror(errno));
        return -1;
    }
    if (mtd_write_data(write, data, size) != size) {
        printf("Can't write %s\n(%s)\n", mtd_name, strerror(errno));
        mtd_write_close(write);
        return -1;
    }
    if (mtd_write_close(write)) {
        printf("Can't finish %s\n(%s)\n", mtd_name, strerror(errno));
        return -1;
    }

    printf("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : "");
    return 0;
}

// ------------------------------------
// for misc partitions on block devices
@@ -202,3 +245,23 @@ static int set_bootloader_message_block(const struct bootloader_message *in,
    }
    return 0;
}

int set_bootloader_message_block_name(const struct bootloader_message *in,
                                        const char* block_name) {
    wait_for_device(block_name);
    FILE* f = fopen(block_name, "wb");
    if (f == NULL) {
        printf("Can't open %s\n(%s)\n", block_name, strerror(errno));
        return -1;
    }
    int count = fwrite(in, sizeof(*in), 1, f);
    if (count != 1) {
        printf("Failed writing %s\n(%s)\n", block_name, strerror(errno));
        return -1;
    }
    if (fclose(f) != 0) {
        printf("Failed closing %s\n(%s)\n", block_name, strerror(errno));
        return -1;
    }
    return 0;
}
+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@ struct bootloader_message {
int get_bootloader_message(struct bootloader_message *out);
int set_bootloader_message(const struct bootloader_message *in);

int set_bootloader_message_mtd_name(const struct bootloader_message *in, const char* mtd_name);
int set_bootloader_message_block_name(const struct bootloader_message *in, const char* block_name);

#ifdef __cplusplus
}
#endif
Loading