Skip to content

Commit 736240f

Browse files
[SL-UP] Add OTA Support for series3 (#94)
1 parent cb310bb commit 736240f

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-14
lines changed

src/platform/silabs/CHIPDevicePlatformConfig.h

-4
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@
138138
#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
139139

140140
#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
141-
#if defined(EFR32MG21)
142-
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (2 * 1024)
143-
#else
144141
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (8 * 1024)
145-
#endif
146142
#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
147143

148144
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0

src/platform/silabs/OTAImageProcessorImpl.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
5050
static void HandleApply(intptr_t context);
5151
static void HandleAbort(intptr_t context);
5252
static void HandleProcessBlock(intptr_t context);
53+
static void LockRadioProcessing();
54+
static void UnlockRadioProcessing();
5355
CHIP_ERROR ProcessHeader(ByteSpan & block);
5456

5557
/**

src/platform/silabs/efr32/OTAImageProcessorImpl.cpp

+63-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ extern "C" {
3030

3131
#include <platform/silabs/SilabsConfig.h>
3232

33+
#ifdef _SILICON_LABS_32B_SERIES_2
34+
// Series 2 bootloader_ api calls must be called from a critical section context for thread safeness
35+
#define WRAP_BL_DFU_CALL(code) \
36+
{ \
37+
CORE_CRITICAL_SECTION(code;) \
38+
}
39+
#else
40+
// series 3 bootloader_ calls uses rtos mutex for thread safety. Cannot be called within a critical section
41+
#define WRAP_BL_DFU_CALL(code) \
42+
{ \
43+
code; \
44+
}
45+
#endif
46+
3347
/// No error, operation OK
3448
#define SL_BOOTLOADER_OK 0L
3549

@@ -144,7 +158,15 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
144158

145159
ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started");
146160

147-
CORE_CRITICAL_SECTION(bootloader_init();)
161+
#ifdef _SILICON_LABS_32B_SERIES_2
162+
// TODO sl-temp: bootloader_init is called previously sl_platform_init(). Recalling it for series3 causes a crash.
163+
WRAP_BL_DFU_CALL(err = bootloader_init())
164+
if (err != SL_BOOTLOADER_OK)
165+
{
166+
ChipLogProgress(SoftwareUpdate, "bootloader_init Failed error: %ld", err);
167+
}
168+
#endif
169+
148170
mSlotId = 0; // Single slot until we support multiple images
149171
writeBufOffset = 0;
150172
mWriteOffset = 0;
@@ -186,7 +208,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
186208
return;
187209
}
188210
#endif // SL_BTLCTRL_MUX
189-
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);)
211+
WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes))
212+
190213
#if SL_BTLCTRL_MUX
191214
err = sl_wfx_host_post_bootloader_spi_transfer();
192215
if (err != SL_STATUS_OK)
@@ -208,11 +231,27 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
208231
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
209232
}
210233

234+
// TODO: SE access is not thread safe. It assert if other tasks accesses it during bootloader_verifyImage or
235+
// bootloader_setImageToBootload steps - MATTER-4155 - PLATFORM_HYD-3235
236+
void OTAImageProcessorImpl::LockRadioProcessing()
237+
{
238+
#if !SL_WIFI
239+
DeviceLayer::ThreadStackMgr().LockThreadStack();
240+
#endif // SL_WIFI
241+
}
242+
243+
void OTAImageProcessorImpl::UnlockRadioProcessing()
244+
{
245+
#if !SL_WIFI
246+
DeviceLayer::ThreadStackMgr().UnlockThreadStack();
247+
#endif // SL_WIFI
248+
}
249+
211250
void OTAImageProcessorImpl::HandleApply(intptr_t context)
212251
{
213252
uint32_t err = SL_BOOTLOADER_OK;
214253

215-
ChipLogProgress(SoftwareUpdate, "HandleApply: started");
254+
ChipLogProgress(SoftwareUpdate, "HandleApply: verifying image");
216255

217256
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218257
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
@@ -224,7 +263,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
224263
return;
225264
}
226265
#endif // SL_BTLCTRL_MUX
227-
CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);)
266+
267+
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
268+
osDelay(100); // sl-temp: delay for uart print before verifyImage
269+
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
270+
LockRadioProcessing();
271+
WRAP_BL_DFU_CALL(err = bootloader_verifyImage(mSlotId, NULL))
272+
UnlockRadioProcessing();
228273
if (err != SL_BOOTLOADER_OK)
229274
{
230275
ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err);
@@ -235,13 +280,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
235280
if (err != SL_STATUS_OK)
236281
{
237282
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
238-
return;
239283
}
240284
#endif // SL_BTLCTRL_MUX
241285
return;
242286
}
243-
244-
CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);)
287+
ChipLogProgress(SoftwareUpdate, "Image verified, Set image to bootload");
288+
LockRadioProcessing();
289+
WRAP_BL_DFU_CALL(err = bootloader_setImageToBootload(mSlotId))
290+
UnlockRadioProcessing();
245291
if (err != SL_BOOTLOADER_OK)
246292
{
247293
ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err);
@@ -252,7 +298,6 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
252298
if (err != SL_STATUS_OK)
253299
{
254300
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
255-
return;
256301
}
257302
#endif // SL_BTLCTRL_MUX
258303
return;
@@ -266,8 +311,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
266311
return;
267312
}
268313
#endif // SL_BTLCTRL_MUX
314+
315+
ChipLogProgress(SoftwareUpdate, "Reboot and install new image...");
316+
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
317+
osDelay(100); // sl-temp: delay for uart print before reboot
318+
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
319+
LockRadioProcessing();
269320
// This reboots the device
270-
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)
321+
WRAP_BL_DFU_CALL(bootloader_rebootAndInstall())
322+
UnlockRadioProcessing(); // Unneccessay but for good measure
271323
}
272324

273325
void OTAImageProcessorImpl::HandleAbort(intptr_t context)
@@ -326,7 +378,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
326378
return;
327379
}
328380
#endif // SL_BTLCTRL_MUX
329-
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);)
381+
WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes))
382+
330383
#if SL_BTLCTRL_MUX
331384
err = sl_wfx_host_post_bootloader_spi_transfer();
332385
if (err != SL_STATUS_OK)

0 commit comments

Comments
 (0)