Skip to content

Commit

Permalink
Added changes for the multi OTA 917 NCP
Browse files Browse the repository at this point in the history
  • Loading branch information
shgutte committed Apr 4, 2024
1 parent d7cc14b commit 501f56b
Show file tree
Hide file tree
Showing 12 changed files with 626 additions and 326 deletions.
2 changes: 2 additions & 0 deletions src/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ static_library("SiWx917") {
"${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.h",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.h",
"${silabs_platform_dir}/multi-ota/OTAUtilityFirmwareProcessor.cpp",
"${silabs_platform_dir}/multi-ota/OTAUtilityFirmwareProcessor.h",
"${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor.cpp",
"${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor.h",
"${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ static_library("efr32") {
"${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.h",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.h",
"${silabs_platform_dir}/multi-ota/OTAUtilityFirmwareProcessor.cpp",
"${silabs_platform_dir}/multi-ota/OTAUtilityFirmwareProcessor.h",
"${silabs_platform_dir}/multi-ota/efr32/OTAFirmwareProcessor.cpp",
"${silabs_platform_dir}/multi-ota/efr32/OTAFirmwareProcessor.h",
"${silabs_platform_dir}/multi-ota/efr32/OTAHooks.cpp",
Expand Down
77 changes: 77 additions & 0 deletions src/platform/silabs/multi-ota/917NCP/OTAFirmwareProcessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/silabs/multi-ota/OTAMultiImageProcessorImpl.h>
#include <platform/silabs/multi-ota/efr32/OTAFirmwareProcessor.h>

#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#include "wfx_host_events.h"
#include <platform/silabs/SilabsConfig.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "sl_si91x_driver.h"
#ifdef SLI_SI91X_MCU_INTERFACE
#include "sl_si91x_hal_soc_soft_reset.h"
#endif
#ifdef __cplusplus
}
#endif

// TODO: more descriptive error codes
#define SL_OTA_ERROR 1L

namespace chip {

CHIP_ERROR OTAFirmwareProcessor::Init()
{
ReturnErrorCodeIf(mCallbackProcessDescriptor == nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED);
return OTAUtilityFirmwareProcessor::getInstance()->Init();
}

CHIP_ERROR OTAFirmwareProcessor::Clear()
{
OTATlvProcessor::ClearInternal();
return OTAUtilityFirmwareProcessor::getInstance()->Clear();
}

CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block)
{
return OTAUtilityFirmwareProcessor::getInstance()->ProcessInternal917(block);
}

CHIP_ERROR OTAFirmwareProcessor::ProcessDescriptor(ByteSpan & block)
{
OTADataAccumulator *mAccumulator = &OTAUtilityFirmwareProcessor::getInstance()->mAccumulator;
ReturnErrorOnFailure(mAccumulator->Accumulate(block));
ReturnErrorOnFailure(mCallbackProcessDescriptor(static_cast<void *>(mAccumulator->data())));
return OTAUtilityFirmwareProcessor::getInstance()->ProcessDescriptor(block);
}

CHIP_ERROR OTAFirmwareProcessor::ApplyAction()
{
return OTAUtilityFirmwareProcessor::getInstance()->ApplyAction917();
}

CHIP_ERROR OTAFirmwareProcessor::FinalizeAction()
{
return OTAUtilityFirmwareProcessor::getInstance()->FinalizeAction917();
}

} // namespace chip
46 changes: 46 additions & 0 deletions src/platform/silabs/multi-ota/917NCP/OTAFirmwareProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 <lib/support/Span.h>
#include <platform/silabs/multi-ota/OTATlvProcessor.h>
#include "OTAUtilityFirmwareProcessor.h"

namespace chip {

class OTAFirmwareProcessor : public OTATlvProcessor
{
public:
struct Descriptor
{
uint32_t version;
char versionString[kVersionStringSize];
char buildDate[kBuildDateSize];
};

CHIP_ERROR Init() override;
CHIP_ERROR Clear() override;
CHIP_ERROR ApplyAction() override;
CHIP_ERROR FinalizeAction() override;
private:
CHIP_ERROR ProcessInternal(ByteSpan & block) override;
CHIP_ERROR ProcessDescriptor(ByteSpan & block);
};

} // namespace chip
44 changes: 44 additions & 0 deletions src/platform/silabs/multi-ota/917NCP/OTAHooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 <include/platform/CHIPDeviceLayer.h>
#include <platform/silabs/multi-ota/OTAMultiImageProcessorImpl.h>

#include <app/clusters/ota-requestor/OTARequestorInterface.h>

#include <platform/silabs/multi-ota/efr32/OTAFirmwareProcessor.h>

CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor)
{
auto desc = static_cast<chip::OTAFirmwareProcessor::Descriptor *>(descriptor);
ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate);

return CHIP_NO_ERROR;
}

CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit()
{
static chip::OTAFirmwareProcessor sApplicationProcessor;

sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor);

auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance();
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(6, &sApplicationProcessor));

return CHIP_NO_ERROR;
}
Loading

0 comments on commit 501f56b

Please sign in to comment.