diff options
author | Steve Kondik <steve@cyngn.com> | 2015-10-12 09:56:15 -1000 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-12 09:56:15 -1000 |
commit | 70ef33f58bb8199279136a613e89285631fb1f44 (patch) | |
tree | 1ba855eb0ae1f897cf29fc465fa2fb8c781f83fc | |
parent | 4e77523999a944331f73fa723115fa56ca38334c (diff) | |
parent | e8baf4a8e8d8a8de4ae276a9f29956008c13f7ba (diff) | |
download | bootable_recovery-70ef33f58bb8199279136a613e89285631fb1f44.zip bootable_recovery-70ef33f58bb8199279136a613e89285631fb1f44.tar.gz bootable_recovery-70ef33f58bb8199279136a613e89285631fb1f44.tar.bz2 |
Merge branch 'LA.BF64.1.2.2_rb4.1' of git://codeaurora.org/platform/bootable/recovery into caf-merge
Change-Id: Ie03faab6af46354caac6e4c65c2d4319838b3501
-rw-r--r-- | Android.mk | 4 | ||||
-rw-r--r-- | device.h | 3 | ||||
-rw-r--r-- | install.cpp | 64 | ||||
-rw-r--r-- | recovery.cpp | 4 | ||||
-rw-r--r-- | updater/Android.mk | 1 | ||||
-rw-r--r-- | updater/install.c | 69 |
6 files changed, 144 insertions, 1 deletions
@@ -88,6 +88,10 @@ endif LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin +ifeq ($(TARGET_USE_MDTP), true) + LOCAL_CFLAGS += -DUSE_MDTP +endif + ifeq ($(TARGET_RECOVERY_UI_LIB),) LOCAL_SRC_FILES += default_device.cpp else @@ -102,6 +102,9 @@ class Device { virtual bool PreWipeData() { return true; } virtual bool PostWipeData() { return true; } + // Called before reboot + virtual char const* GetRebootReason() { return ""; } + private: RecoveryUI* ui_; }; diff --git a/install.cpp b/install.cpp index c7d382f..be97987 100644 --- a/install.cpp +++ b/install.cpp @@ -22,6 +22,7 @@ #include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> +#include <sys/mount.h> #include "common.h" #include "install.h" @@ -194,6 +195,58 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache) { return INSTALL_SUCCESS; } +#ifdef USE_MDTP +static int +mdtp_update() +{ + const char** args = (const char**)malloc(sizeof(char*) * 2); + + if (args == NULL) { + LOGE("Failed to allocate memory for MDTP FOTA app arguments\n"); + return 0; + } + + args[0] = "/sbin/mdtp_fota"; + args[1] = NULL; + int status = 0; + + ui->Print("Running MDTP integrity verification and update...\n"); + + /* Make sure system partition is mounted, so MDTP can process its content. */ + mkdir("/system", 0755); + status = mount("/dev/block/bootdevice/by-name/system", "/system", "ext4", + MS_NOATIME | MS_NODEV | MS_NODIRATIME | + MS_RDONLY, ""); + + if (status) { + LOGE("Failed to mount the system partition, error=%s.\n", strerror(errno)); + free(args); + return 0; + } + + status = 0; + + pid_t pid = fork(); + if (pid == 0) { + execv(args[0], (char* const*)args); + LOGE("Can't run %s (%s)\n", args[0], strerror(errno)); + _exit(-1); + } + if (pid > 0) { + LOGE("Waiting for MDTP FOTA to complete...\n"); + pid = waitpid(pid, &status, 0); + LOGE("MDTP FOTA completed, status: %d\n", status); + } + + /* Leave the system partition unmounted before we finish. */ + umount("/system"); + + free(args); + + return (status > 0) ? 1 : 0; +} +#endif /* USE_MDTP */ + static int really_install_package(const char *path, bool* wipe_cache, bool needs_mount) { @@ -261,6 +314,17 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount) sysReleaseMap(&map); +#ifdef USE_MDTP + /* If MDTP update failed, return an error such that recovery will not finish. */ + if (result == INSTALL_SUCCESS) { + if (!mdtp_update()) { + ui->Print("Unable to verify integrity of /system for MDTP, update aborted.\n"); + return INSTALL_ERROR; + } + ui->Print("Successfully verified integrity of /system for MDTP.\n"); + } +#endif /* USE_MDTP */ + return result; } diff --git a/recovery.cpp b/recovery.cpp index b7a5458..5923c81 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1110,8 +1110,10 @@ main(int argc, char **argv) { break; default: + char reason[PROPERTY_VALUE_MAX]; + snprintf(reason, PROPERTY_VALUE_MAX, "reboot,%s", device->GetRebootReason()); ui->Print("Rebooting...\n"); - property_set(ANDROID_RB_PROPERTY, "reboot,"); + property_set(ANDROID_RB_PROPERTY, reason); break; } sleep(5); // should reboot before this finishes diff --git a/updater/Android.mk b/updater/Android.mk index 1bdf977..f4ed954 100644 --- a/updater/Android.mk +++ b/updater/Android.mk @@ -62,6 +62,7 @@ inc := $(call intermediates-dir-for,PACKAGING,updater_extensions,,,32)/register. else inc := $(call intermediates-dir-for,PACKAGING,updater_extensions)/register.inc endif + # Encode the value of TARGET_RECOVERY_UPDATER_LIBS into the filename of the dependency. # So if TARGET_RECOVERY_UPDATER_LIBS is changed, a new dependency file will be generated. # Note that we have to remove any existing depency files before creating new one, diff --git a/updater/install.c b/updater/install.c index 01a5dd2..ba2dda7 100644 --- a/updater/install.c +++ b/updater/install.c @@ -931,6 +931,74 @@ Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) { return StringValue(strdup(value)); } +//Check to confirm if this is the same hardware as the one the package was +//generated on or not. 32 vs 64 bit variants are upgrade compatible but have +//names such as msmWXYZ msmWXYZ_32 vs msmWXYZ_64.Input to this +//function is the BuildProp value that gets stored in the update package +//at the time it it created. +Value* ConfirmDevVariant(const char* name, State* state, int argc, Expr* argv[]) +{ + //ro.product.device that was on the build that the update package was made + //from + char* package_dev_variant; + //ro.product.device on the current hardware + char current_dev_variant[PROPERTY_VALUE_MAX]; + int comparison_len; + int package_dev_variant_len; + int current_dev_variant_len; + if (argc != 1) { + return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + } + package_dev_variant = Evaluate(state, argv[0]); + if (!package_dev_variant) goto error; + property_get("ro.product.device", current_dev_variant, "n/a"); + if (!strncmp(current_dev_variant,"n/a",3)) { + ErrorAbort(state, "Failed to get valid ro.product.device"); + goto error; + } + package_dev_variant_len = strlen(package_dev_variant); + current_dev_variant_len = strlen(current_dev_variant); + //Ensure device variant lengths are atleast 3 characters long + if ((package_dev_variant_len < 3) || (current_dev_variant_len < 3)) { + ErrorAbort(state, "Device Variant length is less than 3 characters"); + goto error; + } + //Length of the largest string - 3(for _32/64) + comparison_len = + (package_dev_variant_len >= current_dev_variant_len ? + package_dev_variant_len : + current_dev_variant_len) - 3; + //Complete match + if (!strncmp(current_dev_variant, package_dev_variant, + strlen(current_dev_variant))) + goto success; + //Match except for the last 3 char's of either string which are _32 or _64 + if (!strncmp(current_dev_variant, package_dev_variant, comparison_len)) { + if (package_dev_variant_len >= current_dev_variant_len) { + if (!strncmp(&package_dev_variant[package_dev_variant_len-3], + "_32", 3) || + !strncmp(&package_dev_variant[package_dev_variant_len-3], + "_64", 3)) + goto success; + } else { + if (!strncmp(¤t_dev_variant[current_dev_variant_len-3], + "_32", 3) || + !strncmp(¤t_dev_variant[current_dev_variant_len-3], + "_64", 3)) + goto success; + } + ErrorAbort(state, "Invalid target for update package"); + goto error; + } +success: + free(package_dev_variant); + return StringValue(strdup("OK")); +error: + if (package_dev_variant) { + free(package_dev_variant); + } + return StringValue(strdup("ERROR")); +} // file_getprop(file, key) // @@ -1622,4 +1690,5 @@ void RegisterInstallFunctions() { RegisterFunction("enable_reboot", EnableRebootFn); RegisterFunction("tune2fs", Tune2FsFn); + RegisterFunction("get_device_compatible", ConfirmDevVariant); } |