From 733f3a3d5f0af7751f6335ed8ebcb163ae6d8797 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 9 Dec 2021 15:34:04 +0000 Subject: [PATCH] Fix build errors --- .../lighting-app/nrfconnect/CMakeLists.txt | 4 +- .../lighting-app/nrfconnect/main/AppTask.cpp | 47 ++++++-- .../nrfconnect/main/include/AppTask.h | 1 + .../ota-requestor/ClusterInterface.cpp | 1 + .../clusters/ota-requestor/OTARequestor.cpp | 2 +- src/app/clusters/ota-requestor/OTARequestor.h | 15 +-- src/app/zap_cluster_list.py | 2 +- src/include/platform/OTARequestorInterface.h | 19 ++- src/lib/shell/commands/BUILD.gn | 4 +- src/lib/shell/commands/Ota.cpp | 48 ++------ src/platform/ESP32/OTAImageProcessorImpl.cpp | 113 ------------------ src/platform/ESP32/OTAImageProcessorImpl.h | 51 -------- src/platform/nrfconnect/BUILD.gn | 2 +- 13 files changed, 75 insertions(+), 234 deletions(-) delete mode 100644 src/platform/ESP32/OTAImageProcessorImpl.cpp delete mode 100644 src/platform/ESP32/OTAImageProcessorImpl.h diff --git a/examples/lighting-app/nrfconnect/CMakeLists.txt b/examples/lighting-app/nrfconnect/CMakeLists.txt index 1452ce1d6ef7ee..95cb6d03a915bd 100644 --- a/examples/lighting-app/nrfconnect/CMakeLists.txt +++ b/examples/lighting-app/nrfconnect/CMakeLists.txt @@ -78,7 +78,9 @@ target_sources(app PRIVATE ${GEN_DIR}/lighting-app/zap-generated/CHIPClusters.cpp ${GEN_DIR}/lighting-app/zap-generated/IMClusterCommandHandler.cpp ${NRFCONNECT_COMMON}/util/LEDWidget.cpp - ${NRFCONNECT_COMMON}/util/ThreadUtil.cpp) + ${NRFCONNECT_COMMON}/util/ThreadUtil.cpp + ${CHIP_ROOT}/src/app/clusters/ota-requestor/OTARequestor.cpp + ${CHIP_ROOT}/src/app/clusters/ota-requestor/BDXDownloader.cpp) chip_configure_data_model(app INCLUDE_CLIENT_CALLBACKS diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index 74efec03379d84..8c4b1391f88dbf 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -23,28 +23,34 @@ #include "LEDWidget.h" #include "LightingManager.h" #include "ThreadUtil.h" -#include -#include #include #include #include +#include +#include #include - #include #include - -#include - #include +#include #include +#if CONFIG_CHIP_OTA_REQUESTOR +#include +#include +#include +#endif + #include #include #include LOG_MODULE_DECLARE(app); +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; + namespace { constexpr int kFactoryResetTriggerTimeout = 3000; @@ -65,10 +71,20 @@ bool sIsThreadProvisioned = false; bool sIsThreadEnabled = false; bool sHaveBLEConnections = false; -} // namespace +#if CONFIG_CHIP_OTA_REQUESTOR +class DummyOTARequestorDriver : public chip::OTARequestorDriver +{ + bool CheckImageDownloadAllowed() override { return true; } + chip::UserConsentAction RequestUserConsent() override { return chip::ImmediateYes; } + void ImageDownloadComplete() override {} +} sOTARequestorDriver; + +OTAImageProcessorImpl sOTAImageProcessor; +chip::BDXDownloader sBDXDownloader; +chip::OTARequestor sOTARequestor; +#endif -using namespace ::chip::Credentials; -using namespace ::chip::DeviceLayer; +} // namespace AppTask AppTask::sAppTask; @@ -119,9 +135,22 @@ int AppTask::Init() PlatformMgr().AddEventHandler(ChipEventHandler, 0); #endif + InitOTARequestor(); + return 0; } +void AppTask::InitOTARequestor() +{ +#if CONFIG_CHIP_OTA_REQUESTOR + sBDXDownloader.SetImageProcessorDelegate(&sOTAImageProcessor); + sOTARequestor.SetOtaRequestorDriver(&sOTARequestorDriver); + sOTARequestor.SetBDXDownloader(&sBDXDownloader); + sOTARequestor.SetServerInstance(&chip::Server::GetInstance()); + chip::SetRequestorInstance(&sOTARequestor); +#endif +} + int AppTask::StartApp() { int ret = Init(); diff --git a/examples/lighting-app/nrfconnect/main/include/AppTask.h b/examples/lighting-app/nrfconnect/main/include/AppTask.h index 12ff22ba963ca3..62c35ba0430d32 100644 --- a/examples/lighting-app/nrfconnect/main/include/AppTask.h +++ b/examples/lighting-app/nrfconnect/main/include/AppTask.h @@ -52,6 +52,7 @@ class AppTask friend AppTask & GetAppTask(void); int Init(); + void InitOTARequestor(); static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor); static void ActionCompleted(LightingManager::Action_t aAction, int32_t aActor); diff --git a/src/app/clusters/ota-requestor/ClusterInterface.cpp b/src/app/clusters/ota-requestor/ClusterInterface.cpp index 03bee4216f9fe3..8ae3958a5108b0 100644 --- a/src/app/clusters/ota-requestor/ClusterInterface.cpp +++ b/src/app/clusters/ota-requestor/ClusterInterface.cpp @@ -20,6 +20,7 @@ * to the OTA Requestor object that handles them */ +#include #include // OTA Software Update Requestor Cluster AnnounceOtaProvider Command callback diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index 99844744893263..7e4806a0a3f384 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -334,7 +334,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr } } -OTARequestor::OTATriggerResult OTARequestor::TriggerImmediateQuery() +OTARequestorInterface::OTATriggerResult OTARequestor::TriggerImmediateQuery() { if (mProviderNodeId != kUndefinedNodeId) diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index bd342ceb415540..1a300dca43d4a7 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -48,19 +48,12 @@ class OTARequestor : public OTARequestorInterface // Application interface declarations -- start - // Return value for various trigger-type APIs - enum OTATriggerResult - { - kTriggerSuccessful = 0, - kNoProviderKnown = 1 - }; - // Application directs the Requestor to start the Image Query process // and download the new image if available - OTATriggerResult TriggerImmediateQuery(); + OTATriggerResult TriggerImmediateQuery() override; // Send ApplyImage - void ApplyUpdate(); + void ApplyUpdate() override; // A setter for the delegate class pointer void SetOtaRequestorDriver(OTARequestorDriver * driver) { mOtaRequestorDriver = driver; } @@ -95,7 +88,7 @@ class OTARequestor : public OTARequestorInterface // Handler for the AnnounceOTAProvider command EmberAfStatus HandleAnnounceOTAProvider( app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, - const app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData); + const app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData) override; // Virtual functions from OTARequestorInterface -- end /** @@ -120,7 +113,7 @@ class OTARequestor : public OTARequestorInterface * Called to indicate test mode. This is when the Requestor is used as a test tool and the the provider parameters are supplied * explicitly. */ - void TestModeSetProviderParameters(NodeId nodeId, FabricIndex fabIndex, EndpointId endpointId) + void TestModeSetProviderParameters(NodeId nodeId, FabricIndex fabIndex, EndpointId endpointId) override { mProviderNodeId = nodeId; mProviderFabricIndex = fabIndex; diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index 8d90adc6e1df79..990d882af6dae9 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -138,7 +138,7 @@ 'ON_OFF_SWITCH_CONFIG_CLUSTER': [], 'OPERATIONAL_CREDENTIALS_CLUSTER': [], 'OTA_BOOTLOAD_CLUSTER': [], - 'OTA_PROVIDER_CLUSTER': ['ota-requestor'], + 'OTA_PROVIDER_CLUSTER': [], 'OTA_REQUESTOR_CLUSTER': [], 'POLL_CONTROL_CLUSTER': [], 'POWER_CONFIG_CLUSTER': [], diff --git a/src/include/platform/OTARequestorInterface.h b/src/include/platform/OTARequestorInterface.h index 0af7452c51efe8..214fe76af2dc21 100644 --- a/src/include/platform/OTARequestorInterface.h +++ b/src/include/platform/OTARequestorInterface.h @@ -23,8 +23,7 @@ #include #include - -#include +#include #pragma once @@ -35,6 +34,13 @@ namespace chip { class OTARequestorInterface { public: + // Return value for various trigger-type APIs + enum OTATriggerResult + { + kTriggerSuccessful = 0, + kNoProviderKnown = 1 + }; + // Handler for the AnnounceOTAProvider command virtual EmberAfStatus HandleAnnounceOTAProvider( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, @@ -48,6 +54,15 @@ class OTARequestorInterface // Destructor virtual ~OTARequestorInterface() = default; + + // Send QueryImage command + virtual OTATriggerResult TriggerImmediateQuery() = 0; + + // Send ApplyImage command + virtual void ApplyUpdate() = 0; + + // Manually set OTA Provider parameters + virtual void TestModeSetProviderParameters(NodeId nodeId, FabricIndex fabIndex, EndpointId endpointId) = 0; }; // The instance of the class implementing OTARequestorInterface must be managed through diff --git a/src/lib/shell/commands/BUILD.gn b/src/lib/shell/commands/BUILD.gn index 9e2a06a33ac378..d669f6bf85427c 100644 --- a/src/lib/shell/commands/BUILD.gn +++ b/src/lib/shell/commands/BUILD.gn @@ -53,9 +53,7 @@ source_set("commands") { if (chip_enable_ota_requestor && chip_device_platform != "none") { sources += [ "Ota.cpp" ] - public_deps += [ "${chip_root}/src/app/clusters/ota-requestor:headers" ] - # TODO: remove dependency of OTA shell on controller-clusters - include_dirs = [ "${chip_root}/zzz_generated/controller-clusters" ] + configs += [ "${chip_root}/src/controller:config" ] } if (chip_device_platform != "none") { diff --git a/src/lib/shell/commands/Ota.cpp b/src/lib/shell/commands/Ota.cpp index ee018c94a387f0..2aac126e35573a 100644 --- a/src/lib/shell/commands/Ota.cpp +++ b/src/lib/shell/commands/Ota.cpp @@ -15,12 +15,6 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include #include #include @@ -28,12 +22,7 @@ #include #include #include - -#if CHIP_DEVICE_LAYER_TARGET_NRFCONNECT -#include -#elif CHIP_DEVICE_LAYER_TARGET_ESP32 -#include -#endif +#include using namespace chip::DeviceLayer; @@ -41,56 +30,33 @@ namespace chip { namespace Shell { namespace { -class DummyOTARequestorDriver : public OTARequestorDriver -{ - bool CheckImageDownloadAllowed() override { return true; } - void ImageDownloadComplete() override {} -} sOTARequestorDriver; - -constexpr size_t kActiveSessions = 1; -DeviceLayer::OTAImageProcessorImpl sOTAImageProcessor; -BDXDownloader sBDXDownloader; -CASEClientPool sCASEClientPool; -OperationalDeviceProxyPool sDevicePool; -OTARequestor sOTARequestor; Shell::Engine sSubShell; -void InitRequestor() -{ - Server::GetInstance().SetCASEClientPool(&sCASEClientPool); - Server::GetInstance().SetDevicePool(&sDevicePool); - sBDXDownloader.SetImageProcessorDelegate(&sOTAImageProcessor); - sOTARequestor.SetOtaRequestorDriver(&sOTARequestorDriver); - sOTARequestor.SetBDXDownloader(&sBDXDownloader); - sOTARequestor.SetServerInstance(&Server::GetInstance()); - SetRequestorInstance(&sOTARequestor); -} - CHIP_ERROR QueryImageHandler(int argc, char ** argv) { + VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(argc == 3, CHIP_ERROR_INVALID_ARGUMENT); const FabricIndex fabricIndex = static_cast(strtoul(argv[0], nullptr, 10)); const NodeId providerNodeId = static_cast(strtoull(argv[1], nullptr, 10)); const EndpointId providerEndpointId = static_cast(strtoul(argv[2], nullptr, 10)); - InitRequestor(); - sOTARequestor.TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId); - PlatformMgr().ScheduleWork([](intptr_t) { sOTARequestor.TriggerImmediateQuery(); }); + GetRequestorInstance()->TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId); + PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); }); return CHIP_NO_ERROR; } CHIP_ERROR ApplyImageHandler(int argc, char ** argv) { + VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(argc == 3, CHIP_ERROR_INVALID_ARGUMENT); const FabricIndex fabricIndex = static_cast(strtoul(argv[0], nullptr, 10)); const NodeId providerNodeId = static_cast(strtoull(argv[1], nullptr, 10)); const EndpointId providerEndpointId = static_cast(strtoul(argv[2], nullptr, 10)); - InitRequestor(); - sOTARequestor.TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId); - PlatformMgr().ScheduleWork([](intptr_t) { sOTARequestor.ApplyUpdate(); }); + GetRequestorInstance()->TestModeSetProviderParameters(providerNodeId, fabricIndex, providerEndpointId); + PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); }); return CHIP_NO_ERROR; } diff --git a/src/platform/ESP32/OTAImageProcessorImpl.cpp b/src/platform/ESP32/OTAImageProcessorImpl.cpp deleted file mode 100644 index b8c96e23b4f38b..00000000000000 --- a/src/platform/ESP32/OTAImageProcessorImpl.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * - * 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 "OTAImageProcessorImpl.h" -#include "ESP32Utils.h" - -#include -#include - -namespace chip { -namespace DeviceLayer { - -CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() -{ - VerifyOrReturnError(!mOtaUpdateInProgress, CHIP_ERROR_INCORRECT_STATE); - - mOtaUpdatePartition = esp_ota_get_next_update_partition(NULL); - if (mOtaUpdatePartition == nullptr) - { - ChipLogError(DeviceLayer, "Partition not found"); - return ESP32Utils::MapError(ESP_ERR_NOT_FOUND); - } - - ChipLogProgress(DeviceLayer, "Writing to partition subtype %d at offset 0x%x", mOtaUpdatePartition->subtype, - mOtaUpdatePartition->address); - - esp_err_t err = esp_ota_begin(mOtaUpdatePartition, OTA_WITH_SEQUENTIAL_WRITES, &mOtaUpdateHandle); - if (err != ESP_OK) - { - ChipLogError(DeviceLayer, "esp_ota_begin failed (%s)", esp_err_to_name(err)); - return ESP32Utils::MapError(err); - } - - mOtaUpdateImageLen = 0; - mOtaUpdateInProgress = true; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR OTAImageProcessorImpl::Finalize() -{ - VerifyOrReturnError(mOtaUpdateInProgress, CHIP_ERROR_INCORRECT_STATE); - - ChipLogProgress(DeviceLayer, "OTA image length %d bytes", mOtaUpdateImageLen); - esp_err_t err = esp_ota_end(mOtaUpdateHandle); - - if (err == ESP_ERR_OTA_VALIDATE_FAILED) - { - ChipLogError(DeviceLayer, "Image validation failed, image is corrupted"); - } - else if (err != ESP_OK) - { - ChipLogError(DeviceLayer, "esp_ota_end failed (%s)!", esp_err_to_name(err)); - } - - mOtaUpdateInProgress = false; - - return ESP32Utils::MapError(err); -} - -CHIP_ERROR OTAImageProcessorImpl::Abort() -{ - VerifyOrReturnError(mOtaUpdateInProgress, CHIP_ERROR_INCORRECT_STATE); - - mOtaUpdateInProgress = false; - mOtaUpdateImageLen = 0; - - return esp_ota_abort(mOtaUpdateHandle); -} - -CHIP_ERROR OTAImageProcessorImpl::Apply() -{ - VerifyOrReturnError(mOtaUpdateInProgress, CHIP_ERROR_INCORRECT_STATE); - - esp_err_t err = esp_ota_set_boot_partition(mOtaUpdatePartition); - ReturnErrorOnFailure(ESP32Utils::MapError(err)); - ChipLogProgress(DeviceLayer, "Applying, Boot partition set offset:0x%x", mOtaUpdatePartition->address); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) -{ - VerifyOrReturnError(mOtaUpdateInProgress, CHIP_ERROR_INCORRECT_STATE); - - esp_err_t err = esp_ota_write(mOtaUpdateHandle, data, length); - if (err != ESP_OK) - { - ChipLogError(DeviceLayer, "esp_ota_write failed (%s)", esp_err_to_name(err)); - Abort(); - return ESP32Utils::MapError(err); - } - mOtaUpdateImageLen += length; - ChipLogProgress(DeviceLayer, "Written image length %d", mOtaUpdateImageLen); - return CHIP_NO_ERROR; -} - -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/ESP32/OTAImageProcessorImpl.h b/src/platform/ESP32/OTAImageProcessorImpl.h deleted file mode 100644 index af453831a7d6ca..00000000000000 --- a/src/platform/ESP32/OTAImageProcessorImpl.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * - * 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. - */ - -#pragma once - -#include -#include - -#include "esp_err.h" -#include "esp_log.h" -#include "esp_ota_ops.h" -#include "esp_system.h" - -namespace chip { -namespace DeviceLayer { - -class OTAImageProcessorImpl : public OTAImageProcessorInterface -{ -public: - static constexpr size_t kBufferSize = 1024; - - CHIP_ERROR PrepareDownload() override; - CHIP_ERROR Finalize() override; - CHIP_ERROR Abort() override; - CHIP_ERROR Apply() override; - CHIP_ERROR ProcessBlock(ByteSpan & block) override; - -private: - bool mOtaUpdateInProgress = false; - const esp_partition_t * mOtaUpdatePartition = nullptr; - esp_ota_handle_t mOtaUpdateHandle; - uint32_t mOtaUpdateImageLen = 0; - uint8_t mBuffer[1024]; -}; - -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/nrfconnect/BUILD.gn b/src/platform/nrfconnect/BUILD.gn index f7a6a27f7b7d34..0bf154e0ded158 100644 --- a/src/platform/nrfconnect/BUILD.gn +++ b/src/platform/nrfconnect/BUILD.gn @@ -73,8 +73,8 @@ static_library("nrfconnect") { if (chip_enable_ota_requestor) { sources += [ - "OTAImageProcessorImpl.h", "OTAImageProcessorImpl.cpp", + "OTAImageProcessorImpl.h", ] } }