From f59a9a8203a7e8d9cc7827867b91fe1f757d7b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 01:42:05 +0000 Subject: [PATCH 01/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index acee8550..d46efd9f 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -27,6 +27,7 @@ #include "applypatch/store.h" #include "applypatch/transfer_manager.h" #include "applypatch/partition_record.h" +#include "applypatch/partition_record.h" #include "diffpatch/diffpatch.h" #include "dump.h" #include "fs_manager/mount.h" -- Gitee From 45790fae115ca39b0527eb36220991cc85679ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 01:43:05 +0000 Subject: [PATCH 02/12] update services/updater_binary/update_image_patch.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/updater_binary/update_image_patch.h b/services/updater_binary/update_image_patch.h index ce5af69c..c510c0be 100644 --- a/services/updater_binary/update_image_patch.h +++ b/services/updater_binary/update_image_patch.h @@ -60,6 +60,8 @@ public: USInstrImageShaCheck() {} virtual ~USInstrImageShaCheck() {} int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; + virtual GetParam(Uscript::UScriptContext &context, CheckPara ¶); + virtual GetParam(Uscript::UScriptContext &context, CheckPara ¶); private: int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); -- Gitee From 1ed2e899d538b38e83be1135d82009dc6af3c391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 01:46:24 +0000 Subject: [PATCH 03/12] update services/updater_binary/update_image_patch.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/updater_binary/update_image_patch.h b/services/updater_binary/update_image_patch.h index c510c0be..640d619f 100644 --- a/services/updater_binary/update_image_patch.h +++ b/services/updater_binary/update_image_patch.h @@ -60,8 +60,8 @@ public: USInstrImageShaCheck() {} virtual ~USInstrImageShaCheck() {} int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; - virtual GetParam(Uscript::UScriptContext &context, CheckPara ¶); - virtual GetParam(Uscript::UScriptContext &context, CheckPara ¶); + virtual std::string GetDevicePath(const std::string &partName); + virtual std::string GetHashData(const CheckPara ¶, const size_t length); private: int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); -- Gitee From 7546d5a02d21d1419cd53a93a23916ab30075419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 01:56:05 +0000 Subject: [PATCH 04/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- .../updater_binary/update_image_patch.cpp | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index d46efd9f..9c455301 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -27,12 +27,13 @@ #include "applypatch/store.h" #include "applypatch/transfer_manager.h" #include "applypatch/partition_record.h" -#include "applypatch/partition_record.h" +#include "applypatch/update_progress.h" #include "diffpatch/diffpatch.h" #include "dump.h" #include "fs_manager/mount.h" #include "log/log.h" #include "patch/update_patch.h" +#include "threadpool/thread_pool.h" #include "updater/updater_const.h" #include "updater/hardware_fault_retry.h" #include "utils.h" @@ -244,6 +245,11 @@ int32_t USInstrImageShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::UScript return result; } +std::string USInstrImageShaCheck::GetDevicePath(const std::string &partName) +{ + return GetBlockDeviceByMountPoint(partName); +} + int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPara ¶) { if (context.GetParamCount() != IMAGE_PATCH_CHECK_CMD_LEN) { @@ -261,9 +267,9 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa return USCRIPT_INVALID_PARAM; } - para.devPath = GetBlockDeviceByMountPoint(para.partName); + para.devPath = GetDevicePath(para.partName); #ifndef UPDATER_UT - if (para.partName != "/userdata") { + if (para.partName != "/userdata" && para.devPath.find("dm") == std::string::npos) { std::string suffix = Utils::GetUpdateSuffix(); para.devPath += suffix; } @@ -271,36 +277,47 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa para.devPath = "/data/updater" + para.partName; #endif if (para.devPath.empty()) { - LOG(ERROR) << "cannot get block device of partition" << para.partName; + LOG(ERROR) << "cannot get block device of partition " << para.partName; return USCRIPT_ERROR_EXECUTE; } LOG(INFO) << "dev path: " << para.devPath; return USCRIPT_SUCCESS; } -int32_t USInstrImageShaCheck::CheckHash(const CheckPara ¶) +std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const size_t length) { UpdatePatch::MemMapInfo mapBuffer {}; if (PatchMapFile(para.devPath, mapBuffer) != UpdatePatch::PATCH_SUCCESS) { LOG(ERROR) << "PatchMapFile error"; - return USCRIPT_ERROR_EXECUTE; + return ""; } - if (!std::all_of(para.srcSize.begin(), para.srcSize.end(), ::isdigit)) { + UpdatePatch::BlockBuffer data = { mapBuffer.memory, length }; + std::string resultSha = UpdatePatch::GeneraterBufferHash(data); + std::transform(resultSha.begin(), resultSha.end(), resultSha.begin(), ::toupper); + return resultSha; +} + +int32_t USInstrImageShaCheck::CheckHash(const CheckPara ¶) +{ + if (para.srcSize.empty() || !std::all_of(para.srcSize.begin(), para.srcSize.end(), ::isdigit)) { LOG(ERROR) << "para size error " << para.srcSize; return USCRIPT_ERROR_EXECUTE; } - uint32_t length = 0; - if (!Utils::ConvertToUnsignedLong(para.srcSize, length)) { + size_t length = 0; + if (!Utils::ConvertToUnsignedLongLong(para.srcSize, length)) { LOG(ERROR) << "ConvertToUnsignedLong error"; return USCRIPT_ERROR_EXECUTE; } - UpdatePatch::BlockBuffer data = { mapBuffer.memory, length }; - std::string resultSha = UpdatePatch::GeneraterBufferHash(data); - std::transform(resultSha.begin(), resultSha.end(), resultSha.begin(), ::toupper); + std::string resultSha = GetHashData(para, length); + if (resultSha.empty()) { + LOG(ERROR) << "get hash fail of partition " << para.partName; + return USCRIPT_ERROR_EXECUTE; + } if (resultSha != para.srcHash) { - LOG(ERROR) << "resultSha:" << resultSha << " srcHash:" << para.srcHash; + LOG(ERROR) << para.partName << " resultSha:" << resultSha << " srcHash:" << para.srcHash; return USCRIPT_INVALID_PARAM; } + SetUpdateProgress(Uscript::GetScriptProportion() * Uscript::GetTotalProportion()); return USCRIPT_SUCCESS; } -- Gitee From ae9301990a2322aa970a16a7770310596aa2e602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 02:16:52 +0000 Subject: [PATCH 05/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index 9c455301..44bd0c1b 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -247,7 +247,12 @@ int32_t USInstrImageShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::UScript std::string USInstrImageShaCheck::GetDevicePath(const std::string &partName) { - return GetBlockDeviceByMountPoint(partName); + std::string devPath = GetBlockDeviceByMountPoint(partName); + if (partName != "/userdata") { + std::string suffix = Utils::GetUpdateSuffix(); + devPath += suffix; + } + return devPath; } int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPara ¶) @@ -267,12 +272,8 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa return USCRIPT_INVALID_PARAM; } - para.devPath = GetDevicePath(para.partName); #ifndef UPDATER_UT - if (para.partName != "/userdata" && para.devPath.find("dm") == std::string::npos) { - std::string suffix = Utils::GetUpdateSuffix(); - para.devPath += suffix; - } + para.devPath = GetDevicePath(para.partName); #else para.devPath = "/data/updater" + para.partName; #endif -- Gitee From bf5161faab8db7150478c5a63ad58c630e8b94a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 09:19:33 +0000 Subject: [PATCH 06/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index 44bd0c1b..5ecf8abe 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -285,7 +285,7 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa return USCRIPT_SUCCESS; } -std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const size_t length) +std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const uint64_t length) { UpdatePatch::MemMapInfo mapBuffer {}; if (PatchMapFile(para.devPath, mapBuffer) != UpdatePatch::PATCH_SUCCESS) { @@ -304,7 +304,7 @@ int32_t USInstrImageShaCheck::CheckHash(const CheckPara ¶) LOG(ERROR) << "para size error " << para.srcSize; return USCRIPT_ERROR_EXECUTE; } - size_t length = 0; + uint64_t length = 0; if (!Utils::ConvertToUnsignedLongLong(para.srcSize, length)) { LOG(ERROR) << "ConvertToUnsignedLong error"; return USCRIPT_ERROR_EXECUTE; -- Gitee From f0107b5e64126e678ff37b64c428907d75931873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 09:20:19 +0000 Subject: [PATCH 07/12] update services/updater_binary/update_image_patch.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/updater_binary/update_image_patch.h b/services/updater_binary/update_image_patch.h index 640d619f..8a7ed636 100644 --- a/services/updater_binary/update_image_patch.h +++ b/services/updater_binary/update_image_patch.h @@ -61,7 +61,7 @@ public: virtual ~USInstrImageShaCheck() {} int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; virtual std::string GetDevicePath(const std::string &partName); - virtual std::string GetHashData(const CheckPara ¶, const size_t length); + virtual std::string GetHashData(const CheckPara ¶, const uint64_t length); private: int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); -- Gitee From eb79de708068c42bf1aac794c5d32af9c77d9200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 10:07:14 +0000 Subject: [PATCH 08/12] update services/updater_binary/update_image_patch.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/updater_binary/update_image_patch.h b/services/updater_binary/update_image_patch.h index 8a7ed636..640d619f 100644 --- a/services/updater_binary/update_image_patch.h +++ b/services/updater_binary/update_image_patch.h @@ -61,7 +61,7 @@ public: virtual ~USInstrImageShaCheck() {} int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; virtual std::string GetDevicePath(const std::string &partName); - virtual std::string GetHashData(const CheckPara ¶, const uint64_t length); + virtual std::string GetHashData(const CheckPara ¶, const size_t length); private: int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); -- Gitee From b08ad03dbe63da25210610fd1c24ba88bf87e3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 10:10:17 +0000 Subject: [PATCH 09/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index 5ecf8abe..425e4bf6 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -285,7 +285,7 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa return USCRIPT_SUCCESS; } -std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const uint64_t length) +std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const size_t length) { UpdatePatch::MemMapInfo mapBuffer {}; if (PatchMapFile(para.devPath, mapBuffer) != UpdatePatch::PATCH_SUCCESS) { @@ -304,8 +304,8 @@ int32_t USInstrImageShaCheck::CheckHash(const CheckPara ¶) LOG(ERROR) << "para size error " << para.srcSize; return USCRIPT_ERROR_EXECUTE; } - uint64_t length = 0; - if (!Utils::ConvertToUnsignedLongLong(para.srcSize, length)) { + size_t length = 0; + if (!Utils::ConvertToUnsignedLongLong(para.srcSize, static_cast(length))) { LOG(ERROR) << "ConvertToUnsignedLong error"; return USCRIPT_ERROR_EXECUTE; } -- Gitee From b54b6c17cc444cde15eab6ed472a917e74d29fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 10:13:48 +0000 Subject: [PATCH 10/12] update services/updater_binary/update_image_patch.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/updater_binary/update_image_patch.h b/services/updater_binary/update_image_patch.h index 640d619f..8a7ed636 100644 --- a/services/updater_binary/update_image_patch.h +++ b/services/updater_binary/update_image_patch.h @@ -61,7 +61,7 @@ public: virtual ~USInstrImageShaCheck() {} int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; virtual std::string GetDevicePath(const std::string &partName); - virtual std::string GetHashData(const CheckPara ¶, const size_t length); + virtual std::string GetHashData(const CheckPara ¶, const uint64_t length); private: int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); -- Gitee From 3f4c3351bbd29503007c47ad9b792cfaa176c4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 10:14:19 +0000 Subject: [PATCH 11/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index 425e4bf6..c6162e17 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -285,7 +285,7 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa return USCRIPT_SUCCESS; } -std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const size_t length) +std::string USInstrImageShaCheck::GetHashData(const CheckPara ¶, const uint64_t length) { UpdatePatch::MemMapInfo mapBuffer {}; if (PatchMapFile(para.devPath, mapBuffer) != UpdatePatch::PATCH_SUCCESS) { -- Gitee From 2ae3ea33505d995d97aa7d87d11a5559907a1aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Wed, 27 Aug 2025 10:15:18 +0000 Subject: [PATCH 12/12] update services/updater_binary/update_image_patch.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/updater_binary/update_image_patch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index c6162e17..5ecf8abe 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -304,8 +304,8 @@ int32_t USInstrImageShaCheck::CheckHash(const CheckPara ¶) LOG(ERROR) << "para size error " << para.srcSize; return USCRIPT_ERROR_EXECUTE; } - size_t length = 0; - if (!Utils::ConvertToUnsignedLongLong(para.srcSize, static_cast(length))) { + uint64_t length = 0; + if (!Utils::ConvertToUnsignedLongLong(para.srcSize, length)) { LOG(ERROR) << "ConvertToUnsignedLong error"; return USCRIPT_ERROR_EXECUTE; } -- Gitee