Skip to content

Commit c827a7e

Browse files
committed
Inital multi OTA work WIP
1 parent 1913dba commit c827a7e

18 files changed

+1852
-10
lines changed

examples/platform/silabs/OTAConfig.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "OTAConfig.h"
2020
#include <app/server/Server.h>
21+
#include "silabs_utils.h"
2122

2223
#ifndef SIWX_917
2324

@@ -81,7 +82,6 @@ chip::DefaultOTARequestor gRequestorCore;
8182
chip::DefaultOTARequestorStorage gRequestorStorage;
8283
chip::DeviceLayer::DefaultOTARequestorDriver gRequestorUser;
8384
chip::BDXDownloader gDownloader;
84-
chip::OTAImageProcessorImpl gImageProcessor;
8585

8686
void OTAConfig::Init()
8787
{
@@ -93,12 +93,18 @@ void OTAConfig::Init()
9393

9494
// Periodic query timeout must be set prior to requestor being initialized
9595
gRequestorUser.SetPeriodicQueryTimeout(OTA_PERIODIC_TIMEOUT);
96-
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
9796

98-
gImageProcessor.SetOTAImageFile("test.txt");
99-
gImageProcessor.SetOTADownloader(&gDownloader);
97+
auto & imageProcessor = chip::OTAImageProcessorImpl::GetDefaultInstance();
98+
gRequestorUser.Init(&gRequestorCore, &imageProcessor);
99+
100+
CHIP_ERROR err = imageProcessor.Init(&gDownloader);
101+
if (err != CHIP_NO_ERROR)
102+
{
103+
SILABS_LOG("Image processor init failed");
104+
assert(err == CHIP_NO_ERROR);
105+
}
100106

101107
// Connect the Downloader and Image Processor objects
102-
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
108+
gDownloader.SetImageProcessorDelegate(&imageProcessor);
103109
// Initialize and interconnect the Requestor and Image Processor objects -- END
104110
}

examples/platform/silabs/OTAConfig.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
2323
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
2424
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
25+
26+
#ifdef CHIP_DEVICE_CONFIG_ENABLE_MULTI_OTA_REQUESTOR
27+
#include <platform/silabs/multi-ota/MultiOTAImageProcessorImpl.h>
28+
#else
2529
#include <platform/silabs/OTAImageProcessorImpl.h>
30+
#endif
2631

2732
class OTAConfig
2833
{

src/platform/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
151151
defines += [
152152
"CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR=${chip_enable_ota_requestor}",
153153
]
154+
# TODO: add this to silabs platform specific code
155+
defines += [
156+
"CHIP_DEVICE_CONFIG_ENABLE_MULTI_OTA_REQUESTOR=${chip_enable_multi_ota_requestor}",
157+
]
154158

155159
if (chip_device_project_config_include != "") {
156160
defines += [ "CHIP_DEVICE_PROJECT_CONFIG_INCLUDE=${chip_device_project_config_include}" ]

src/platform/device.gni

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ declare_args() {
8787

8888
# Enable OTA requestor support
8989
chip_enable_ota_requestor = false
90+
# TODO: add this to silabs platform specific code
91+
chip_enable_multi_ota_requestor = false
9092

9193
# Select DNS-SD implementation
9294
if (chip_device_platform == "linux" || chip_device_platform == "esp32" ||

src/platform/silabs/OTAImageProcessorImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
4040
CHIP_ERROR ConfirmCurrentImage() override;
4141

4242
void SetOTADownloader(OTADownloader * downloader) { mDownloader = downloader; }
43-
void SetOTAImageFile(const char * imageFile) { mImageFile = imageFile; }
43+
CHIP_ERROR Init(OTADownloader * downloader);
44+
static OTAImageProcessorImpl & GetDefaultInstance();
4445

4546
private:
4647
//////////// Actual handlers for the OTAImageProcessorInterface ///////////////
@@ -68,7 +69,6 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
6869
MutableByteSpan mBlock;
6970
OTADownloader * mDownloader;
7071
OTAImageHeaderParser mHeaderParser;
71-
const char * mImageFile = nullptr;
7272
static constexpr size_t kAlignmentBytes = 64;
7373
// Intermediate, word-aligned buffer for writing to the bootloader storage.
7474
// Bootloader storage API requires the buffer size to be a multiple of 4.

src/platform/silabs/efr32/BUILD.gn

+17-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,25 @@ static_library("efr32") {
7777
sources += [ "BLEManagerImpl.cpp" ]
7878
}
7979

80-
if (chip_enable_ota_requestor) {
80+
if (chip_enable_multi_ota_requestor) {
81+
sources += [
82+
"${silabs_platform_dir}/multi-ota/MultiOTAImageProcessorImpl.h",
83+
"${silabs_platform_dir}/multi-ota/MultiOTAImageProcessorImpl.cpp",
84+
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.h",
85+
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp",
86+
#"${silabs_platform_dir}/multi-ota/efr32/OTAFactoryDataProcessor.h",
87+
#"${silabs_platform_dir}/multi-ota/efr32/OTAFactoryDataProcessor.cpp",
88+
"${silabs_platform_dir}/multi-ota/efr32/OTAFirmwareProcessor.h",
89+
"${silabs_platform_dir}/multi-ota/efr32/OTAFirmwareProcessor.cpp",
90+
"${silabs_platform_dir}/multi-ota/efr32/OTAHooks.cpp",
91+
92+
]
93+
}
94+
else if (chip_enable_ota_requestor) {
8195
sources += [
8296
"${silabs_platform_dir}/OTAImageProcessorImpl.h",
83-
"OTAImageProcessorImpl.cpp",
97+
"${silabs_platform_dir}/efr32/OTAImageProcessorImpl.cpp",
98+
8499
]
85100
}
86101

src/platform/silabs/efr32/OTAImageProcessorImpl.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ extern "C" {
3333
/// No error, operation OK
3434
#define SL_BOOTLOADER_OK 0L
3535

36+
static chip::OTAImageProcessorImpl gImageProcessor;
37+
3638
namespace chip {
3739

3840
// Define static memebers
@@ -41,6 +43,15 @@ uint32_t OTAImageProcessorImpl::mWriteOffset
4143
uint16_t OTAImageProcessorImpl::writeBufOffset = 0;
4244
uint8_t OTAImageProcessorImpl::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 };
4345

46+
CHIP_ERROR OTAImageProcessorImpl::Init(OTADownloader * downloader)
47+
{
48+
ReturnErrorCodeIf(downloader == nullptr, CHIP_ERROR_INVALID_ARGUMENT);
49+
50+
gImageProcessor.SetOTADownloader(downloader);
51+
52+
return CHIP_NO_ERROR;
53+
}
54+
4455
CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
4556
{
4657
DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast<intptr_t>(this));
@@ -204,6 +215,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
204215
ChipLogProgress(SoftwareUpdate, "HandleApply: started");
205216

206217
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218+
// TODO: Make sure this call gets put in MultiOTAImageProcessorImpl::HandleApply
207219
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
208220
#if SL_BTLCTRL_MUX
209221
err = sl_wfx_host_pre_bootloader_spi_transfer();
@@ -271,6 +283,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context)
271283
imageProcessor->ReleaseBlock();
272284
}
273285

286+
// TODO: Put this in ProcessInternal for efr32 Application image Processor
274287
void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
275288
{
276289
uint32_t err = SL_BOOTLOADER_OK;
@@ -400,4 +413,9 @@ CHIP_ERROR OTAImageProcessorImpl::ReleaseBlock()
400413
return CHIP_NO_ERROR;
401414
}
402415

416+
OTAImageProcessorImpl & OTAImageProcessorImpl::GetDefaultInstance()
417+
{
418+
return gImageProcessor;
419+
}
420+
403421
} // namespace chip

src/platform/silabs/efr32/args.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ if (chip_crypto == "") {
3232
}
3333

3434
chip_device_platform = "efr32"
35-
3635
#Net work configuration OpenThread
3736
lwip_platform = "silabs"
3837
chip_mdns = "platform"
@@ -42,6 +41,7 @@ chip_system_config_use_open_thread_inet_endpoints = true
4241
chip_with_lwip = false
4342

4443
chip_build_tests = false
44+
chip_enable_multi_ota_requestor = false
4545

4646
# Transitional CommissionableDataProvider not used anymore
4747
# examples/platform/silabs/efr32/SilabsDeviceDataProvider is now used.

0 commit comments

Comments
 (0)