From 8ef1dc180dba4afbe2eeb06e928e3700f28950cf Mon Sep 17 00:00:00 2001 From: like2001 Date: Sat, 31 Aug 2024 10:41:45 +0800 Subject: [PATCH 1/2] flashd erase norflash partition --- services/flashd/partition.cpp | 39 +++++++++++++++++++++++++++++++++++ services/flashd/partition.h | 1 + 2 files changed, 40 insertions(+) diff --git a/services/flashd/partition.cpp b/services/flashd/partition.cpp index 7519f001..2d6eb14b 100644 --- a/services/flashd/partition.cpp +++ b/services/flashd/partition.cpp @@ -23,6 +23,8 @@ #include "flashd_utils.h" #include "fs_manager/mount.h" #include "utils.h" +#include "ptable_manager.h" +#include "applypatch/data_writer.h" namespace Flashd { int Partition::DoFlash(const uint8_t *buffer, int bufferSize) const @@ -40,6 +42,43 @@ int Partition::DoFlash(const uint8_t *buffer, int bufferSize) const } int Partition::DoErase() const +{ + std::string writeMode = "WRITE_RAW"; + uint64_t partitionSize = 0; +#ifdef UPDATER_USE_PTABLE + DevicePtable::GetInstance().LoadPartitionInfo(); + DevicePtable &devicePtb = DevicePtable::GetInstance(); + Ptable::PtnInfo ptnInfo; + if (!devicePtb.GetPartionInfoByName(devName_, ptnInfo)) { + FLASHD_LOGE("DoErase: cannot find the lun index of partition: %s", devName.c_str()); + return -1; + } + writeMode = ptnInfo.writeMode; + partitionSize = ptnInfo.partitionSize; + std::unique_ptr dataWriter = DataWriter::CreateDataWriter(writeMode, + ptnInfo.writePath, devName_, ptnInfo.startAddr); +#else + std::unique_ptr dataWriter = DataWriter::CreateDataWriter(WRITE_RAW, + GetBlockDeviceByMountPoint(partition)); +#endif + if (writeMode != "WRITE_RAW") { + FLASHD_LOGI("erase norflash partition"); + std::vector zeroBuffer(partitionSize, 0); + if (!dataWriter->Write(zeroBuffer.data(), partitionSize, nullptr)) { + FLASHD_LOGE("erase %s failed", devName_.c_str()); + return -1; + } + } else { + FLASHD_LOGI("erase raw partition"); + if (auto ret = EraseRawImage(); ret != 0) { + FLASHD_LOGE("erase %s failed", devName_.c_str()); + return -1; + } + } + return 0; +} + +int Partition::EraseRawImage() const { auto fd = open(Updater::Utils::GetPartitionRealPath(devName_).c_str(), O_RDWR); if (fd < 0) { diff --git a/services/flashd/partition.h b/services/flashd/partition.h index 1bd3846d..b9f9bec7 100644 --- a/services/flashd/partition.h +++ b/services/flashd/partition.h @@ -30,6 +30,7 @@ public: int DoFlash(const uint8_t *buffer, int bufferSize) const; int DoFormat() const; int DoErase() const; + int EraseRawImage() const; private: uint64_t GetBlockDeviceSize(int fd) const; -- Gitee From b686cc28f400791586747ee61eedf746d41fcab8 Mon Sep 17 00:00:00 2001 From: like2001 Date: Sat, 31 Aug 2024 10:41:45 +0800 Subject: [PATCH 2/2] flashd erase norflash partition Signed-off-by: like2001 --- services/flashd/partition.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/flashd/partition.cpp b/services/flashd/partition.cpp index 2d6eb14b..63da3f5a 100644 --- a/services/flashd/partition.cpp +++ b/services/flashd/partition.cpp @@ -61,6 +61,13 @@ int Partition::DoErase() const std::unique_ptr dataWriter = DataWriter::CreateDataWriter(WRITE_RAW, GetBlockDeviceByMountPoint(partition)); #endif +<<<<<<< HEAD +======= + if (!dataWriter) { + FLASHD_LOGE("DataWriter creation failed"); + return -1; + } +>>>>>>> 377e7c59 (flashd erase norflash partition) if (writeMode != "WRITE_RAW") { FLASHD_LOGI("erase norflash partition"); std::vector zeroBuffer(partitionSize, 0); -- Gitee