@@ -30,6 +30,20 @@ extern "C" {
30
30
31
31
#include < platform/silabs/SilabsConfig.h>
32
32
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
+
33
47
// / No error, operation OK
34
48
#define SL_BOOTLOADER_OK 0L
35
49
@@ -144,7 +158,15 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
144
158
145
159
ChipLogProgress (SoftwareUpdate, " HandlePrepareDownload: started" );
146
160
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
+
148
170
mSlotId = 0 ; // Single slot until we support multiple images
149
171
writeBufOffset = 0 ;
150
172
mWriteOffset = 0 ;
@@ -186,7 +208,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
186
208
return ;
187
209
}
188
210
#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
+
190
213
#if SL_BTLCTRL_MUX
191
214
err = sl_wfx_host_post_bootloader_spi_transfer ();
192
215
if (err != SL_STATUS_OK)
@@ -208,11 +231,27 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
208
231
ChipLogProgress (SoftwareUpdate, " OTA image downloaded successfully" );
209
232
}
210
233
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
+
211
250
void OTAImageProcessorImpl::HandleApply (intptr_t context)
212
251
{
213
252
uint32_t err = SL_BOOTLOADER_OK;
214
253
215
- ChipLogProgress (SoftwareUpdate, " HandleApply: started " );
254
+ ChipLogProgress (SoftwareUpdate, " HandleApply: verifying image " );
216
255
217
256
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218
257
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl ().ForceKeyMapSave ();
@@ -224,7 +263,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
224
263
return ;
225
264
}
226
265
#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 ();
228
273
if (err != SL_BOOTLOADER_OK)
229
274
{
230
275
ChipLogError (SoftwareUpdate, " bootloader_verifyImage() error: %ld" , err);
@@ -235,13 +280,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
235
280
if (err != SL_STATUS_OK)
236
281
{
237
282
ChipLogError (SoftwareUpdate, " sl_wfx_host_post_bootloader_spi_transfer() error: %ld" , err);
238
- return ;
239
283
}
240
284
#endif // SL_BTLCTRL_MUX
241
285
return ;
242
286
}
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 ();
245
291
if (err != SL_BOOTLOADER_OK)
246
292
{
247
293
ChipLogError (SoftwareUpdate, " bootloader_setImageToBootload() error: %ld" , err);
@@ -252,7 +298,6 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
252
298
if (err != SL_STATUS_OK)
253
299
{
254
300
ChipLogError (SoftwareUpdate, " sl_wfx_host_post_bootloader_spi_transfer() error: %ld" , err);
255
- return ;
256
301
}
257
302
#endif // SL_BTLCTRL_MUX
258
303
return ;
@@ -266,8 +311,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
266
311
return ;
267
312
}
268
313
#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 ();
269
320
// This reboots the device
270
- CORE_CRITICAL_SECTION (bootloader_rebootAndInstall ();)
321
+ WRAP_BL_DFU_CALL (bootloader_rebootAndInstall ())
322
+ UnlockRadioProcessing (); // Unneccessay but for good measure
271
323
}
272
324
273
325
void OTAImageProcessorImpl::HandleAbort (intptr_t context)
@@ -326,7 +378,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
326
378
return ;
327
379
}
328
380
#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
+
330
383
#if SL_BTLCTRL_MUX
331
384
err = sl_wfx_host_post_bootloader_spi_transfer ();
332
385
if (err != SL_STATUS_OK)
0 commit comments