Skip to content

Commit 900b9d8

Browse files
authored
Merge branch 'master' into camera-webrtc-server
2 parents 349dbbe + a5ebda6 commit 900b9d8

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

examples/platform/silabs/SoftwareFaultReports.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "SoftwareFaultReports.h"
20+
#include "FreeRTOSConfig.h"
2021
#include "silabs_utils.h"
2122
#include <app/clusters/software-diagnostics-server/software-diagnostics-server.h>
2223
#include <app/util/attribute-storage.h>

src/platform/silabs/CHIPDevicePlatformConfig.h

-4
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@
144144
#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
145145

146146
#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
147-
#if defined(EFR32MG21)
148-
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (2 * 1024)
149-
#else
150147
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (8 * 1024)
151-
#endif
152148
#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
153149

154150
#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

+62-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ extern "C" {
3030
#include "sl_core.h"
3131
}
3232

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

@@ -144,7 +160,12 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
144160

145161
ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started");
146162

147-
CORE_CRITICAL_SECTION(bootloader_init();)
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+
148169
mSlotId = 0; // Single slot until we support multiple images
149170
writeBufOffset = 0;
150171
mWriteOffset = 0;
@@ -186,7 +207,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
186207
return;
187208
}
188209
#endif // SL_BTLCTRL_MUX
189-
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);)
210+
WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes))
211+
190212
#if SL_BTLCTRL_MUX
191213
err = sl_wfx_host_post_bootloader_spi_transfer();
192214
if (err != SL_STATUS_OK)
@@ -208,11 +230,27 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
208230
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
209231
}
210232

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

215-
ChipLogProgress(SoftwareUpdate, "HandleApply: started");
253+
ChipLogProgress(SoftwareUpdate, "HandleApply: verifying image");
216254

217255
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218256
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
@@ -224,11 +262,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
224262
return;
225263
}
226264
#endif // SL_BTLCTRL_MUX
227-
#if defined(SL_TRUSTZONE_NONSECURE)
228-
CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId);)
229-
#else
230-
CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);)
231-
#endif
265+
266+
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
267+
osDelay(100); // sl-temp: delay for uart print before verifyImage
268+
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
269+
LockRadioProcessing();
270+
WRAP_BL_DFU_CALL(err = bootloader_verifyImage(mSlotId, NULL))
271+
UnlockRadioProcessing();
232272
if (err != SL_BOOTLOADER_OK)
233273
{
234274
ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err);
@@ -239,13 +279,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
239279
if (err != SL_STATUS_OK)
240280
{
241281
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
242-
return;
243282
}
244283
#endif // SL_BTLCTRL_MUX
245284
return;
246285
}
247-
248-
CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);)
286+
ChipLogProgress(SoftwareUpdate, "Image verified, Set image to bootload");
287+
LockRadioProcessing();
288+
WRAP_BL_DFU_CALL(err = bootloader_setImageToBootload(mSlotId))
289+
UnlockRadioProcessing();
249290
if (err != SL_BOOTLOADER_OK)
250291
{
251292
ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err);
@@ -256,7 +297,6 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
256297
if (err != SL_STATUS_OK)
257298
{
258299
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
259-
return;
260300
}
261301
#endif // SL_BTLCTRL_MUX
262302
return;
@@ -270,8 +310,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
270310
return;
271311
}
272312
#endif // SL_BTLCTRL_MUX
313+
314+
ChipLogProgress(SoftwareUpdate, "Reboot and install new image...");
315+
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
316+
osDelay(100); // sl-temp: delay for uart print before reboot
317+
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
318+
LockRadioProcessing();
273319
// This reboots the device
274-
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)
320+
WRAP_BL_DFU_CALL(bootloader_rebootAndInstall())
321+
UnlockRadioProcessing(); // Unneccessay but for good measure
275322
}
276323

277324
void OTAImageProcessorImpl::HandleAbort(intptr_t context)
@@ -330,7 +377,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
330377
return;
331378
}
332379
#endif // SL_BTLCTRL_MUX
333-
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);)
380+
WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes))
381+
334382
#if SL_BTLCTRL_MUX
335383
err = sl_wfx_host_post_bootloader_spi_transfer();
336384
if (err != SL_STATUS_OK)

0 commit comments

Comments
 (0)