@@ -30,6 +30,22 @@ extern "C" {
30
30
#include " sl_core.h"
31
31
}
32
32
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
+
33
49
// / No error, operation OK
34
50
#define SL_BOOTLOADER_OK 0L
35
51
@@ -144,7 +160,12 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
144
160
145
161
ChipLogProgress (SoftwareUpdate, " HandlePrepareDownload: started" );
146
162
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
+
148
169
mSlotId = 0 ; // Single slot until we support multiple images
149
170
writeBufOffset = 0 ;
150
171
mWriteOffset = 0 ;
@@ -186,7 +207,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
186
207
return ;
187
208
}
188
209
#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
+
190
212
#if SL_BTLCTRL_MUX
191
213
err = sl_wfx_host_post_bootloader_spi_transfer ();
192
214
if (err != SL_STATUS_OK)
@@ -208,11 +230,27 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
208
230
ChipLogProgress (SoftwareUpdate, " OTA image downloaded successfully" );
209
231
}
210
232
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
+
211
249
void OTAImageProcessorImpl::HandleApply (intptr_t context)
212
250
{
213
251
uint32_t err = SL_BOOTLOADER_OK;
214
252
215
- ChipLogProgress (SoftwareUpdate, " HandleApply: started " );
253
+ ChipLogProgress (SoftwareUpdate, " HandleApply: verifying image " );
216
254
217
255
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218
256
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl ().ForceKeyMapSave ();
@@ -224,11 +262,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
224
262
return ;
225
263
}
226
264
#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 ();
232
272
if (err != SL_BOOTLOADER_OK)
233
273
{
234
274
ChipLogError (SoftwareUpdate, " bootloader_verifyImage() error: %ld" , err);
@@ -239,13 +279,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
239
279
if (err != SL_STATUS_OK)
240
280
{
241
281
ChipLogError (SoftwareUpdate, " sl_wfx_host_post_bootloader_spi_transfer() error: %ld" , err);
242
- return ;
243
282
}
244
283
#endif // SL_BTLCTRL_MUX
245
284
return ;
246
285
}
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 ();
249
290
if (err != SL_BOOTLOADER_OK)
250
291
{
251
292
ChipLogError (SoftwareUpdate, " bootloader_setImageToBootload() error: %ld" , err);
@@ -256,7 +297,6 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
256
297
if (err != SL_STATUS_OK)
257
298
{
258
299
ChipLogError (SoftwareUpdate, " sl_wfx_host_post_bootloader_spi_transfer() error: %ld" , err);
259
- return ;
260
300
}
261
301
#endif // SL_BTLCTRL_MUX
262
302
return ;
@@ -270,8 +310,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
270
310
return ;
271
311
}
272
312
#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 ();
273
319
// This reboots the device
274
- CORE_CRITICAL_SECTION (bootloader_rebootAndInstall ();)
320
+ WRAP_BL_DFU_CALL (bootloader_rebootAndInstall ())
321
+ UnlockRadioProcessing (); // Unneccessay but for good measure
275
322
}
276
323
277
324
void OTAImageProcessorImpl::HandleAbort (intptr_t context)
@@ -330,7 +377,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
330
377
return ;
331
378
}
332
379
#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
+
334
382
#if SL_BTLCTRL_MUX
335
383
err = sl_wfx_host_post_bootloader_spi_transfer ();
336
384
if (err != SL_STATUS_OK)
0 commit comments