diff --git a/partitionslot/BUILD.gn b/partitionslot/BUILD.gn old mode 100644 new mode 100755 diff --git a/partitionslot/bundle.json b/partitionslot/bundle.json old mode 100644 new mode 100755 index d154845b9464fabd31e2bc67f9df5645602df155..b82849ed5bdf518f6d59553f838a209608878cc9 --- a/partitionslot/bundle.json +++ b/partitionslot/bundle.json @@ -1,7 +1,7 @@ { "name": "@ohos/drivers_peripheral_partitionslot", "description": "partitionslot hdf", - "version": "3.1", + "version": "6.0", "license": "Apache License 2.0", "publishAs": "code-segment", "segment": { diff --git a/partitionslot/common/logs/iam_logger.h b/partitionslot/common/logs/iam_logger.h new file mode 100755 index 0000000000000000000000000000000000000000..5aaaeb78e3b336d8e9ef9f71f7c64ea04d8d2da2 --- /dev/null +++ b/partitionslot/common/logs/iam_logger.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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 IAM_LOGGER_H +#define IAM_LOGGER_H + +#include "hilog/log.h" +namespace OHOS { +namespace UserIam { +namespace Common { +#ifdef __FILE_NAME__ +#define PIN_AUTH_FILE __FILE_NAME__ +#else +#define PIN_AUTH_FILE (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) +#endif + +#ifdef LOG_DOMAIN +#undef LOG_DOMAIN +#endif + +#define LOG_DOMAIN 0xD002414 + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define PIN_AUTH_DEBUG(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__) +#define PIN_AUTH_INFO(...) HILOG_INFO(LOG_CORE, __VA_ARGS__) +#define PIN_AUTH_WARN(...) HILOG_WARN(LOG_CORE, __VA_ARGS__) +#define PIN_AUTH_ERROR(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__) +#define PIN_AUTH_FATAL(...) HILOG_FATAL(LOG_CORE, __VA_ARGS__) + +#define ARGS(fmt, ...) "[%{public}s@%{public}s:%{public}d] " fmt, __FUNCTION__, PIN_AUTH_FILE, __LINE__, ##__VA_ARGS__ +#define PIN_LOG(level, ...) PIN_AUTH_##level(ARGS(__VA_ARGS__)) + +#define IAM_LOGD(...) PIN_LOG(DEBUG, __VA_ARGS__) +#define IAM_LOGI(...) PIN_LOG(INFO, __VA_ARGS__) +#define IAM_LOGW(...) PIN_LOG(WARN, __VA_ARGS__) +#define IAM_LOGE(...) PIN_LOG(ERROR, __VA_ARGS__) +#define IAM_LOGF(...) PIN_LOG(FATAL, __VA_ARGS__) + +} // namespace Common +} // namespace UserIam +} // namespace OHOS + +#endif // IAM_LOGGER_H \ No newline at end of file diff --git a/partitionslot/common/utils/iam_ptr.h b/partitionslot/common/utils/iam_ptr.h new file mode 100755 index 0000000000000000000000000000000000000000..4da9c23a2afbfa1acccd2049281c9f8dad0a77c0 --- /dev/null +++ b/partitionslot/common/utils/iam_ptr.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 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 IAM_PTR_H +#define IAM_PTR_H + +#include + +#include "refbase.h" + +namespace OHOS { +namespace UserIam { +namespace Common { +template +static inline std::shared_ptr SptrToStdSharedPtr(sptr &other) +{ + return std::shared_ptr(other.GetRefPtr(), [other](T *) mutable { other = nullptr; }); +} + +template +static inline std::shared_ptr MakeShared(Args &&... args) +{ + try { + return std::make_shared(std::forward(args)...); + } catch (...) { + return nullptr; + } +} + +template +static inline std::unique_ptr MakeUnique(Args &&... args) +{ + try { + return std::make_unique(std::forward(args)...); + } catch (...) { + return nullptr; + } +} +} // namespace Common +} // namespace UserIam +} // namespace OHOS + +#endif // IAM_PTR_H \ No newline at end of file diff --git a/partitionslot/hal/BUILD.gn b/partitionslot/hal/BUILD.gn old mode 100644 new mode 100755 diff --git a/partitionslot/hal/include/partitionslot_manager.h b/partitionslot/hal/include/partitionslot_manager.h old mode 100644 new mode 100755 index 836a15fb869bf77f13595339ebb512dbd8fe7d9b..0797ae154f219ee6f549d6bbf903476dcd8b8ea9 --- a/partitionslot/hal/include/partitionslot_manager.h +++ b/partitionslot/hal/include/partitionslot_manager.h @@ -24,20 +24,23 @@ namespace OHOS { namespace HDI { namespace Partitionslot { -namespace V1_0 { +namespace V1_1 { class PartitionSlotManager : public DelayedSingleton { public: int32_t GetCurrentSlot(int32_t& currentSlot, int32_t& numOfSlots); int32_t GetSlotSuffix(int32_t slot, std::string& suffix); + int32_t GetCheckpoint(int32_t& checkpoint); int32_t SetActiveSlot(int32_t slot); int32_t SetSlotUnbootable(int32_t slot); + int32_t SetCheckpoint(int32_t checkpoint); private: int32_t WriteSlot(int fd, int32_t slot, off_t offset, off_t size); int ReadMisc(off_t offset, off_t size); int WriteSlotToMisc(int32_t slot, off_t offset, off_t size); + int WriteCheckpointToMisc(int32_t checkpoint, off_t offset, off_t size); }; -} // V1_0 +} // V1_1 } // Partitionslot } // HDI } // OHOS diff --git a/partitionslot/hal/src/partitionslot_manager.cpp b/partitionslot/hal/src/partitionslot_manager.cpp old mode 100644 new mode 100755 index e462e936f9c9843e4ec43c32e6dbd4a7f1d4c97a..16a8d8fa591683d4a7fde2c36ef57e7971236e45 --- a/partitionslot/hal/src/partitionslot_manager.cpp +++ b/partitionslot/hal/src/partitionslot_manager.cpp @@ -29,7 +29,7 @@ namespace OHOS { namespace HDI { namespace Partitionslot { -namespace V1_0 { +namespace V1_1 { constexpr int32_t UPDATE_PARTITION_B = 2; @@ -39,13 +39,23 @@ constexpr off_t MISC_PARTITION_ACTIVE_SLOT_SIZE = 4; constexpr off_t MISC_PARTITION_UNBOOT_SLOT_OFFSET = MISC_PARTITION_ACTIVE_SLOT_OFFSET + MISC_PARTITION_ACTIVE_SLOT_SIZE; constexpr off_t MISC_PARTITION_UNBOOT_SLOT_SIZE = 4; +constexpr off_t MISC_PARTITION_CHECKPOINT_OFFSET = MISC_PARTITION_UNBOOT_SLOT_OFFSET + MISC_PARTITION_UNBOOT_SLOT_SIZE; +constexpr off_t MISC_PARTITION_CHECKPOINT_SIZE = 4; + #define MISC_DEVICE_NODE "/dev/block/by-name/bootctrl" +#define AB_PARTITON_NUM 2 +#define SIGER_PARTITON_NUM 1 int32_t PartitionSlotManager::GetCurrentSlot(int32_t& currentSlot, int32_t& numOfSlots) { HILOG_DEBUG(LOG_CORE, "%{public}s called!", __func__); numOfSlots = system::GetIntParameter("ohos.boot.bootslots", 1); currentSlot = ReadMisc(MISC_PARTITION_ACTIVE_SLOT_OFFSET, MISC_PARTITION_ACTIVE_SLOT_SIZE); + if (numOfSlots == AB_PARTITON_NUM) { + if ((currentSlot != SIGER_PARTITON_NUM) && (currentSlot != AB_PARTITON_NUM)) { + currentSlot = 1; + } + } HILOG_INFO(LOG_CORE, "current slot is %{public}d, numOfSlots is %{public}d", currentSlot, numOfSlots); return 0; } @@ -62,6 +72,14 @@ int32_t PartitionSlotManager::GetSlotSuffix(int32_t slot, std::string& suffix) return 0; } +int32_t PartitionSlotManager::GetCheckpoint(int32_t& checkpoint) +{ + HILOG_DEBUG(LOG_CORE, "%{public}s called!", __func__); + checkpoint = ReadMisc(MISC_PARTITION_CHECKPOINT_OFFSET, MISC_PARTITION_CHECKPOINT_SIZE); + HILOG_INFO(LOG_CORE, "checkpoint is %{public}d", checkpoint); + return 0; +} + int32_t PartitionSlotManager::SetActiveSlot(int32_t slot) { HILOG_DEBUG(LOG_CORE, "%{public}s called!, slot is %{public}d", __func__, slot); @@ -74,6 +92,13 @@ int32_t PartitionSlotManager::SetSlotUnbootable(int32_t slot) return WriteSlotToMisc(slot, MISC_PARTITION_UNBOOT_SLOT_OFFSET, MISC_PARTITION_UNBOOT_SLOT_SIZE); } +int32_t PartitionSlotManager::SetCheckpoint(int32_t checkpoint) +{ + HILOG_INFO(LOG_CORE, "set checkpoint is %{public}d", checkpoint); + HILOG_DEBUG(LOG_CORE, "%{public}s called!, checkpoint is %{public}d", __func__, checkpoint); + return WriteCheckpointToMisc(checkpoint, MISC_PARTITION_CHECKPOINT_OFFSET, MISC_PARTITION_CHECKPOINT_SIZE); +} + int32_t PartitionSlotManager::WriteSlot(int fd, int32_t slot, off_t offset, off_t size) { if (lseek(fd, offset, SEEK_SET) < 0) { @@ -130,7 +155,28 @@ int PartitionSlotManager::WriteSlotToMisc(int32_t slot, off_t offset, off_t size close(fd); return 0; } -} // V1_0 + +int PartitionSlotManager::WriteCheckpointToMisc(int32_t checkpoint, off_t offset, off_t size) +{ + if (checkpoint < 0) { + HILOG_ERROR(LOG_CORE, "Invalid checkpoint : %{public}d", checkpoint); + return -1; + } + int fd = open(MISC_DEVICE_NODE, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) { + HILOG_ERROR(LOG_CORE, "Failed to open miscDevice errno %{public}d ", errno); + return -1; + } + + if (WriteSlot(fd, checkpoint, offset, size) < 0) { + HILOG_ERROR(LOG_CORE, "Failed to WriteSlot miscDevice %{public}d errno %{public}d ", checkpoint, errno); + close(fd); + return -1; + } + close(fd); + return 0; +} +} // V1_1 } // Partitionslot } // HDI } // OHOS diff --git a/partitionslot/hdi_service/BUILD.gn b/partitionslot/hdi_service/BUILD.gn old mode 100644 new mode 100755 index 3bdbb95c0e760f0f7d178bb15269feb48e5db3a0..24383fa7bfc730e5614477d1ff8ec77c0f2b35b9 --- a/partitionslot/hdi_service/BUILD.gn +++ b/partitionslot/hdi_service/BUILD.gn @@ -13,15 +13,18 @@ import("//build/ohos.gni") -ohos_shared_library("libpartition_slot_service_1.0") { - include_dirs = [ "include" ] +ohos_shared_library("libpartition_slot_service_1.1") { + include_dirs = [ + "include", + "../common/logs", + ] sources = [ "src/partitionslot_impl.cpp" ] public_deps = [ "../../../../drivers/peripheral/partitionslot/hal:partitionslot_source", ] external_deps = [ "c_utils:utils", - "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", + "drivers_interface_partitionslot:libpartitionslot_proxy_1.1", "hdf_core:libhdf_utils", "hilog:libhilog", "init:libbegetutil", @@ -33,11 +36,14 @@ ohos_shared_library("libpartition_slot_service_1.0") { } ohos_shared_library("libpartitionslot_driver") { - include_dirs = [ "include" ] + include_dirs = [ + "include", + "../common/logs", + ] sources = [ "src/partition_slot_driver.cpp" ] external_deps = [ "c_utils:utils", - "drivers_interface_partitionslot:libpartitionslot_stub_1.0", + "drivers_interface_partitionslot:libpartitionslot_stub_1.1", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", @@ -54,7 +60,7 @@ ohos_shared_library("libpartitionslot_driver") { group("hdf_partitionslot_service") { deps = [ - ":libpartition_slot_service_1.0", + ":libpartition_slot_service_1.1", ":libpartitionslot_driver", ] } diff --git a/partitionslot/hdi_service/include/partitionslot_impl.h b/partitionslot/hdi_service/include/partitionslot_impl.h old mode 100644 new mode 100755 index 84dddbcee5ec69584ed44304054b6b4ed38860e9..e79818bf42a776f000ef4f9d12bddcdd4541712b --- a/partitionslot/hdi_service/include/partitionslot_impl.h +++ b/partitionslot/hdi_service/include/partitionslot_impl.h @@ -13,26 +13,28 @@ * limitations under the License. */ -#ifndef OHOS_HDI_PARTITIONSLOT_V1_0_PARTITIONSLOTIMPL_H -#define OHOS_HDI_PARTITIONSLOT_V1_0_PARTITIONSLOTIMPL_H +#ifndef OHOS_HDI_PARTITIONSLOT_V1_1_PARTITIONSLOTIMPL_H +#define OHOS_HDI_PARTITIONSLOT_V1_1_PARTITIONSLOTIMPL_H -#include "v1_0/ipartition_slot.h" +#include "v1_1/ipartition_slot.h" namespace OHOS { namespace HDI { namespace Partitionslot { -namespace V1_0 { +namespace V1_1 { class PartitionSlotImpl : public IPartitionSlot { public: virtual ~PartitionSlotImpl() {} int32_t GetCurrentSlot(int32_t& currentSlot, int32_t& numOfSlots) override; int32_t GetSlotSuffix(int32_t slot, std::string& suffix) override; + int32_t GetCheckpoint(int32_t& checkpoint) override; int32_t SetActiveSlot(int32_t slot) override; int32_t SetSlotUnbootable(int32_t slot) override; + int32_t SetCheckpoint(int32_t checkpoint) override; }; -} // V1_0 +} // V1_1 } // Partitionslot } // HDI } // OHOS -#endif // OHOS_HDI_PARTITIONSLOT_V1_0_PARTITIONSLOTIMPL_H \ No newline at end of file +#endif // OHOS_HDI_PARTITIONSLOT_V1_1_PARTITIONSLOTIMPL_H \ No newline at end of file diff --git a/partitionslot/hdi_service/src/partition_slot_driver.cpp b/partitionslot/hdi_service/src/partition_slot_driver.cpp old mode 100644 new mode 100755 index 32afb46805159674853f844239f10f359afb419d..c42599aacc1f340ca825be639af2ac201764a499 --- a/partitionslot/hdi_service/src/partition_slot_driver.cpp +++ b/partitionslot/hdi_service/src/partition_slot_driver.cpp @@ -17,9 +17,9 @@ #include #include #include -#include "v1_0/partition_slot_stub.h" +#include "v1_1/partition_slot_stub.h" -using namespace OHOS::HDI::Partitionslot::V1_0; +using namespace OHOS::HDI::Partitionslot::V1_1; struct HdfPartitionSlotHost { struct IDeviceIoService ioService; diff --git a/partitionslot/hdi_service/src/partitionslot_impl.cpp b/partitionslot/hdi_service/src/partitionslot_impl.cpp old mode 100644 new mode 100755 index a3e54d4c4e66787aa30de5cae7267904fea24df7..7149d01e5f3b197e96718d18e4e86b7138ddecda --- a/partitionslot/hdi_service/src/partitionslot_impl.cpp +++ b/partitionslot/hdi_service/src/partitionslot_impl.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace HDI { namespace Partitionslot { -namespace V1_0 { +namespace V1_1 { #define HDF_LOG_TAG hdf_partitionslot_impl extern "C" IPartitionSlot *PartitionSlotImplGetInstance(void) @@ -42,6 +42,12 @@ int32_t PartitionSlotImpl::GetSlotSuffix(int32_t slot, std::string& suffix) return PartitionSlotManager::GetInstance()->GetSlotSuffix(slot, suffix); } +int32_t PartitionSlotImpl::GetCheckpoint(int32_t& checkpoint) +{ + HDF_LOGD("%{public}s called!", __func__); + return PartitionSlotManager::GetInstance()->GetCheckpoint(checkpoint); +} + int32_t PartitionSlotImpl::SetActiveSlot(int32_t slot) { HDF_LOGD("%{public}s called!, slot is %{public}d", __func__, slot); @@ -53,7 +59,13 @@ int32_t PartitionSlotImpl::SetSlotUnbootable(int32_t slot) HDF_LOGD("%{public}s called!, slot is %{public}d", __func__, slot); return PartitionSlotManager::GetInstance()->SetSlotUnbootable(slot); } -} // V1_0 + +int32_t PartitionSlotImpl::SetCheckpoint(int32_t checkpoint) +{ + HDF_LOGD("%{public}s called!, checkpoint is %{public}d", __func__, checkpoint); + return PartitionSlotManager::GetInstance()->SetCheckpoint(checkpoint); +} +} // V1_1 } // Partitionslot } // HDI } // OHOS diff --git a/partitionslot/test/BUILD.gn b/partitionslot/test/BUILD.gn old mode 100644 new mode 100755 index 0240a6d0c7900a659ddc6da19fef1229965ccc10..0e511a9f1ee61a5439d7fcd5c458d0a8d9588e3e --- a/partitionslot/test/BUILD.gn +++ b/partitionslot/test/BUILD.gn @@ -19,7 +19,7 @@ ohos_unittest("partitionslot_hdi_test") { external_deps = [ "c_utils:utils", - "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", + "drivers_interface_partitionslot:libpartitionslot_proxy_1.1", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", diff --git a/partitionslot/test/unittest/hdf_partitionslot_test.cpp b/partitionslot/test/unittest/hdf_partitionslot_test.cpp old mode 100644 new mode 100755 index f04f210f6f0243a6021fcfdfa9b974ed84d9f417..2fc9bb51f712ec8128c2b33ebce161d47d2461eb --- a/partitionslot/test/unittest/hdf_partitionslot_test.cpp +++ b/partitionslot/test/unittest/hdf_partitionslot_test.cpp @@ -18,13 +18,13 @@ #include #include "hdf_log.h" #include "idevmgr_hdi.h" -#include "v1_0/ipartition_slot.h" +#include "v1_1/ipartition_slot.h" namespace OHOS { namespace PartitionSlot { using namespace testing; using namespace testing::ext; -using namespace OHOS::HDI::Partitionslot::V1_0; +using namespace OHOS::HDI::Partitionslot::V1_1; using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; class HDFPartitionSlotTest : public testing::Test { @@ -90,5 +90,22 @@ HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_004, TestSize.Level1) ASSERT_TRUE(partitionslot != nullptr); ASSERT_TRUE(partitionslot->SetSlotUnbootable(2) == 0); } + +HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_005, TestSize.Level1) +{ + std::cout << "begin set checkpoint by service" << std::endl; + sptr partitionslot = IPartitionSlot::Get(); + ASSERT_TRUE(partitionslot!= nullptr); + ASSERT_TRUE(partitionslot->SetCheckpoint(1) == 0); +} + +HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_006, TestSize.Level1) +{ + std::cout << "begin get checkpoint by service" << std::endl; + int checkpoint = 1; + sptr partitionslot = IPartitionSlot::Get(); + ASSERT_TRUE(partitionslot!= nullptr); + ASSERT_TRUE(partitionslot->GetCheckpoint(checkpoint) == 0); +} } // PartitionSlot } // OHOS