summaryrefslogtreecommitdiff
authorZhigang Yu <zhigang.yu@amlogic.com>2017-08-28 12:06:59 (GMT)
committer Zhigang Yu <zhigang.yu@amlogic.com>2017-08-29 02:25:58 (GMT)
commit800494b577b6837a37afe3e2888a5dca151de947 (patch)
treeddcb7e36c52a1accbe8661553f9ad4c6e5753e0e
parent677e98b7d0edd7e19743995c0a040ba2ec73f4f8 (diff)
downloadamlogic-o-800494b577b6837a37afe3e2888a5dca151de947.zip
amlogic-o-800494b577b6837a37afe3e2888a5dca151de947.tar.gz
amlogic-o-800494b577b6837a37afe3e2888a5dca151de947.tar.bz2
ota: add fun for mark update middle status[2/2]
PD# 149779 1.add fun for mark update middle status 2.define TARGET_OTA_PARTITION_CHANGE := true Change-Id: I679fdada16a61db52abe69c2c6f2c1ea122dd1d1
Diffstat
-rw-r--r--common/recovery/check/dtbcheck.cpp55
-rw-r--r--common/recovery/updater_extra/install_amlogic.cpp84
-rw-r--r--p212/BoardConfig.mk1
-rw-r--r--p230/BoardConfig.mk1
4 files changed, 140 insertions, 1 deletions
diff --git a/common/recovery/check/dtbcheck.cpp b/common/recovery/check/dtbcheck.cpp
index 42230ee..9d13bee 100644
--- a/common/recovery/check/dtbcheck.cpp
+++ b/common/recovery/check/dtbcheck.cpp
@@ -631,6 +631,61 @@ GetDevDtbImage(){
}
int
+GetEnvPartitionOffset(const ZipArchiveHandle za) {
+ int i = 0;
+ int find = 0;
+ int ret = -1;
+ int offset = 116*1024*1024; //bootloader(4M) GAP(32M) reserved(64M) GAP(8M) cache(--) GAP(8M)
+ int imageSize = 0;
+ int partition_num_zip = 0;
+
+ ret = GetZipDtbImage(za, DTB_IMG, &imageSize);
+ if ((ret == 0) || (ret == 2)) {
+ printf("no dtb.img in the update or no need check dtb, check dtb over!\n");
+ return 0;
+ } else if (ret < 0) {
+ printf("get dtb.img from update.zip failed!\n");
+ ret = -1;
+ goto END;
+ }
+
+ working_fdt = (struct fdt_header *)s_pDtbBuffer;
+
+ ret = GetPartitionFromDtb("/partitions", MAX_LEVEL, &partition_num_zip, 0);
+ if (ret != 0) {
+ printf("get partition map from dtb.img failed!\n");
+ ret = -1;
+ goto END;
+ }
+
+ for (i=0; i<partition_num_zip;i++) {
+ printf("%s:0x%08x\n", dtb_zip[i].partition_name, dtb_zip[i].partition_size);
+ if (!strcmp("cache", dtb_zip[i].partition_name)) {
+ offset += dtb_zip[i].partition_size;
+ find = 1;
+ }
+ }
+
+ if (find == 0) {
+ printf("get cache partition size from dtb.img failed!\n");
+ ret = -1;
+ goto END;
+ }
+ printf("env partition offset:0x%08x\n", offset);
+
+ ret = offset;
+
+END:
+ if (s_pDtbBuffer != NULL)
+ {
+ free(s_pDtbBuffer);
+ s_pDtbBuffer = NULL;
+ }
+
+ return ret;
+}
+
+int
RecoveryDtbCheck(const ZipArchiveHandle za){
int i = 0, ret = -1, err = -1;
int fd = -1;
diff --git a/common/recovery/updater_extra/install_amlogic.cpp b/common/recovery/updater_extra/install_amlogic.cpp
index 42650d7..763fe1d 100644
--- a/common/recovery/updater_extra/install_amlogic.cpp
+++ b/common/recovery/updater_extra/install_amlogic.cpp
@@ -81,6 +81,7 @@ static const char *sEmmcPartionName[] = {
int RecoverySecureCheck(const ZipArchiveHandle zipArchive);
int RecoveryDtbCheck(const ZipArchiveHandle zipArchive);
+int GetEnvPartitionOffset(const ZipArchiveHandle za);
/*
* return value: 0 if no error; 1 if path not existed, -1 if access failed
*
@@ -561,7 +562,7 @@ Value* SetBootloaderEnvFn(const char* name, State* state, const std::vector<std:
}
//rm backup dtb.img and recovery.img
- if ((!strcmp(env_name.c_str(), "1")) || (!strcmp(env_val.c_str(), "2"))) {
+ if ((!strcmp(env_val.c_str(), "1")) || (!strcmp(env_val.c_str(), "2"))) {
struct stat st;
if (stat("/cache/recovery/dtb.img", &st) == 0) {
unlink("/cache/recovery/dtb.img");
@@ -659,6 +660,84 @@ Value* RebootRecovery(const char* name, State* state, const std::vector<std::uni
return ErrorAbort(state, "reboot to recovery failed!\n");
}
+Value* SetUpdateStage(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) {
+ int ret = 0;
+ if (argv.size() != 1) {
+ return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 args, got %zu", name, argv.size());
+ }
+
+ std::vector<std::string> args;
+ if (!ReadArgs(state, argv, &args)) {
+ return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name);
+ }
+
+ const std::string& stage_step = args[0];
+
+ FILE *pf = fopen("/cache/recovery/stage", "w+");
+ if (pf == NULL) {
+ return ErrorAbort(state, "fopen stage failed!\n");
+ }
+
+ int len = fwrite(stage_step.c_str(), 1, strlen(stage_step.c_str()), pf);
+ printf("stage write len:%d, %s\n", len, stage_step.c_str());
+ fflush(pf);
+ fclose(pf);
+
+ return StringValue("done");
+}
+
+Value* GetUpdateStage(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) {
+ char buff[128] = {0};
+
+ FILE *pf = fopen("/cache/recovery/stage", "r");
+ if (pf == NULL) {
+ return StringValue("0");
+ }
+
+ int len = fread(buff, 1, 128, pf);
+ printf("stage fread len:%d, %s\n", len, buff);
+ fclose(pf);
+
+ return StringValue(buff);
+}
+
+Value* BackupEnvPartition(const char* name, State* state,
+ const std::vector<std::unique_ptr<Expr>>&argv) {
+ int offset = 0;
+ char tmpbuf[32] = {0};
+ ZipArchiveHandle za = static_cast<UpdaterInfo*>(state->cookie)->package_zip;
+
+ offset = GetEnvPartitionOffset(za);
+ if (offset <= 0) {
+ return ErrorAbort(state, "get env partition offset failed!\n");
+ }
+
+ offset = offset/(1024*1024);
+
+ sprintf(tmpbuf, "%s%d", "seek=", offset);
+ char *args2[7] = {"/sbin/busybox", "dd", "if=/dev/block/env", "of=/dev/block/mmcblk0", "bs=1M"};
+ args2[5] = &tmpbuf[0];
+ args2[6] = nullptr;
+ pid_t child = fork();
+ if (child == 0) {
+ execv("/sbin/busybox", args2);
+ printf("execv failed\n");
+ _exit(EXIT_FAILURE);
+ }
+
+ int status;
+ waitpid(child, &status, 0);
+ if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status) != 0) {
+ ErrorAbort(state,"child exited with status:%d\n", WEXITSTATUS(status));
+ }
+ } else if (WIFSIGNALED(status)) {
+ ErrorAbort(state,"child terminated by signal :%d\n", WTERMSIG(status));
+ }
+
+ return StringValue(strdup("0"));
+}
+
void Register_libinstall_amlogic() {
RegisterFunction("write_dtb_image", WriteDtbImageFn);
RegisterFunction("write_bootloader_image", WriteBootloaderImageFn);
@@ -666,4 +745,7 @@ void Register_libinstall_amlogic() {
RegisterFunction("backup_data_cache", BackupDataCache);
RegisterFunction("set_bootloader_env", SetBootloaderEnvFn);
RegisterFunction("ota_zip_check", OtaZipCheck);
+ RegisterFunction("get_update_stage", GetUpdateStage);
+ RegisterFunction("set_update_stage", SetUpdateStage);
+ RegisterFunction("backup_env_partition", BackupEnvPartition);
}
diff --git a/p212/BoardConfig.mk b/p212/BoardConfig.mk
index fe08d82..4e8b73b 100644
--- a/p212/BoardConfig.mk
+++ b/p212/BoardConfig.mk
@@ -97,6 +97,7 @@ TARGET_RELEASETOOLS_EXTENSIONS := device/amlogic/common
TARGET_USE_BLOCK_BASE_UPGRADE := true
TARGET_OTA_UPDATE_DTB := true
#TARGET_RECOVERY_DISABLE_ADB_SIDELOAD := true
+#TARGET_OTA_PARTITION_CHANGE := true
TARGET_RECOVERY_UPDATER_LIBS := libinstall_amlogic
diff --git a/p230/BoardConfig.mk b/p230/BoardConfig.mk
index bdde261..dba6511 100644
--- a/p230/BoardConfig.mk
+++ b/p230/BoardConfig.mk
@@ -98,6 +98,7 @@ TARGET_RELEASETOOLS_EXTENSIONS := device/amlogic/common
TARGET_USE_BLOCK_BASE_UPGRADE := true
TARGET_OTA_UPDATE_DTB := true
#TARGET_RECOVERY_DISABLE_ADB_SIDELOAD := true
+#TARGET_OTA_PARTITION_CHANGE := true
TARGET_RECOVERY_UPDATER_LIBS := libinstall_amlogic