32
32
#include <libgen.h>
33
33
#include <unistd.h>
34
34
#include "silabs_utils.h"
35
+
36
+ #ifdef EFR32MG24 //For efr32 NCP combos
35
37
#include "btl_interface.h"
36
38
#include "em_bus.h" // For CORE_CRITICAL_SECTION
37
-
38
39
#if (defined(EFR32MG24 ) && defined(WF200_WIFI ))
39
40
#include "sl_wfx_host_api.h"
40
41
#include "spi_multiplex.h"
42
+ #endif // EFR32MG24 && WF200_WIFI
43
+ #else
44
+ #ifdef __cplusplus
45
+ extern "C" {
41
46
#endif
47
+ #include "sl_si91x_driver.h"
48
+ #include "sl_si91x_hal_soc_soft_reset.h"
49
+ #ifdef __cplusplus
50
+ }
51
+ #endif // __cplusplus
52
+ #endif // EFR32MG24
42
53
43
54
#include "ota.h"
44
55
#include "pal.h"
53
64
*/
54
65
#define OTA_PLATFORM_IMAGE_STATE_FILE "PlatformImageState.txt"
55
66
67
+ #ifdef SIWX_917
68
+ #define SL_STATUS_FW_UPDATE_DONE ((sl_status_t)0x10003)
69
+ #define SL_FWUP_RPS_HEADER 1
70
+ #define SL_FWUP_RPS_CONTENT 2
71
+
72
+ static uint8_t flag = SL_FWUP_RPS_HEADER ;
73
+ bool reset_flag = false;
74
+ #endif // Siwx917
75
+
56
76
/**
57
77
* @brief Specify the OTA signature algorithm we support on this platform.
58
78
*/
@@ -82,7 +102,8 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
82
102
83
103
static bool bl_init_done = false;
84
104
85
- int16_t otaPal_WriteBlock ( OtaFileContext_t * const C ,
105
+ #ifdef EFR32MG24
106
+ int16_t otaPal_WriteBlock_efr32 ( OtaFileContext_t * const C ,
86
107
uint32_t ulOffset ,
87
108
uint8_t * const pcData ,
88
109
uint32_t ulBlockSize )
@@ -112,8 +133,6 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
112
133
SILABS_LOG ("otaPal_WriteBlock bootloader Init Failed %d" ,err );
113
134
return -1 ;
114
135
}
115
-
116
- SILABS_LOG ("otaPal_WriteBlock mSlotId %d ulBlockSize %d kAlignmentBytes %d" , mSlotId , ulBlockSize , kAlignmentBytes );
117
136
118
137
while (blockReadOffset < ulBlockSize )
119
138
{
@@ -122,6 +141,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
122
141
blockReadOffset ++ ;
123
142
if (writeBufOffset == kAlignmentBytes )
124
143
{
144
+ SILABS_LOG ("packets mWriteOffset %d, blockReadOffset %d writeBufOffset %d" , mWriteOffset , blockReadOffset , writeBufOffset );
125
145
writeBufOffset = 0 ;
126
146
127
147
#if (defined(EFR32MG24 ) && defined(WF200_WIFI ))
@@ -142,7 +162,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
142
162
}
143
163
else if ((blockReadOffset == ulBlockSize ) && ulBlockSize != 1024 )
144
164
{
145
- SILABS_LOG ("while loop (blockReadOffset == ulBlockSize) mWriteOffset %d, blockReadOffset %d writeBufOffset %d" , mWriteOffset , blockReadOffset , writeBufOffset );
165
+ SILABS_LOG ("last packet mWriteOffset %d, blockReadOffset %d writeBufOffset %d" , mWriteOffset , blockReadOffset , writeBufOffset );
146
166
if (writeBufOffset != 0 )
147
167
{
148
168
// Account for last bytes of the image not yet written to storage
@@ -176,8 +196,117 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
176
196
return ( int16_t ) filerc ;
177
197
}
178
198
199
+ #else
200
+ int16_t otaPal_WriteBlock_siwx917 ( OtaFileContext_t * const C ,
201
+ uint32_t ulOffset ,
202
+ uint8_t * const pcData ,
203
+ uint32_t ulBlockSize )
204
+ {
205
+
206
+ int32_t status = 0 ;
207
+ int32_t filerc = 0 ;
208
+ uint32_t const kAlignmentBytes = 64 ;
209
+ uint8_t mSlotId ;
210
+ static uint32_t mWriteOffset ;
211
+ uint16_t writeBufOffset = 0 ;
212
+
213
+ static uint64_t downloadedBytes ;
214
+
215
+ uint32_t blockReadOffset = 0 ;
216
+ uint8_t writeBuffer [64 ] = { 0 };
217
+
218
+ mSlotId = 0 ; // Single slot until we support multiple images
219
+ downloadedBytes = 0 ;
220
+
221
+ while (blockReadOffset < ulBlockSize )
222
+ {
223
+ writeBuffer [writeBufOffset ] = * (pcData + blockReadOffset );
224
+ writeBufOffset ++ ;
225
+ blockReadOffset ++ ;
226
+ if (writeBufOffset == kAlignmentBytes )
227
+ {
228
+ SILABS_LOG ("packets mWriteOffset %d, blockReadOffset %d writeBufOffset %d" , mWriteOffset , blockReadOffset , writeBufOffset );
229
+ writeBufOffset = 0 ;
230
+ if (flag == SL_FWUP_RPS_HEADER )
231
+ {
232
+ // Send RPS header which is received as first chunk
233
+ status = sl_si91x_fwup_start (writeBuffer );
234
+
235
+ // Send RPS content
236
+ status = sl_si91x_fwup_load (writeBuffer , kAlignmentBytes );
237
+
238
+ flag = SL_FWUP_RPS_CONTENT ;
239
+ }
240
+ else if (flag == SL_FWUP_RPS_CONTENT )
241
+ {
242
+ // Send RPS content
243
+ status = sl_si91x_fwup_load (writeBuffer , kAlignmentBytes );
244
+ if (status != SL_STATUS_OK ) {
245
+ if (status == SL_STATUS_FW_UPDATE_DONE ) {
246
+ reset_flag = true;
247
+ }
248
+ }
249
+ else
250
+ {
251
+ SILABS_LOG ("ERROR: In HandleProcessBlock for middle chunk sl_si91x_fwup_load error %ld" , status );
252
+ return -1 ;
253
+ }
254
+ }
255
+ mWriteOffset += kAlignmentBytes ;
256
+ downloadedBytes += kAlignmentBytes ;
257
+ filerc = ( int32_t ) ulBlockSize ;
258
+ }
259
+ else if ((blockReadOffset == ulBlockSize ) && ulBlockSize != 1024 )
260
+ {
261
+ SILABS_LOG ("last packet mWriteOffset %d, blockReadOffset %d writeBufOffset %d" , mWriteOffset , blockReadOffset , writeBufOffset );
262
+ if (writeBufOffset != 0 )
263
+ {
264
+ // Account for last bytes of the image not yet written to storage
265
+ downloadedBytes += writeBufOffset ;
266
+
267
+ if (flag == SL_FWUP_RPS_CONTENT )
268
+ {
269
+ // Send RPS content
270
+ status = sl_si91x_fwup_load (writeBuffer , writeBufOffset );
271
+ SILABS_LOG ("status: 0x%lX" , status );
272
+ if (status != SL_STATUS_OK ) {
273
+ if (status == SL_STATUS_FW_UPDATE_DONE ) {
274
+ reset_flag = true;
275
+ }
276
+ }
277
+ else
278
+ {
279
+ SILABS_LOG ("ERROR: In HandleProcessBlock for last chunk sl_si91x_fwup_load error %ld" , status );
280
+ return -1 ;
281
+ }
282
+ }
283
+ }
284
+ mWriteOffset += writeBufOffset ;
285
+ filerc = ( int32_t ) ulBlockSize ;
286
+ }
287
+ }
288
+ filerc = ( int32_t ) ulBlockSize ;
289
+ return ( int16_t ) filerc ;
290
+ }
291
+ #endif
292
+
293
+ int16_t otaPal_WriteBlock ( OtaFileContext_t * const C ,
294
+ uint32_t ulOffset ,
295
+ uint8_t * const pcData ,
296
+ uint32_t ulBlockSize )
297
+ {
298
+ #ifdef EFR32MG24
299
+ return otaPal_WriteBlock_efr32 ( C ,ulOffset ,pcData ,ulBlockSize );
300
+ #else
301
+ return otaPal_WriteBlock_siwx917 ( C ,ulOffset ,pcData ,ulBlockSize );
302
+ #endif
303
+ }
304
+
305
+
179
306
/* Return no error. POSIX implementation simply does nothing on activate. */
180
- OtaPalStatus_t otaPal_ActivateNewImage ( OtaFileContext_t * const C )
307
+
308
+ #ifdef EFR32MG24
309
+ OtaPalStatus_t otaPal_ActivateNewImage_efr32 ( OtaFileContext_t * const C )
181
310
{
182
311
( void ) C ;
183
312
@@ -204,9 +333,31 @@ OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C )
204
333
205
334
// This reboots the device
206
335
CORE_CRITICAL_SECTION (bootloader_rebootAndInstall ();)
336
+
207
337
return OTA_PAL_COMBINE_ERR ( OtaPalSuccess , 0 );
208
338
}
209
339
340
+ #else
341
+ OtaPalStatus_t otaPal_ActivateNewImage_siwx917 ( OtaFileContext_t * const C )
342
+ {
343
+ ( void ) C ;
344
+ if (reset_flag ){
345
+ SILABS_LOG ("M4/TA/combined image update completed - reset started" );
346
+ sl_si91x_soc_soft_reset ();
347
+ }
348
+ return OTA_PAL_COMBINE_ERR ( OtaPalSuccess , 0 );
349
+ }
350
+ #endif
351
+
352
+ OtaPalStatus_t otaPal_ActivateNewImage ( OtaFileContext_t * const C )
353
+ {
354
+ #ifdef EFR32MG24
355
+ return otaPal_ActivateNewImage_efr32 ( C );
356
+ #else
357
+ return otaPal_ActivateNewImage_siwx917 ( C );
358
+ #endif
359
+ }
360
+
210
361
/* Set the final state of the last transferred (final) OTA file (or bundle).
211
362
* On POSIX, the state of the OTA image is stored in PlatformImageState.txt. */
212
363
OtaPalStatus_t otaPal_SetPlatformImageState ( OtaFileContext_t * const C ,
0 commit comments