From ddb6b2ac99fdad00b6b7abfe02090adb0a46e3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Wed, 28 May 2025 15:21:45 +0800 Subject: [PATCH 01/21] =?UTF-8?q?chunk=E6=A0=BC=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/BUILD.gn | 1 + services/stream_update/bin_chunk_update.cpp | 128 +++++++++++++++++++- services/stream_update/bin_chunk_update.h | 18 +++ 3 files changed, 144 insertions(+), 3 deletions(-) diff --git a/services/stream_update/BUILD.gn b/services/stream_update/BUILD.gn index aabb0996..2d5890e2 100755 --- a/services/stream_update/BUILD.gn +++ b/services/stream_update/BUILD.gn @@ -55,6 +55,7 @@ ohos_static_library("libbinchunkupdate") { "init:libbegetutil_static", "init:libfsmanager_static_real", "openssl:libcrypto_static", + "zlib:libz", ] public_configs = [ ":libstreamupdate_exported_headers" ] diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index a9140fd9..324f24b6 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -30,6 +30,10 @@ #include "slot_info/slot_info.h" #include "utils.h" +#include // 支持ZIP_ZLIB和ZIP_GZIP +// #include // 支持ZIP_BZIP2 +// #include // 支持ZIP_LZMA + namespace Updater { using namespace Uscript; using namespace Hpackage; @@ -37,6 +41,12 @@ using namespace std::placeholders; constexpr const char *UPDATE_BIN_FILE = "update.bin"; constexpr const size_t HASH_BUFFER_SIZE = 50 * 1024; +constexpr size_t CHUNK_INFO_MAGIC_SIZE = 8; +constexpr size_t CHUNK_INFO_VERSION_SIZE = 8; +constexpr size_t CHUNK_INFO_RESERVED_SIZE = 232; +constexpr size_t CHUNK_DATA_PARTION_SIZE = 32; +constexpr size_t CHUNK_DATA_RESERVED_SIZE = 224; + BinChunkUpdate::BinChunkUpdate(uint32_t maxBufSize) { LOG(DEBUG) << "BinChunkUpdate::BinChunkUpdate enter"; @@ -112,6 +122,9 @@ UpdateResultCode BinChunkUpdate::ProcessBufferData() case BIN_UPDATE_HEAD_TIP: ret = UpdateBinHead(buffer_, curlen_); break; + case BIN_UPDATE_INFO_TIP: + ret = UpdateBinInfo(buffer_, curlen_); + break; case BIN_UPDATE_DATA_TIP: ret = UpdateBinData(buffer_, curlen_); break; @@ -502,7 +515,7 @@ bool BinChunkUpdate::ReadPartitionData(uint8_t *data, uint32_t &len) } updateInfo_.curPartition = ""; - PkgFileImpl::ConvertBufferToString(updateInfo_.curPartition, {data + offset, tlv.length}); + PkgFileImpl::ConvertBufferToString(updateInfo_.curPartition, {data + offset, CHUNK_DATA_PARTION_SIZE}); LOG(DEBUG) << "PreWriteBin name " << updateInfo_.curPartition; return true; @@ -622,9 +635,16 @@ bool BinChunkUpdate::ProcessPartition(uint8_t *data, uint32_t &len, uint32_t &of } std::string partition; - PkgFileImpl::ConvertBufferToString(partition, {data + offset, tlv.length}); + PkgFileImpl::ConvertBufferToString(partition, {data + offset, CHUNK_DATA_PARTION_SIZE}); LOG(DEBUG) << "partition:" << partition; - offset += tlv.length; + offset += CHUNK_DATA_PARTION_SIZE; + + std::string reservedData; + reservedData.assign(data + offset, data + offset + 224); + if (reservedData.size() != CHUNK_DATA_RESERVED_SIZE) { + LOG(ERROR) << " ERROR Reserved size:" << reservedData.size(); + } + offset += CHUNK_DATA_RESERVED_SIZE; if (partition != updateInfo_.curPartition) { updateInfo_.updateStep = CHUNK_INSTALL_STEP_POST; @@ -727,6 +747,66 @@ UpdateResultCode BinChunkUpdate::ChunkInstallPostWrite(uint8_t *data, uint32_t & return STREAM_UPDATE_SUCCESS; } +UpdateResultCode BinChunkUpdate::UpdateBinInfo(uint8_t *data, uint32_t &len) +{ + LOG(DEBUG) << "BinChunkUptdate::UpdateBinInfo enter"; + PkgTlvHH tlv; + uint32_t offset = offset_; + + if ((len - offset) < sizeof(PkgTlvHH)) { + LOG(DEBUG) << "needNewData"; + updateInfo_.needNewData = true; + return STREAM_UPDATE_FAILURE; + } + + tlv.type = ReadLE16(data + offset); + LOG(DEBUG) << "tlv.type:" << tlv.type; + if (tlv.type != BIN_UPDATE_INFO_TIP) { + LOG(ERROR) << "Invalid chunkinfo type: 0x" << std::hex << tlv.type; + return STREAM_UPDATE_FAILURE; + } + + tlv.length = ReadLE16(data + offset + sizeof(uint16_t)); + LOG(DEBUG) << "tlv.length:" << tlv.length; + offset += sizeof(PkgTlvHH); + + if ((len - offset) < tlv.length) { + LOG(DEBUG) << "needNewData"; + updateInfo_.needNewData = true; + return STREAM_UPDATE_FAILURE; + } + + updateInfo_.magicNum.assign(data + offset, data + offset + CHUNK_INFO_MAGIC_SIZE); + LOG(DEBUG) << "magicNum:" << updateInfo_.magicNum; + offset += CHUNK_INFO_MAGIC_SIZE; + + updateInfo_.fileFormatVeriosn.assign(data + offset, data + offset + CHUNK_INFO_VERSION_SIZE); + LOG(DEBUG) << "fileFormatVeriosn:" << updateInfo_.fileFormatVeriosn; + offset += CHUNK_INFO_VERSION_SIZE; + + updateInfo_.compresionMethod = ReadLE16(data + offset); + LOG(DEBUG) << "compresionMethod:" << updateInfo_.compresionMethod; + offset += sizeof(uint16_t); + + updateInfo_.signMethod = ReadLE16(data + offset); + LOG(DEBUG) << "signMethod:" << updateInfo_.signMethod; + offset += sizeof(uint16_t); + + updateInfo_.chunkListNum = ReadLE32(data + offset); + LOG(DEBUG) << "chunkListNum:" << updateInfo_.chunkListNum; + offset += sizeof(uint32_t); + + std::string reservedData; + reservedData.assign(data + offset, data + offset + CHUNK_INFO_RESERVED_SIZE); + if (reservedData.size() != CHUNK_INFO_RESERVED_SIZE) { + LOG(ERROR) << " ERROR Reserved size:" << reservedData.size(); + return STREAM_UPDATE_FAILURE; + } + offset += CHUNK_INFO_RESERVED_SIZE; + + return STREAM_UPDATE_COMPLETE; +} + UpdateResultCode BinChunkUpdate::UpdateBinData(uint8_t *data, uint32_t &len) { LOG(DEBUG) << "BinChunkUpdate::UpdateBinData enter"; @@ -812,4 +892,46 @@ bool BinChunkUpdate::VerifyPartitionHash(const std::string &partitionName, const return true; } +std::vector BinChunkUpdate::decompress_data(int compress_method, + const std::vector& compressed_data) +{ + LOG(DEBUG) << "BinChunkUpdate::decompress_data enter"; + switch(compress_method) { + case NO_COMPRESS: + return compressed_data; + + case ZIP_ZLIB: { + z_stream zs = {}; + if (inflateInit(&zs) != Z_OK) + LOG(ERROR) << "inflateInit failed"; + return {}; + + zs.next_in = const_cast(compressed_data.data()); + zs.avail_in = compressed_data.size(); + + std::vector output(compressed_data.size() * 5); + int ret; + do { + zs.next_out = output.data() + zs.total_out; + zs.avail_out = output.size() - zs.total_out; + ret = inflate(&zs, Z_FINISH); + if (ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) { + inflateEnd(&zs); + LOG(ERROR) << "zlib decompress error"; + } + if (zs.avail_out == 0) + output.resize(output.size() * 2); + } while (ret != Z_STREAM_END); + + inflateEnd(&zs); + output.resize(zs.total_out); + return output; + } + + default: + LOG(ERROR) << "zlib decompress error"; + return {}; + } +} + } // namespace Updater diff --git a/services/stream_update/bin_chunk_update.h b/services/stream_update/bin_chunk_update.h index 306326d6..f2228c6f 100755 --- a/services/stream_update/bin_chunk_update.h +++ b/services/stream_update/bin_chunk_update.h @@ -49,10 +49,19 @@ using UpdateResultCode = enum { using BinUpdateTip = enum { BIN_UPDATE_ZIP_TIP = 0xaa, BIN_UPDATE_HEAD_TIP = 0x01, + BIN_UPDATE_INFO_TIP = 0x10, BIN_UPDATE_DATA_TIP = 0x12, BIN_UPDATE_HASH_TIP = 0x16 }; +using CompressMethod = enum { + NO_COMPRESS = 0, + ZIP_ZLIB = 4, + ZIP_GZIP = 8, + ZIP_BZIP2 = 12, + ZIP_LZMA = 16 +}; + using ChunkInstallStep = enum { CHUNK_INSTALL_STEP_PRE = 0, CHUNK_INSTALL_STEP_DO, @@ -66,6 +75,11 @@ struct BinChunkUpdateInfo { int srcFd; int targetFd; std::unique_ptr transferParams; + std::string magicNum; + std::string fileFormatVeriosn; + int16_t compresionMethod; + int16_t signMethod; + int32_t chunkListNum; std::string curPartition; std::string cmdLine; int patitionNum; @@ -90,6 +104,7 @@ private: UpdateResultCode ChunkInstallPostWrite(uint8_t *data, uint32_t &len); UpdateResultCode UpdateBinHead(uint8_t *data, uint32_t &len); + UpdateResultCode UpdateBinInfo(uint8_t *data, uint32_t &len); UpdateResultCode UpdateBinData(uint8_t *data, uint32_t &len); UpdateResultCode UpdateBinHash(uint8_t *data, uint32_t &len); UpdateResultCode UpdateBinOther(uint8_t *data, uint32_t &len); @@ -130,6 +145,9 @@ private: const std::map &dataLenInfos); std::string ComputeFileHash(const std::string& partitionName, const std::map &dataLenInfos); + std::vector decompress_data(int compress_method, + const std::vector& compressed_data); + Hpackage::PkgManager::PkgManagerPtr pkgManager_; uint8_t *buffer_ = nullptr; uint32_t maxBufSize_ = 0; -- Gitee From b55cfcf359f4e767809ce509e3bab53a9e6c5a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Thu, 29 May 2025 16:04:37 +0800 Subject: [PATCH 02/21] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index 324f24b6..3ebd3121 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -749,51 +749,51 @@ UpdateResultCode BinChunkUpdate::ChunkInstallPostWrite(uint8_t *data, uint32_t & UpdateResultCode BinChunkUpdate::UpdateBinInfo(uint8_t *data, uint32_t &len) { - LOG(DEBUG) << "BinChunkUptdate::UpdateBinInfo enter"; + LOG(INFO) << "BinChunkUptdate::UpdateBinInfo enter"; PkgTlvHH tlv; uint32_t offset = offset_; if ((len - offset) < sizeof(PkgTlvHH)) { - LOG(DEBUG) << "needNewData"; + LOG(INFO) << "needNewData"; updateInfo_.needNewData = true; return STREAM_UPDATE_FAILURE; } tlv.type = ReadLE16(data + offset); - LOG(DEBUG) << "tlv.type:" << tlv.type; + LOG(INFO) << "tlv.type:" << tlv.type; if (tlv.type != BIN_UPDATE_INFO_TIP) { LOG(ERROR) << "Invalid chunkinfo type: 0x" << std::hex << tlv.type; return STREAM_UPDATE_FAILURE; } tlv.length = ReadLE16(data + offset + sizeof(uint16_t)); - LOG(DEBUG) << "tlv.length:" << tlv.length; + LOG(INFO) << "tlv.length:" << tlv.length; offset += sizeof(PkgTlvHH); if ((len - offset) < tlv.length) { - LOG(DEBUG) << "needNewData"; + LOG(INFO) << "needNewData"; updateInfo_.needNewData = true; return STREAM_UPDATE_FAILURE; } updateInfo_.magicNum.assign(data + offset, data + offset + CHUNK_INFO_MAGIC_SIZE); - LOG(DEBUG) << "magicNum:" << updateInfo_.magicNum; + LOG(INFO) << "magicNum:" << updateInfo_.magicNum; offset += CHUNK_INFO_MAGIC_SIZE; updateInfo_.fileFormatVeriosn.assign(data + offset, data + offset + CHUNK_INFO_VERSION_SIZE); - LOG(DEBUG) << "fileFormatVeriosn:" << updateInfo_.fileFormatVeriosn; + LOG(INFO) << "fileFormatVeriosn:" << updateInfo_.fileFormatVeriosn; offset += CHUNK_INFO_VERSION_SIZE; updateInfo_.compresionMethod = ReadLE16(data + offset); - LOG(DEBUG) << "compresionMethod:" << updateInfo_.compresionMethod; + LOG(INFO) << "compresionMethod:" << updateInfo_.compresionMethod; offset += sizeof(uint16_t); updateInfo_.signMethod = ReadLE16(data + offset); - LOG(DEBUG) << "signMethod:" << updateInfo_.signMethod; + LOG(INFO) << "signMethod:" << updateInfo_.signMethod; offset += sizeof(uint16_t); updateInfo_.chunkListNum = ReadLE32(data + offset); - LOG(DEBUG) << "chunkListNum:" << updateInfo_.chunkListNum; + LOG(INFO) << "chunkListNum:" << updateInfo_.chunkListNum; offset += sizeof(uint32_t); std::string reservedData; @@ -804,7 +804,7 @@ UpdateResultCode BinChunkUpdate::UpdateBinInfo(uint8_t *data, uint32_t &len) } offset += CHUNK_INFO_RESERVED_SIZE; - return STREAM_UPDATE_COMPLETE; + return STREAM_UPDATE_SUCCESS; } UpdateResultCode BinChunkUpdate::UpdateBinData(uint8_t *data, uint32_t &len) -- Gitee From 210206e20a315f37d9529f893458b18e804147d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Fri, 30 May 2025 14:02:15 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E6=AD=BB=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index 3ebd3121..7ae99e38 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -756,7 +756,7 @@ UpdateResultCode BinChunkUpdate::UpdateBinInfo(uint8_t *data, uint32_t &len) if ((len - offset) < sizeof(PkgTlvHH)) { LOG(INFO) << "needNewData"; updateInfo_.needNewData = true; - return STREAM_UPDATE_FAILURE; + return STREAM_UPDATE_SUCCESS; } tlv.type = ReadLE16(data + offset); @@ -773,7 +773,7 @@ UpdateResultCode BinChunkUpdate::UpdateBinInfo(uint8_t *data, uint32_t &len) if ((len - offset) < tlv.length) { LOG(INFO) << "needNewData"; updateInfo_.needNewData = true; - return STREAM_UPDATE_FAILURE; + return STREAM_UPDATE_SUCCESS; } updateInfo_.magicNum.assign(data + offset, data + offset + CHUNK_INFO_MAGIC_SIZE); @@ -804,6 +804,8 @@ UpdateResultCode BinChunkUpdate::UpdateBinInfo(uint8_t *data, uint32_t &len) } offset += CHUNK_INFO_RESERVED_SIZE; + offset_ = offset; + return STREAM_UPDATE_SUCCESS; } -- Gitee From 60757632703cacf8737105d54b33c9156bfd75d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Fri, 30 May 2025 15:31:57 +0800 Subject: [PATCH 04/21] 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index 7ae99e38..b2a91509 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -538,7 +538,7 @@ bool BinChunkUpdate::OpenDevPath() srcPath += suffix; } - LOG(DEBUG) << "ChunkInstallPreWrite curPartition:" << updateInfo_.curPartition + LOG(INFO) << "ChunkInstallPreWrite curPartition:" << updateInfo_.curPartition << " srcPath:" << srcPath << " targetPath:" << targetPath; updateInfo_.srcFd = open(srcPath.c_str(), O_RDWR | O_LARGEFILE); @@ -581,7 +581,7 @@ bool BinChunkUpdate::InitTransferParams() UpdateResultCode BinChunkUpdate::ChunkInstallDoWrite(uint8_t *data, uint32_t &len) { - LOG(DEBUG) << "BinChunkUpdate::ChunkInstallDoWrite enter"; + LOG(INFO) << "BinChunkUpdate::ChunkInstallDoWrite enter"; uint32_t offset = offset_; // 处理安装分区 @@ -693,9 +693,9 @@ bool BinChunkUpdate::ProcessInstallData(uint8_t *data, uint32_t &len, uint32_t & } tlv2.type = ReadLE16(data + offset); - LOG(DEBUG) << "tlv2.type:" << tlv2.type; + LOG(INFO) << "tlv2.type:" << tlv2.type; tlv2.length = ReadLE32(data + offset + sizeof(uint16_t)); - LOG(DEBUG) << "tlv2.length:" << tlv2.length; + LOG(INFO) << "tlv2.length:" << tlv2.length; offset += sizeof(PkgTlvHI); if ((len - offset) < tlv2.length) { -- Gitee From cbfa412a93f88352b4acf32eb728ef58ff378f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Fri, 30 May 2025 17:29:07 +0800 Subject: [PATCH 05/21] 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 17 +++++++++++++++-- updater_default_cfg.gni | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index b2a91509..e407968a 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -704,8 +704,21 @@ bool BinChunkUpdate::ProcessInstallData(uint8_t *data, uint32_t &len, uint32_t & return false; } - updateInfo_.transferParams->dataBuffer = data + offset; - updateInfo_.transferParams->dataBufferSize = tlv2.length; + // 提取数据 + std::vector compressed_data(data + offset, data + offset + tlv2.length); + + std::vector decompressed_data = decompress_data(updateInfo_.compresionMethod, compressed_data); + + if (decompressed_data.empty()) { + LOG(ERROR) << "Decompression failed"; + return false; + } + // Store the decompressed data in the updateInfo structure + updateInfo_.transferParams->dataBuffer = decompressed_data.data(); + updateInfo_.transferParams->dataBufferSize = decompressed_data.size(); + + // updateInfo_.transferParams->dataBuffer = data + offset; + // updateInfo_.transferParams->dataBufferSize = tlv2.length; offset += tlv2.length; return true; diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 4f84e9f2..4dc20cd0 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -45,7 +45,7 @@ template("updater_gen") { } else { ohos_executable(target_name) { if (!is_asan && !is_emulator && target_name == "updater_binary") { - static_link = true + static_link = false } forward_variables_from(invoker, "*") -- Gitee From 11e37e0cb7482b08d69ae8357e0f60661c28b435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Tue, 3 Jun 2025 09:23:18 +0800 Subject: [PATCH 06/21] 4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- interfaces/kits/slot_info/slot_info.cpp | 7 ++++++- updater_default_cfg.gni | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/slot_info/slot_info.cpp b/interfaces/kits/slot_info/slot_info.cpp index 0948b5f5..eaef9700 100644 --- a/interfaces/kits/slot_info/slot_info.cpp +++ b/interfaces/kits/slot_info/slot_info.cpp @@ -25,19 +25,22 @@ namespace Updater { #ifndef UPDATER_AB_SUPPORT void GetPartitionSuffix(std::string &suffix) { + LOG(INFO) << "enter GetPartitionSuffix not support ab"; suffix = ""; } void GetActivePartitionSuffix(std::string &suffix) { + LOG(INFO) << "enter GetActivePartitionSuffix not support ab"; suffix = ""; } void SetActiveSlot() { + LOG(INFO) << "enter SetActiveSlot not support ab"; } #else void GetPartitionSuffix(std::string &suffix) { - sptr partitionslot = + LOG(INFO) << "enter GetPartitionSuffix support ab"; OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { LOG(ERROR) << "partitionslot ptr is nullptr"; @@ -62,6 +65,7 @@ void GetPartitionSuffix(std::string &suffix) void GetActivePartitionSuffix(std::string &suffix) { + LOG(INFO) << "enter GetActivePartitionSuffix support ab"; sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { @@ -86,6 +90,7 @@ void GetActivePartitionSuffix(std::string &suffix) void SetActiveSlot() { + LOG(INFO) << "enter SetActiveSlot support ab"; sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 4dc20cd0..4f84e9f2 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -45,7 +45,7 @@ template("updater_gen") { } else { ohos_executable(target_name) { if (!is_asan && !is_emulator && target_name == "updater_binary") { - static_link = false + static_link = true } forward_variables_from(invoker, "*") -- Gitee From 2c8829b5cf2ca1a800db5a4b693c8738b6747ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Tue, 3 Jun 2025 10:23:40 +0800 Subject: [PATCH 07/21] 5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- interfaces/kits/slot_info/BUILD.gn | 1 - updater_default_cfg.gni | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/interfaces/kits/slot_info/BUILD.gn b/interfaces/kits/slot_info/BUILD.gn index 98db2059..a4e1c75a 100644 --- a/interfaces/kits/slot_info/BUILD.gn +++ b/interfaces/kits/slot_info/BUILD.gn @@ -31,7 +31,6 @@ ohos_static_library("libslotinfo") { "c_utils:utils", "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", "hilog:libhilog_base", - "init:libbegetutil_static", ] } diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 4f84e9f2..796286a3 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -13,7 +13,7 @@ import("//build/ohos.gni") -init_feature_ab_partition = false +init_feature_ab_partition = true declare_args() { updater_cfg_file = "" updater_ui_support = true -- Gitee From 0b68cef58b093bd79954e8ce1104e3c0b49811f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Tue, 3 Jun 2025 11:05:04 +0800 Subject: [PATCH 08/21] 6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- interfaces/kits/slot_info/slot_info.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/slot_info/slot_info.cpp b/interfaces/kits/slot_info/slot_info.cpp index eaef9700..40c31bd0 100644 --- a/interfaces/kits/slot_info/slot_info.cpp +++ b/interfaces/kits/slot_info/slot_info.cpp @@ -25,22 +25,20 @@ namespace Updater { #ifndef UPDATER_AB_SUPPORT void GetPartitionSuffix(std::string &suffix) { - LOG(INFO) << "enter GetPartitionSuffix not support ab"; suffix = ""; } void GetActivePartitionSuffix(std::string &suffix) { - LOG(INFO) << "enter GetActivePartitionSuffix not support ab"; suffix = ""; } void SetActiveSlot() { - LOG(INFO) << "enter SetActiveSlot not support ab"; } #else void GetPartitionSuffix(std::string &suffix) { - LOG(INFO) << "enter GetPartitionSuffix support ab"; + LOG(INFO) << "enter etPartitionSuffix"; + sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { LOG(ERROR) << "partitionslot ptr is nullptr"; @@ -65,7 +63,7 @@ void GetPartitionSuffix(std::string &suffix) void GetActivePartitionSuffix(std::string &suffix) { - LOG(INFO) << "enter GetActivePartitionSuffix support ab"; + LOG(INFO) << "enter GetActivePartitionSuffix"; sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { @@ -90,7 +88,7 @@ void GetActivePartitionSuffix(std::string &suffix) void SetActiveSlot() { - LOG(INFO) << "enter SetActiveSlot support ab"; + LOG(INFO) << "enter SetActiveSlot"; sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { -- Gitee From 29087bdc68c72da8d9ef50877aced00c391d43c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Tue, 3 Jun 2025 16:42:02 +0800 Subject: [PATCH 09/21] static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- bundle.json | 7 ++ .../kits/include/slot_info/slot_info_static.h | 27 +++++ interfaces/kits/slot_info/BUILD.gn | 24 ++++- .../kits/slot_info/slot_info_static.cpp | 98 +++++++++++++++++++ services/flow_update/update_bin/BUILD.gn | 1 + .../update_bin/component_processor.cpp | 4 +- services/stream_update/BUILD.gn | 1 + services/stream_update/bin_chunk_update.cpp | 8 +- services/updater_binary/BUILD.gn | 2 +- .../updater_binary/update_image_block.cpp | 8 +- .../updater_binary/update_image_patch.cpp | 6 +- services/updater_binary/update_processor.cpp | 4 +- 12 files changed, 173 insertions(+), 17 deletions(-) create mode 100755 interfaces/kits/include/slot_info/slot_info_static.h create mode 100755 interfaces/kits/slot_info/slot_info_static.cpp diff --git a/bundle.json b/bundle.json index a591441e..6c1ed649 100644 --- a/bundle.json +++ b/bundle.json @@ -326,6 +326,13 @@ "header_files": [], "header_base": "//base/update/updater/services/script/threadpool" } + }, + { + "name": "//base/update/updater/interfaces/kits/slot_info:libslotinfo_static", + "header": { + "header_files": [], + "header_base": "//base/update/updater/interfaces/kits/include" + } } ], "test": [ diff --git a/interfaces/kits/include/slot_info/slot_info_static.h b/interfaces/kits/include/slot_info/slot_info_static.h new file mode 100755 index 00000000..67ce6fe7 --- /dev/null +++ b/interfaces/kits/include/slot_info/slot_info_static.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 SLOT_INFO_STATIC_H +#define SLOT_INFO_STATIC_H + +#include +#include +#include +#include + +namespace Updater { +void GetPartitionSuffixStatic(std::string &suffix); +void GetActivePartitionSuffixStatic(std::string &suffix); +} // Updater +#endif /* SLOT_INFO_STATIC_H */ diff --git a/interfaces/kits/slot_info/BUILD.gn b/interfaces/kits/slot_info/BUILD.gn index a4e1c75a..55365057 100644 --- a/interfaces/kits/slot_info/BUILD.gn +++ b/interfaces/kits/slot_info/BUILD.gn @@ -28,12 +28,34 @@ ohos_static_library("libslotinfo") { if (init_feature_ab_partition) { defines = [ "UPDATER_AB_SUPPORT" ] external_deps = [ - "c_utils:utils", + "c_utils:utilsbase", "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", "hilog:libhilog_base", + "init:libbegetutil_static", ] } subsystem_name = "updater" part_name = "updater" } + +ohos_static_library("libslotinfo_static") { + sources = [ "slot_info_static.cpp" ] + + include_dirs = [ + "${updater_path}/interfaces/kits/include", + "${updater_path}/services/include", + "${updater_path}/utils/include", + ] + + if (init_feature_ab_partition) { + defines = [ "UPDATER_AB_SUPPORT" ] + external_deps = [ + "c_utils:utilsbase", + "hilog:libhilog_base", + ] + } + + subsystem_name = "updater" + part_name = "updater" +} \ No newline at end of file diff --git a/interfaces/kits/slot_info/slot_info_static.cpp b/interfaces/kits/slot_info/slot_info_static.cpp new file mode 100755 index 00000000..bcd6a0e4 --- /dev/null +++ b/interfaces/kits/slot_info/slot_info_static.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#include +#include "slot_info/slot_info_static.h" +#include "log/log.h" +#include + +namespace Updater { +#define MISC_DEVICE_NODE "/dev/block/by-name/bootctrl" +constexpr int32_t UPDATE_PARTITION_A = 1; +constexpr int32_t UPDATE_PARTITION_AB = 2; +constexpr off_t MISC_PARTITION_ACTIVE_SLOT_OFFSET = 1024; +constexpr off_t MISC_PARTITION_ACTIVE_SLOT_SIZE = 4; + +#ifndef UPDATER_AB_SUPPORT +void GetPartitionSuffixStatic(std::string &suffix) +{ + suffix = ""; +} +void GetActivePartitionSuffixStatic(std::string &suffix) +{ + suffix = ""; +} +#else +static int ReadMisc(off_t offset, off_t size) +{ + int fd = open(MISC_DEVICE_NODE, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) { + return -1; + } + if (lseek(fd, offset, SEEK_SET) < 0) { + LOG(ERROR) << "Failed lseek miscDevice"; + close(fd); + return -1; + } + int32_t slot = 0; + if (read(fd, &slot, size) != size) { + LOG(ERROR) <<"Failed read migic miscDevice"; + close(fd); + return -1; + } + LOG(INFO) << "Read slot:" << slot; + close(fd); + return slot; +} + +void GetPartitionSuffixStatic(std::string &suffix) +{ + // 1. 通过popen执行cat命令获取cmdline内容 + int32_t current_slot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); + + LOG(INFO) << "current_slot: " << current_slot; + + // 4. 校验槽位有效性 + if (current_slot < UPDATE_PARTITION_A || current_slot > UPDATE_PARTITION_AB) { + LOG(ERROR) << "Invalid slot value: " << current_slot << ", expected 1 or 2"; + suffix = ""; + return; + } + + // 5. 生成目标分区后缀(取反当前槽位) + suffix = (current_slot == UPDATE_PARTITION_A) ? "_b" : "_a"; + LOG(INFO) << "Active slot: " << current_slot << ", target suffix: " << suffix; +} + +void GetActivePartitionSuffixStatic(std::string &suffix) +{ + // 1. 通过popen执行cat命令获取cmdline内容 + int32_t current_slot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); + + LOG(INFO) << "current_slot: " << current_slot; + + // 4. 校验槽位有效性 + if (current_slot < UPDATE_PARTITION_A || current_slot > UPDATE_PARTITION_AB) { + LOG(ERROR) << "Invalid slot value: " << current_slot << ", expected 1 or 2"; + suffix = ""; + return; + } + + // 5. 生成目标分区后缀 + suffix = (current_slot == UPDATE_PARTITION_A) ? "_a" : "_b"; + LOG(INFO) << "Active slot: " << current_slot << ", target suffix: " << suffix; +} +#endif +} // updater \ No newline at end of file diff --git a/services/flow_update/update_bin/BUILD.gn b/services/flow_update/update_bin/BUILD.gn index 83e3d6df..62f93ad8 100644 --- a/services/flow_update/update_bin/BUILD.gn +++ b/services/flow_update/update_bin/BUILD.gn @@ -45,6 +45,7 @@ ohos_static_library("libBinFlowUpdate") { "${updater_path}/services/log:libupdaterlog", "${updater_path}/services/package:libupdaterpackage", "${updater_path}/utils:libutils", + "${updater_path}/interfaces/kits/slot_info:libslotinfo_static", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/services/flow_update/update_bin/component_processor.cpp b/services/flow_update/update_bin/component_processor.cpp index f2cfccc1..f5d4514b 100644 --- a/services/flow_update/update_bin/component_processor.cpp +++ b/services/flow_update/update_bin/component_processor.cpp @@ -23,7 +23,7 @@ #ifdef UPDATER_USE_PTABLE #include "ptable_parse/ptable_manager.h" #endif -#include "slot_info/slot_info.h" +#include "slot_info/slot_info_static.h" #include "updater/updater_const.h" using namespace std; @@ -260,7 +260,7 @@ int RawImgProcessor::GetWritePathAndOffset(const std::string &partitionName, std #ifndef UPDATER_UT if (partitionName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); writePath += suffix; } LOG(INFO) << "write partition path: " << writePath; diff --git a/services/stream_update/BUILD.gn b/services/stream_update/BUILD.gn index 2d5890e2..dc60b436 100755 --- a/services/stream_update/BUILD.gn +++ b/services/stream_update/BUILD.gn @@ -49,6 +49,7 @@ ohos_static_library("libbinchunkupdate") { "${updater_path}/services/log:libupdaterlog", "${updater_path}/services/package:libupdaterpackage", "${updater_path}/utils:libutils", + "${updater_path}/interfaces/kits/slot_info:libslotinfo_static", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index e407968a..9edd7e1d 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -27,7 +27,7 @@ #include "fs_manager/mount.h" #include "log.h" #include "scope_guard.h" -#include "slot_info/slot_info.h" +#include "slot_info/slot_info_static.h" #include "utils.h" #include // 支持ZIP_ZLIB和ZIP_GZIP @@ -532,9 +532,9 @@ bool BinChunkUpdate::OpenDevPath() if (updateInfo_.curPartition != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); targetPath += suffix; - GetActivePartitionSuffix(suffix); + GetActivePartitionSuffixStatic(suffix); srcPath += suffix; } @@ -857,7 +857,7 @@ std::string BinChunkUpdate::ComputeFileHash(const std::string &partitionName, std::string devPath = GetBlockDeviceByMountPoint(partitionName); if (partitionName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); devPath += suffix; } #else diff --git a/services/updater_binary/BUILD.gn b/services/updater_binary/BUILD.gn index e196cd23..977b7768 100644 --- a/services/updater_binary/BUILD.gn +++ b/services/updater_binary/BUILD.gn @@ -58,7 +58,7 @@ ohos_static_library("libupdater_binary") { deps = [ "${updater_path}/interfaces/kits/misc_info:libmiscinfo", - "${updater_path}/interfaces/kits/slot_info:libslotinfo", + "${updater_path}/interfaces/kits/slot_info:libslotinfo_static", "${updater_path}/services/applypatch:libapplypatch", "${updater_path}/services/diffpatch/patch:libpatch", "${updater_path}/services/flow_update/update_bin:libBinFlowUpdate", diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 95a6048f..0ceb2eec 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -30,7 +30,7 @@ #include "updater/updater_const.h" #include "updater/hwfault_retry.h" #include "utils.h" -#include "slot_info/slot_info.h" +#include "slot_info/slot_info_static.h" using namespace Uscript; using namespace Hpackage; @@ -182,7 +182,7 @@ static int32_t GetUpdateBlockInfo(struct UpdateBlockInfo &infos, Uscript::UScrip #ifndef UPDATER_UT if (infos.partitionName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); infos.devPath += suffix; } #else @@ -499,7 +499,7 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: #ifndef UPDATER_UT if (partitionName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); devPath += suffix; } #else @@ -768,7 +768,7 @@ int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::U #ifndef UPDATER_UT if (partitionName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); devPath += suffix; } LOG(INFO) << "write partition path: " << devPath; diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index ec3b3c58..77cfdf29 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -35,7 +35,7 @@ #include "updater/updater_const.h" #include "updater/hwfault_retry.h" #include "utils.h" -#include "slot_info/slot_info.h" +#include "slot_info/slot_info_static.h" using namespace Uscript; using namespace Hpackage; @@ -74,7 +74,7 @@ int32_t USInstrImagePatch::GetParam(Uscript::UScriptContext &context, ImagePatch #ifndef UPDATER_UT if (para.partName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); para.devPath += suffix; } #else @@ -265,7 +265,7 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa #ifndef UPDATER_UT if (para.partName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); para.devPath += suffix; } #else diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 78a17325..fb4949dd 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -31,7 +31,7 @@ #endif #include "script_instruction.h" #include "script_manager.h" -#include "slot_info/slot_info.h" +#include "slot_info/slot_info_static.h" #include "update_image_block.h" #include "update_image_patch.h" #include "update_partitions.h" @@ -461,7 +461,7 @@ int UScriptInstructionRawImageWrite::GetWritePathAndOffset(const std::string &pa #ifndef UPDATER_UT if (partitionName != "/userdata") { std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); writePath += suffix; } LOG(INFO) << "write partition path: " << writePath; -- Gitee From 89ce518a26e89f079fc79632208a0c5d53f41748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Tue, 3 Jun 2025 17:11:13 +0800 Subject: [PATCH 10/21] setactiveslot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index 9edd7e1d..86a60546 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -229,7 +229,7 @@ UpdateResultCode BinChunkUpdate::UpdateBinHash(uint8_t *data, uint32_t &len) //切换ab分区 #ifndef UPDATER_UT - SetActiveSlot(); + // SetActiveSlot(); #else int result = remove("/data/updater/test.txt"); if (result != 0) { -- Gitee From 19461e4b46482ab80c3fdb9ba8ebd8d0bde54c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Wed, 4 Jun 2025 08:49:51 +0800 Subject: [PATCH 11/21] bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index 86a60546..b1a83c95 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -709,10 +709,11 @@ bool BinChunkUpdate::ProcessInstallData(uint8_t *data, uint32_t &len, uint32_t & std::vector decompressed_data = decompress_data(updateInfo_.compresionMethod, compressed_data); - if (decompressed_data.empty()) { - LOG(ERROR) << "Decompression failed"; - return false; - } + // if (decompressed_data.empty()) { + // LOG(ERROR) << "Decompression failed"; + // return false; + // } + // Store the decompressed data in the updateInfo structure updateInfo_.transferParams->dataBuffer = decompressed_data.data(); updateInfo_.transferParams->dataBufferSize = decompressed_data.size(); -- Gitee From cbdd98566478d98571c0a7aad3ba1aa1dfe9ea2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Wed, 4 Jun 2025 10:08:25 +0800 Subject: [PATCH 12/21] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/stream_update/bin_chunk_update.cpp | 6 +++--- services/stream_update/bin_chunk_update.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index b1a83c95..bb6ecf6e 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -707,7 +707,7 @@ bool BinChunkUpdate::ProcessInstallData(uint8_t *data, uint32_t &len, uint32_t & // 提取数据 std::vector compressed_data(data + offset, data + offset + tlv2.length); - std::vector decompressed_data = decompress_data(updateInfo_.compresionMethod, compressed_data); + persistentDecompressedData_ = decompress_data(updateInfo_.compresionMethod, compressed_data); // if (decompressed_data.empty()) { // LOG(ERROR) << "Decompression failed"; @@ -715,8 +715,8 @@ bool BinChunkUpdate::ProcessInstallData(uint8_t *data, uint32_t &len, uint32_t & // } // Store the decompressed data in the updateInfo structure - updateInfo_.transferParams->dataBuffer = decompressed_data.data(); - updateInfo_.transferParams->dataBufferSize = decompressed_data.size(); + updateInfo_.transferParams->dataBuffer = persistentDecompressedData_.data(); + updateInfo_.transferParams->dataBufferSize = persistentDecompressedData_.size(); // updateInfo_.transferParams->dataBuffer = data + offset; // updateInfo_.transferParams->dataBufferSize = tlv2.length; diff --git a/services/stream_update/bin_chunk_update.h b/services/stream_update/bin_chunk_update.h index f2228c6f..ff08d6be 100755 --- a/services/stream_update/bin_chunk_update.h +++ b/services/stream_update/bin_chunk_update.h @@ -153,6 +153,7 @@ private: uint32_t maxBufSize_ = 0; uint32_t curlen_ = 0; uint32_t offset_ = 0; + std::vector persistentDecompressedData_; std::map> chunkInstallProcess_; BinChunkUpdateInfo updateInfo_ {}; -- Gitee From 30e2df1662c1bcd37a6aef33114f910c1d444b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Wed, 4 Jun 2025 15:35:14 +0800 Subject: [PATCH 13/21] static link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- .../kits/slot_info/slot_info_static.cpp | 34 +++---------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/interfaces/kits/slot_info/slot_info_static.cpp b/interfaces/kits/slot_info/slot_info_static.cpp index bcd6a0e4..823a209f 100755 --- a/interfaces/kits/slot_info/slot_info_static.cpp +++ b/interfaces/kits/slot_info/slot_info_static.cpp @@ -17,13 +17,11 @@ #include "slot_info/slot_info_static.h" #include "log/log.h" #include +#include "utils.h" namespace Updater { -#define MISC_DEVICE_NODE "/dev/block/by-name/bootctrl" constexpr int32_t UPDATE_PARTITION_A = 1; constexpr int32_t UPDATE_PARTITION_AB = 2; -constexpr off_t MISC_PARTITION_ACTIVE_SLOT_OFFSET = 1024; -constexpr off_t MISC_PARTITION_ACTIVE_SLOT_SIZE = 4; #ifndef UPDATER_AB_SUPPORT void GetPartitionSuffixStatic(std::string &suffix) @@ -35,32 +33,10 @@ void GetActivePartitionSuffixStatic(std::string &suffix) suffix = ""; } #else -static int ReadMisc(off_t offset, off_t size) -{ - int fd = open(MISC_DEVICE_NODE, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (fd < 0) { - return -1; - } - if (lseek(fd, offset, SEEK_SET) < 0) { - LOG(ERROR) << "Failed lseek miscDevice"; - close(fd); - return -1; - } - int32_t slot = 0; - if (read(fd, &slot, size) != size) { - LOG(ERROR) <<"Failed read migic miscDevice"; - close(fd); - return -1; - } - LOG(INFO) << "Read slot:" << slot; - close(fd); - return slot; -} - void GetPartitionSuffixStatic(std::string &suffix) { - // 1. 通过popen执行cat命令获取cmdline内容 - int32_t current_slot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); + // 1. update.part.slot属性值获取 + int32_t current_slot = Utils::GetUpdateSlot(); LOG(INFO) << "current_slot: " << current_slot; @@ -78,8 +54,8 @@ void GetPartitionSuffixStatic(std::string &suffix) void GetActivePartitionSuffixStatic(std::string &suffix) { - // 1. 通过popen执行cat命令获取cmdline内容 - int32_t current_slot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); + // 1. update.part.slot属性值获取 + int32_t current_slot = Utils::GetUpdateSlot(); LOG(INFO) << "current_slot: " << current_slot; -- Gitee From e9b989a1da3f453a3c72daf24b3d7dfda59f1e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Wed, 4 Jun 2025 17:21:52 +0800 Subject: [PATCH 14/21] fix vab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- utils/utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/utils.cpp b/utils/utils.cpp index 4c81481c..6649019f 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -1114,9 +1114,9 @@ bool SetUpdateSlot(int setSlot) int GetUpdateSlot() { - if (!IsVabDevice()) { - return NOT_AB; - } + // if (!IsVabDevice()) { + // return NOT_AB; + // } char paramValue[PARAM_SIZE + 1] = {0}; if (GetParameter("update.part.slot", "", paramValue, sizeof(paramValue) - 1) <= 0) { LOG(ERROR) << "get update.part.slot failed"; -- Gitee From 49e3956d1abea25e3846f36e02ae16a68602c46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Thu, 5 Jun 2025 08:55:57 +0800 Subject: [PATCH 15/21] fix slot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/updater.cpp | 8 +++++--- utils/utils.cpp | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/updater.cpp b/services/updater.cpp index 84158f91..44f5828c 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -290,9 +290,10 @@ bool IsUpdateBasePkg(UpdaterParams &upParams) UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot) { - if (!Utils::IsVabDevice()) { - return UPDATE_SUCCESS; - } + // if (!Utils::IsVabDevice()) { + // return UPDATE_SUCCESS; + // } + LOG(INFO) << "enter setupdaterslotparam"; if (!isUpdateCurrSlot && !IsUpdateBasePkg(upParams)) { isUpdateCurrSlot = true; } @@ -304,6 +305,7 @@ UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot) bool isUpdateSlotA = (currentSlot == SLOT_A && isUpdateCurrSlot) || (currentSlot == SLOT_B && !isUpdateCurrSlot); int updateSlot = isUpdateSlotA ? SLOT_A : SLOT_B; + LOG(INFO) << "updateslot = " << updateSlot; if (!Utils::SetUpdateSlot(updateSlot)) { LOG(ERROR) << "set update.part.slot fail"; return UPDATE_ERROR; diff --git a/utils/utils.cpp b/utils/utils.cpp index 6649019f..b6527ad7 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -1117,6 +1117,7 @@ int GetUpdateSlot() // if (!IsVabDevice()) { // return NOT_AB; // } + LOG(INFO) << "enter GetUpdateslot"; char paramValue[PARAM_SIZE + 1] = {0}; if (GetParameter("update.part.slot", "", paramValue, sizeof(paramValue) - 1) <= 0) { LOG(ERROR) << "get update.part.slot failed"; @@ -1127,6 +1128,7 @@ int GetUpdateSlot() LOG(ERROR) << "ConvertToLong failed"; return -1; } + LOG(INFO) << "updateslot = " << updateSlot; return updateSlot; } -- Gitee From 6c026e77447c315d8e74d15b89fe53d50aa3c75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Thu, 5 Jun 2025 15:03:53 +0800 Subject: [PATCH 16/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0suffix=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/BUILD.gn | 1 + .../update_bin/component_processor.cpp | 3 +- services/include/updater/updater.h | 2 + services/stream_update/bin_chunk_update.cpp | 8 +-- services/updater.cpp | 23 +++++-- .../updater_binary/update_image_block.cpp | 9 +-- .../updater_binary/update_image_patch.cpp | 6 +- services/updater_binary/update_processor.cpp | 3 +- services/updater_main.cpp | 8 +++ utils/include/utils.h | 5 +- utils/utils.cpp | 63 +++++++++++++++++-- 11 files changed, 99 insertions(+), 32 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index f1c260f5..5377cf83 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -177,6 +177,7 @@ ohos_static_library("libupdater") { "openssl:libcrypto_shared", "openssl:libssl_shared", "zlib:libz", + "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", ] # add updater custom library diff --git a/services/flow_update/update_bin/component_processor.cpp b/services/flow_update/update_bin/component_processor.cpp index f5d4514b..54af30e2 100644 --- a/services/flow_update/update_bin/component_processor.cpp +++ b/services/flow_update/update_bin/component_processor.cpp @@ -259,8 +259,7 @@ int RawImgProcessor::GetWritePathAndOffset(const std::string &partitionName, std #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); writePath += suffix; } LOG(INFO) << "write partition path: " << writePath; diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index de314e5b..d46ba437 100644 --- a/services/include/updater/updater.h +++ b/services/include/updater/updater.h @@ -96,6 +96,8 @@ void ProgressSmoothHandler(int beginProgress, int endProgress); UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot); +UpdaterStatus SetUpdateSuffixParam(); + UpdaterStatus ClearUpdateSlotParam(); UpdaterStatus DoInstallUpdaterPackage(Hpackage::PkgManager::PkgManagerPtr pkgManager, diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index bb6ecf6e..53113f9b 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -531,10 +531,9 @@ bool BinChunkUpdate::OpenDevPath() targetPath = devPath; if (updateInfo_.curPartition != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); targetPath += suffix; - GetActivePartitionSuffixStatic(suffix); + suffix = Utils::GetUpdateActiveSuffix(); srcPath += suffix; } @@ -857,8 +856,7 @@ std::string BinChunkUpdate::ComputeFileHash(const std::string &partitionName, #ifndef UPDATER_UT std::string devPath = GetBlockDeviceByMountPoint(partitionName); if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); devPath += suffix; } #else diff --git a/services/updater.cpp b/services/updater.cpp index 44f5828c..5ed42fb1 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -52,6 +52,7 @@ #include "updater_ui_stub.h" #include "utils.h" #include "write_state/write_state.h" +#include "slot_info/slot_info.h" namespace Updater { using Updater::Utils::SplitString; @@ -290,10 +291,9 @@ bool IsUpdateBasePkg(UpdaterParams &upParams) UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot) { - // if (!Utils::IsVabDevice()) { - // return UPDATE_SUCCESS; - // } - LOG(INFO) << "enter setupdaterslotparam"; + if (!Utils::IsVabDevice()) { + return UPDATE_SUCCESS; + } if (!isUpdateCurrSlot && !IsUpdateBasePkg(upParams)) { isUpdateCurrSlot = true; } @@ -305,14 +305,25 @@ UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot) bool isUpdateSlotA = (currentSlot == SLOT_A && isUpdateCurrSlot) || (currentSlot == SLOT_B && !isUpdateCurrSlot); int updateSlot = isUpdateSlotA ? SLOT_A : SLOT_B; - LOG(INFO) << "updateslot = " << updateSlot; if (!Utils::SetUpdateSlot(updateSlot)) { LOG(ERROR) << "set update.part.slot fail"; return UPDATE_ERROR; } return UPDATE_SUCCESS; } - + +UpdaterStatus SetUpdateSuffixParam() +{ + LOG(INFO) << "enter setupdatesuffixparam"; + std::string suffix = ""; + GetPartitionSuffix(suffix); + if (!Utils::SetUpdateSuffix(suffix)) { + LOG(ERROR) << "set update.part.suffix fail"; + return UPDATE_ERROR; + } + return UPDATE_SUCCESS; +} + UpdaterStatus ClearUpdateSlotParam() { if (!Utils::IsVabDevice()) { diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 0ceb2eec..f7f14201 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -181,8 +181,7 @@ static int32_t GetUpdateBlockInfo(struct UpdateBlockInfo &infos, Uscript::UScrip infos.devPath = GetBlockDeviceByMountPoint(infos.partitionName); #ifndef UPDATER_UT if (infos.partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); infos.devPath += suffix; } #else @@ -498,8 +497,7 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: auto devPath = GetBlockDeviceByMountPoint(partitionName); #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); devPath += suffix; } #else @@ -767,8 +765,7 @@ int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::U } #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); devPath += suffix; } LOG(INFO) << "write partition path: " << devPath; diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index 77cfdf29..968a3249 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -73,8 +73,7 @@ int32_t USInstrImagePatch::GetParam(Uscript::UScriptContext &context, ImagePatch para.devPath = GetBlockDeviceByMountPoint(para.partName); #ifndef UPDATER_UT if (para.partName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); para.devPath += suffix; } #else @@ -264,8 +263,7 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa para.devPath = GetBlockDeviceByMountPoint(para.partName); #ifndef UPDATER_UT if (para.partName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); para.devPath += suffix; } #else diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index fb4949dd..a079e55b 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -460,8 +460,7 @@ int UScriptInstructionRawImageWrite::GetWritePathAndOffset(const std::string &pa #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffixStatic(suffix); + std::string suffix = Utils::GetUpdateSuffix(); writePath += suffix; } LOG(INFO) << "write partition path: " << writePath; diff --git a/services/updater_main.cpp b/services/updater_main.cpp index c92a607f..1d6adfa4 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -673,6 +673,10 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) LOG(ERROR) << "SetUpdateSlotParam failed"; return UPDATE_ERROR; } + if(SetUpdateSuffixParam() != UPDATE_SUCCESS) { + LOG(ERROR) << "SetUpdateSuffixParam failed"; + return UPDATE_ERROR; + } // verify package first if (VerifyCommonFiles(upParams) != UPDATE_SUCCESS) { return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! @@ -963,6 +967,10 @@ static UpdaterStatus PreSdcardUpdatePackages(UpdaterParams &upParams) LOG(ERROR) << "SetUpdateSlotParam failed"; return UPDATE_ERROR; } + if (SetUpdateSuffixParam() != UPDATE_SUCCESS) { + LOG(ERROR) << "SetUpdateSuffixParam failed"; + return UPDATE_ERROR; + } UpdaterStatus status = VerifyPackages(upParams); if (status != UPDATE_SUCCESS) { return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! diff --git a/utils/include/utils.h b/utils/include/utils.h index 7cefae4d..c25486eb 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -117,7 +117,10 @@ bool ConvertToDouble(const std::string &str, double &value); bool ConvertToFloat(const std::string &str, float &value); bool IsVabDevice(); bool SetUpdateSlot(int updateSlot); -int GetUpdateSlot(); +bool SetUpdateSuffix(std::string stringsuffix); +int GetUpdateSlot();; +std::string GetUpdateSuffix(); +std::string GetUpdateActiveSuffix(); #ifndef __WIN32 void SetFileAttributes(const std::string& file, uid_t owner, gid_t group, mode_t mode); #endif diff --git a/utils/utils.cpp b/utils/utils.cpp index b6527ad7..20c331ea 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -1111,13 +1111,35 @@ bool SetUpdateSlot(int setSlot) } return false; } - + +bool SetUpdateSuffix(std::string stringsuffix) +{ + if (stringsuffix.empty()) { + LOG(ERROR) << "suffix is empty"; + return false; + } + int tryNum = 3; + while (tryNum-- > 0) { + if (SetParameter("update.part.suffix", stringsuffix.c_str()) != 0) { + LOG(ERROR) << "set update.part.suffix fail"; + continue; + } + if (strcmp(GetUpdateSuffix().c_str(), stringsuffix.c_str()) == 0) { + LOG(INFO) << "set update.part.suffix is " << stringsuffix; + return true; + } + if (tryNum != 0) { + sleep(1); + } + } + return false; +} + int GetUpdateSlot() { - // if (!IsVabDevice()) { - // return NOT_AB; - // } - LOG(INFO) << "enter GetUpdateslot"; + if (!IsVabDevice()) { + return NOT_AB; + } char paramValue[PARAM_SIZE + 1] = {0}; if (GetParameter("update.part.slot", "", paramValue, sizeof(paramValue) - 1) <= 0) { LOG(ERROR) << "get update.part.slot failed"; @@ -1128,10 +1150,39 @@ int GetUpdateSlot() LOG(ERROR) << "ConvertToLong failed"; return -1; } - LOG(INFO) << "updateslot = " << updateSlot; return updateSlot; } +std::string GetUpdateSuffix() +{ + char paramValue[PARAM_SIZE + 1] = {0}; + if (GetParameter("update.part.suffix", "", paramValue, sizeof(paramValue) - 1) <= 0) { + LOG(ERROR) << "get update.part.suffix failed"; + return std::string(paramValue); + } + LOG(INFO) << "GetUpdateSuffix = " << paramValue; + return std::string(paramValue); +} + +std::string GetUpdateActiveSuffix() +{ + char paramValue[PARAM_SIZE + 1] = {0}; + if (GetParameter("update.part.suffix", "", paramValue, sizeof(paramValue) - 1) <= 0) { + LOG(ERROR) << "get update.part.suffix failed"; + return std::string(paramValue); + } + if (strcmp(paramValue, "_a") == 0) { + strncpy(paramValue, "_b", sizeof(paramValue)); + } else if (strcmp(paramValue, "_b") == 0) { + strncpy(paramValue, "_a", sizeof(paramValue)); + } else { + LOG(ERROR) << "Unexpected suffix value: " << paramValue; + return std::string(paramValue); + } + LOG(INFO) << "GetUpdateActiveSuffix = " << paramValue; + return std::string(paramValue); +} + #ifndef __WIN32 void SetFileAttributes(const std::string& file, uid_t owner, gid_t group, mode_t mode) { -- Gitee From 3233878e57b73d9a93ceb81dbfb6579e52be29d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Thu, 5 Jun 2025 17:24:21 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=8C=87=E9=92=88?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- interfaces/kits/slot_info/slot_info.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/slot_info/slot_info.cpp b/interfaces/kits/slot_info/slot_info.cpp index 40c31bd0..8be93f73 100644 --- a/interfaces/kits/slot_info/slot_info.cpp +++ b/interfaces/kits/slot_info/slot_info.cpp @@ -38,7 +38,7 @@ void SetActiveSlot() void GetPartitionSuffix(std::string &suffix) { LOG(INFO) << "enter etPartitionSuffix"; - sptr partitionslot = + OHOS::sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { LOG(ERROR) << "partitionslot ptr is nullptr"; @@ -64,7 +64,7 @@ void GetPartitionSuffix(std::string &suffix) void GetActivePartitionSuffix(std::string &suffix) { LOG(INFO) << "enter GetActivePartitionSuffix"; - sptr partitionslot = + OHOS::sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { LOG(ERROR) << "partitionslot ptr is nullptr"; @@ -89,7 +89,7 @@ void GetActivePartitionSuffix(std::string &suffix) void SetActiveSlot() { LOG(INFO) << "enter SetActiveSlot"; - sptr partitionslot = + OHOS::sptr partitionslot = OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); if (partitionslot == nullptr) { LOG(ERROR) << "partitionslot ptr is nullptr"; -- Gitee From 7f9484198d2843c7b17bc21cf19bbe5f29f9ccf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Thu, 5 Jun 2025 18:51:01 +0800 Subject: [PATCH 18/21] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- services/BUILD.gn | 2 ++ services/updater.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 5377cf83..fdadaca6 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -81,6 +81,7 @@ ohos_static_library("libupdater_static") { "${updater_path}/interfaces/kits/misc_info:libmiscinfo", "${updater_path}/services/sdcard_update:libsdupdate", "${updater_path}/interfaces/kits/slot_info:libslotinfo", + "${updater_path}/interfaces/kits/slot_info:libslotinfo_static", ] if (defined(use_ptable)) { @@ -99,6 +100,7 @@ ohos_static_library("libupdater_static") { "openssl:libcrypto_shared", "openssl:libssl_shared", "zlib:libz", + "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", ] if (updater_ui_support) { external_deps += [ "drivers_interface_input:libinput_proxy_1.0" ] diff --git a/services/updater.cpp b/services/updater.cpp index 5ed42fb1..dcdfc20e 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -52,7 +52,7 @@ #include "updater_ui_stub.h" #include "utils.h" #include "write_state/write_state.h" -#include "slot_info/slot_info.h" +#include "slot_info/slot_info_static.h" namespace Updater { using Updater::Utils::SplitString; @@ -316,7 +316,7 @@ UpdaterStatus SetUpdateSuffixParam() { LOG(INFO) << "enter setupdatesuffixparam"; std::string suffix = ""; - GetPartitionSuffix(suffix); + GetPartitionSuffixStatic(suffix); if (!Utils::SetUpdateSuffix(suffix)) { LOG(ERROR) << "set update.part.suffix fail"; return UPDATE_ERROR; -- Gitee From b5b39305510444916d0049c4872762916c299718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Fri, 6 Jun 2025 08:19:59 +0800 Subject: [PATCH 19/21] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- .../kits/slot_info/slot_info_static.cpp | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/slot_info/slot_info_static.cpp b/interfaces/kits/slot_info/slot_info_static.cpp index 823a209f..bcd6a0e4 100755 --- a/interfaces/kits/slot_info/slot_info_static.cpp +++ b/interfaces/kits/slot_info/slot_info_static.cpp @@ -17,11 +17,13 @@ #include "slot_info/slot_info_static.h" #include "log/log.h" #include -#include "utils.h" namespace Updater { +#define MISC_DEVICE_NODE "/dev/block/by-name/bootctrl" constexpr int32_t UPDATE_PARTITION_A = 1; constexpr int32_t UPDATE_PARTITION_AB = 2; +constexpr off_t MISC_PARTITION_ACTIVE_SLOT_OFFSET = 1024; +constexpr off_t MISC_PARTITION_ACTIVE_SLOT_SIZE = 4; #ifndef UPDATER_AB_SUPPORT void GetPartitionSuffixStatic(std::string &suffix) @@ -33,10 +35,32 @@ void GetActivePartitionSuffixStatic(std::string &suffix) suffix = ""; } #else +static int ReadMisc(off_t offset, off_t size) +{ + int fd = open(MISC_DEVICE_NODE, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) { + return -1; + } + if (lseek(fd, offset, SEEK_SET) < 0) { + LOG(ERROR) << "Failed lseek miscDevice"; + close(fd); + return -1; + } + int32_t slot = 0; + if (read(fd, &slot, size) != size) { + LOG(ERROR) <<"Failed read migic miscDevice"; + close(fd); + return -1; + } + LOG(INFO) << "Read slot:" << slot; + close(fd); + return slot; +} + void GetPartitionSuffixStatic(std::string &suffix) { - // 1. update.part.slot属性值获取 - int32_t current_slot = Utils::GetUpdateSlot(); + // 1. 通过popen执行cat命令获取cmdline内容 + int32_t current_slot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); LOG(INFO) << "current_slot: " << current_slot; @@ -54,8 +78,8 @@ void GetPartitionSuffixStatic(std::string &suffix) void GetActivePartitionSuffixStatic(std::string &suffix) { - // 1. update.part.slot属性值获取 - int32_t current_slot = Utils::GetUpdateSlot(); + // 1. 通过popen执行cat命令获取cmdline内容 + int32_t current_slot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); LOG(INFO) << "current_slot: " << current_slot; -- Gitee From 655b3f103c2e67c176ad129db98b1f2a6dd88f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Fri, 6 Jun 2025 10:04:36 +0800 Subject: [PATCH 20/21] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- utils/utils.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/utils.cpp b/utils/utils.cpp index 20c331ea..0d27bd49 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -1119,9 +1119,16 @@ bool SetUpdateSuffix(std::string stringsuffix) return false; } int tryNum = 3; + int ret1 = 0; + int ret2 = 0; while (tryNum-- > 0) { - if (SetParameter("update.part.suffix", stringsuffix.c_str()) != 0) { - LOG(ERROR) << "set update.part.suffix fail"; + ret1 = SetParameter("update.part.slot", setSlotStr.c_str()); + if (ret1 != 0) { + LOG(ERROR) << "set update.part.slot fail, ret1 = " << ret1; + } + ret2 = SetParameter("update.part.suffix", stringsuffix.c_str()); + if (ret2 != 0) { + LOG(ERROR) << "set update.part.suffix fail, ret2 = " << ret2; continue; } if (strcmp(GetUpdateSuffix().c_str(), stringsuffix.c_str()) == 0) { -- Gitee From 2e07194ff3d811a97df0f636c54dadbe63dcf996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E7=BD=97=E5=AE=87?= Date: Fri, 6 Jun 2025 10:24:24 +0800 Subject: [PATCH 21/21] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 甘罗宇 --- utils/utils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/utils.cpp b/utils/utils.cpp index 0d27bd49..0453e545 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -1121,6 +1121,8 @@ bool SetUpdateSuffix(std::string stringsuffix) int tryNum = 3; int ret1 = 0; int ret2 = 0; + int setSlot = 1; + std::string setSlotStr = std::to_string(setSlot); while (tryNum-- > 0) { ret1 = SetParameter("update.part.slot", setSlotStr.c_str()); if (ret1 != 0) { -- Gitee