/* * Copyright (c) 2023 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 BIN_FLOW_UPDATE #define BIN_FLOW_UPDATE #include #include #include #include #include #include #include "applypatch/data_writer.h" #include "package/pkg_manager.h" namespace Updater { using BinFlowUpdateStep = enum { BIN_UPDATE_STEP_PRE = 0, BIN_UPDATE_STEP_DO, BIN_UPDATE_STEP_POST }; struct BinFlowUpdateInfo { std::vector componentNames; uint32_t curIndex = 0; size_t imageWriteLen = 0; bool needNewData = false; std::map> updateBinProcess_; BinFlowUpdateStep updateStep = BIN_UPDATE_STEP_PRE; std::unique_ptr writer; const Hpackage::FileInfo *info = nullptr; }; class BinFlowUpdate { public: explicit BinFlowUpdate(uint32_t maxBufSize); virtual ~BinFlowUpdate(); int32_t StartBinFlowUpdate(uint8_t *data, uint32_t len); private: int32_t BinUpdatePreWrite(uint8_t *data, uint32_t &len); int32_t BinUpdateDoWrite(uint8_t *data, uint32_t &len); int32_t BinUpdatePostWrite(uint8_t *data, uint32_t &len); int32_t UpdateBinData(uint8_t *data, uint32_t &len); std::unique_ptr GetDataWriter(const std::string &partition); uint32_t UpdateBinHead(uint8_t *data, uint32_t &len); bool AddRemainData(uint8_t *data, uint32_t &len); Hpackage::PkgManager::PkgManagerPtr pkgManager_; uint8_t *buffer_ = nullptr; uint32_t maxBufSize_ = 0; uint32_t curlen_ = 0; // bin images bool headInit_ = false; std::vector componentNames_; uint32_t procCompIndex_ = 0; std::map> updateBinProcess_; BinFlowUpdateInfo updateInfo_ {}; }; } // Updater #endif /* BIN_FLOW_UPDATE */