Skip to content

Commit 0ada603

Browse files
[nrf toup][nrfconnect] Added support for Matter OTA using SUIT
Modified the OTAImageProcessorImpl to use dfu target multi image only in case of using the mcuboot bootloader and to use dfu target in case of using suit. Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
1 parent c0df90b commit 0ada603

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

config/nrfconnect/chip-module/Kconfig.defaults

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ config BOOT_IMAGE_ACCESS_HOOKS
214214
config UPDATEABLE_IMAGE_NUMBER
215215
default 3 if NRF_WIFI_PATCHES_EXT_FLASH_STORE
216216
default 2 if SOC_SERIES_NRF53X
217+
default 1 if SUIT # SUIT does not support the multi-image dfu
217218

218219
config DFU_MULTI_IMAGE_MAX_IMAGE_COUNT
219220
default 3 if NRF_WIFI_PATCHES_EXT_FLASH_STORE

src/platform/nrfconnect/OTAImageProcessorImpl.cpp

+44-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@
3333

3434
#include "DFUSync.h"
3535

36-
#include <dfu/dfu_multi_image.h>
3736
#include <dfu/dfu_target.h>
37+
38+
#ifdef CONFIG_SUIT
39+
#include <dfu/dfu_target_suit.h>
40+
#else
41+
#include <dfu/dfu_multi_image.h>
3842
#include <dfu/dfu_target_mcuboot.h>
3943
#include <zephyr/dfu/mcuboot.h>
44+
#endif
45+
4046
#include <zephyr/logging/log.h>
4147
#include <zephyr/pm/device.h>
4248

@@ -90,6 +96,7 @@ CHIP_ERROR OTAImageProcessorImpl::PrepareDownloadImpl()
9096
{
9197
mHeaderParser.Init();
9298
mParams = {};
99+
#ifndef CONFIG_SUIT
93100
ReturnErrorOnFailure(System::MapErrorZephyr(dfu_target_mcuboot_set_buf(mBuffer, sizeof(mBuffer))));
94101
ReturnErrorOnFailure(System::MapErrorZephyr(dfu_multi_image_init(mBuffer, sizeof(mBuffer))));
95102

@@ -103,6 +110,7 @@ CHIP_ERROR OTAImageProcessorImpl::PrepareDownloadImpl()
103110

104111
ReturnErrorOnFailure(System::MapErrorZephyr(dfu_multi_image_register_writer(&writer)));
105112
};
113+
#endif
106114

107115
#ifdef CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE
108116
dfu_image_writer cdWriter;
@@ -128,12 +136,25 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
128136
{
129137
PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadComplete);
130138
DFUSync::GetInstance().Free(mDfuSyncMutexId);
139+
140+
#ifdef CONFIG_SUIT
141+
mDfuTargetSuitInitialized = false;
142+
return System::MapErrorZephyr(dfu_target_done(true));
143+
#else
131144
return System::MapErrorZephyr(dfu_multi_image_done(true));
145+
#endif
132146
}
133147

134148
CHIP_ERROR OTAImageProcessorImpl::Abort()
135149
{
136-
CHIP_ERROR error = System::MapErrorZephyr(dfu_multi_image_done(false));
150+
CHIP_ERROR error;
151+
152+
#ifdef CONFIG_SUIT
153+
error = System::MapErrorZephyr(dfu_target_reset());
154+
mDfuTargetSuitInitialized = false;
155+
#else
156+
error = System::MapErrorZephyr(dfu_multi_image_done(false));
157+
#endif
137158

138159
DFUSync::GetInstance().Free(mDfuSyncMutexId);
139160
TriggerFlashAction(ExternalFlashManager::Action::SLEEP);
@@ -145,6 +166,11 @@ CHIP_ERROR OTAImageProcessorImpl::Abort()
145166
CHIP_ERROR OTAImageProcessorImpl::Apply()
146167
{
147168
PostOTAStateChangeEvent(DeviceLayer::kOtaApplyInProgress);
169+
170+
#ifdef CONFIG_SUIT
171+
mDfuTargetSuitInitialized = false;
172+
#endif
173+
148174
// Schedule update of all images
149175
int err = dfu_target_schedule_update(-1);
150176

@@ -178,6 +204,16 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock)
178204

179205
CHIP_ERROR error = ProcessHeader(aBlock);
180206

207+
#ifdef CONFIG_SUIT
208+
if (!mDfuTargetSuitInitialized && error == CHIP_NO_ERROR)
209+
{
210+
ReturnErrorOnFailure(System::MapErrorZephyr(dfu_target_suit_set_buf(mBuffer, sizeof(mBuffer))));
211+
ReturnErrorOnFailure(System::MapErrorZephyr(
212+
dfu_target_init(DFU_TARGET_IMAGE_TYPE_SUIT, 0, static_cast<size_t>(mParams.totalFileBytes), nullptr)));
213+
mDfuTargetSuitInitialized = true;
214+
}
215+
#endif
216+
181217
if (error == CHIP_NO_ERROR)
182218
{
183219
// DFU target library buffers data internally, so do not clone the block data.
@@ -187,9 +223,13 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock)
187223
}
188224
else
189225
{
190-
error = System::MapErrorZephyr(
191-
dfu_multi_image_write(static_cast<size_t>(mParams.downloadedBytes), aBlock.data(), aBlock.size()));
226+
#ifdef CONFIG_SUIT
227+
int err = dfu_target_write(aBlock.data(), aBlock.size());
228+
#else
229+
int err = dfu_multi_image_write(static_cast<size_t>(mParams.downloadedBytes), aBlock.data(), aBlock.size());
192230
mParams.downloadedBytes += aBlock.size();
231+
#endif
232+
error = System::MapErrorZephyr(err);
193233
}
194234
}
195235

src/platform/nrfconnect/OTAImageProcessorImpl.h

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
5858
private:
5959
bool mImageConfirmed = false;
6060
uint32_t mDfuSyncMutexId;
61+
62+
#ifdef CONFIG_SUIT
63+
bool mDfuTargetSuitInitialized = false;
64+
#endif
6165
};
6266

6367
} // namespace DeviceLayer

0 commit comments

Comments
 (0)