Skip to content

Commit

Permalink
[nrf noup] Moved putting QSPI to sleep after OTA requestor init
Browse files Browse the repository at this point in the history
Fixed bug observed on nRF53 SED that ends with assert due to
not initialized QSPI during OTA Requestor init.
  • Loading branch information
kkasperczyk-no authored and Damian-Nordic committed Jun 6, 2022
1 parent 4f5cc99 commit a79fe42
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
44 changes: 17 additions & 27 deletions src/platform/nrfconnect/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
{
VerifyOrReturnError(mDownloader != nullptr, CHIP_ERROR_INCORRECT_STATE);

TriggerFlashAction(FlashHandler::Action::WAKE_UP);

return DeviceLayer::SystemLayer().ScheduleLambda([this] { mDownloader->OnPreparedForDownload(PrepareDownloadImpl()); });
}

Expand All @@ -55,7 +57,10 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()

CHIP_ERROR OTAImageProcessorImpl::Abort()
{
return System::MapErrorZephyr(dfu_target_reset());
CHIP_ERROR error = System::MapErrorZephyr(dfu_target_reset());

TriggerFlashAction(FlashHandler::Action::SLEEP);
return error;
}

CHIP_ERROR OTAImageProcessorImpl::Apply()
Expand All @@ -67,6 +72,8 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
err = dfu_target_schedule_update(-1);
}

TriggerFlashAction(FlashHandler::Action::SLEEP);

#ifdef CONFIG_CHIP_OTA_REQUESTOR_REBOOT_ON_APPLY
if (!err)
{
Expand Down Expand Up @@ -206,8 +213,16 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessHeader(ByteSpan & aBlock)
return CHIP_NO_ERROR;
}

void OTAImageProcessorImpl::TriggerFlashAction(FlashHandler::Action action)
{
if (mFlashHandler)
{
mFlashHandler->DoAction(action);
}
}

// external flash power consumption optimization
void ExtFlashHandler::DoAction(Action aAction)
void FlashHandler::DoAction(Action aAction)
{
#if CONFIG_PM_DEVICE && CONFIG_NORDIC_QSPI_NOR && !CONFIG_SOC_NRF52840 // nRF52 is optimized per default
// utilize the QSPI driver sleep power mode
Expand All @@ -220,30 +235,5 @@ void ExtFlashHandler::DoAction(Action aAction)
#endif
}

OTAImageProcessorImplPMDevice::OTAImageProcessorImplPMDevice(ExtFlashHandler & aHandler) : mHandler(aHandler)
{
mHandler.DoAction(ExtFlashHandler::Action::SLEEP);
}

CHIP_ERROR OTAImageProcessorImplPMDevice::PrepareDownload()
{
mHandler.DoAction(ExtFlashHandler::Action::WAKE_UP);
return OTAImageProcessorImpl::PrepareDownload();
}

CHIP_ERROR OTAImageProcessorImplPMDevice::Abort()
{
auto status = OTAImageProcessorImpl::Abort();
mHandler.DoAction(ExtFlashHandler::Action::SLEEP);
return status;
}

CHIP_ERROR OTAImageProcessorImplPMDevice::Apply()
{
auto status = OTAImageProcessorImpl::Apply();
mHandler.DoAction(ExtFlashHandler::Action::SLEEP);
return status;
}

} // namespace DeviceLayer
} // namespace chip
40 changes: 16 additions & 24 deletions src/platform/nrfconnect/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,25 @@ class OTADownloader;

namespace DeviceLayer {

class FlashHandler
{
public:
enum class Action : uint8_t
{
WAKE_UP,
SLEEP
};
virtual ~FlashHandler() {}
virtual void DoAction(Action aAction);
};

class OTAImageProcessorImpl : public OTAImageProcessorInterface
{
public:
static constexpr size_t kBufferSize = CONFIG_CHIP_OTA_REQUESTOR_BUFFER_SIZE;

OTAImageProcessorImpl(FlashHandler * flashHandler = nullptr) : mFlashHandler(flashHandler){};

enum class ImageType : uint8_t
{
kAppImage = 0,
Expand All @@ -54,6 +68,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
CHIP_ERROR ProcessBlock(ByteSpan & aBlock) override;
bool IsFirstImageRun() override;
CHIP_ERROR ConfirmCurrentImage() override;
void TriggerFlashAction(FlashHandler::Action action);

private:
CHIP_ERROR PrepareDownloadImpl();
Expand All @@ -66,30 +81,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
uint8_t mBuffer[kBufferSize];
OTAImageContentHeader mContentHeader;
OTAImage mCurrentImage;
};

class ExtFlashHandler
{
public:
enum class Action : uint8_t
{
WAKE_UP,
SLEEP
};
virtual ~ExtFlashHandler() {}
virtual void DoAction(Action aAction);
};

class OTAImageProcessorImplPMDevice : public OTAImageProcessorImpl
{
public:
explicit OTAImageProcessorImplPMDevice(ExtFlashHandler & aHandler);
CHIP_ERROR PrepareDownload() override;
CHIP_ERROR Abort() override;
CHIP_ERROR Apply() override;

private:
ExtFlashHandler & mHandler;
FlashHandler * mFlashHandler;
};

} // namespace DeviceLayer
Expand Down

0 comments on commit a79fe42

Please sign in to comment.