Skip to content

Commit 941bec0

Browse files
KishorSilabsjmartinez-silabs
authored andcommitted
Pull request project-chip#1454: Cherry-picks SOC DIC AWS OTA Changes from slc_1.2
Merge in WMN_TOOLS/matter from cherry-pick/feature/917_soc_aws_ota_feature_support to silabs Squashed commit of the following: commit a2d9296d5d7a9e58c218ba8d82ce161380cef90b Author: Thirupathi S <Thirupathi.S@silabs.com> Date: Tue Dec 5 12:23:28 2023 +0000 SOC DIC AWS OTA Changes
1 parent e07df29 commit 941bec0

File tree

3 files changed

+159
-8
lines changed

3 files changed

+159
-8
lines changed

third_party/silabs/aws_ota_sdk/demos/ota/common/src/pal.c

+157-6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,24 @@
3232
#include <libgen.h>
3333
#include <unistd.h>
3434
#include "silabs_utils.h"
35+
36+
#ifdef EFR32MG24 //For efr32 NCP combos
3537
#include "btl_interface.h"
3638
#include "em_bus.h" // For CORE_CRITICAL_SECTION
37-
3839
#if (defined(EFR32MG24) && defined(WF200_WIFI))
3940
#include "sl_wfx_host_api.h"
4041
#include "spi_multiplex.h"
42+
#endif // EFR32MG24 && WF200_WIFI
43+
#else
44+
#ifdef __cplusplus
45+
extern "C" {
4146
#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
4253

4354
#include "ota.h"
4455
#include "pal.h"
@@ -53,6 +64,15 @@
5364
*/
5465
#define OTA_PLATFORM_IMAGE_STATE_FILE "PlatformImageState.txt"
5566

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+
5676
/**
5777
* @brief Specify the OTA signature algorithm we support on this platform.
5878
*/
@@ -82,7 +102,8 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
82102

83103
static bool bl_init_done = false;
84104

85-
int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
105+
#ifdef EFR32MG24
106+
int16_t otaPal_WriteBlock_efr32( OtaFileContext_t * const C,
86107
uint32_t ulOffset,
87108
uint8_t * const pcData,
88109
uint32_t ulBlockSize )
@@ -112,8 +133,6 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
112133
SILABS_LOG("otaPal_WriteBlock bootloader Init Failed %d",err);
113134
return -1;
114135
}
115-
116-
SILABS_LOG("otaPal_WriteBlock mSlotId %d ulBlockSize %d kAlignmentBytes %d", mSlotId, ulBlockSize, kAlignmentBytes);
117136

118137
while (blockReadOffset < ulBlockSize)
119138
{
@@ -122,6 +141,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
122141
blockReadOffset++;
123142
if (writeBufOffset == kAlignmentBytes)
124143
{
144+
SILABS_LOG("packets mWriteOffset %d, blockReadOffset %d writeBufOffset %d", mWriteOffset, blockReadOffset, writeBufOffset);
125145
writeBufOffset = 0;
126146

127147
#if (defined(EFR32MG24) && defined(WF200_WIFI))
@@ -142,7 +162,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
142162
}
143163
else if ((blockReadOffset == ulBlockSize) && ulBlockSize!=1024)
144164
{
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);
146166
if (writeBufOffset != 0)
147167
{
148168
// Account for last bytes of the image not yet written to storage
@@ -176,8 +196,117 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
176196
return ( int16_t ) filerc;
177197
}
178198

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+
179306
/* 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 )
181310
{
182311
( void ) C;
183312

@@ -204,9 +333,31 @@ OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C )
204333

205334
// This reboots the device
206335
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)
336+
207337
return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
208338
}
209339

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+
210361
/* Set the final state of the last transferred (final) OTA file (or bundle).
211362
* On POSIX, the state of the OTA image is stored in PlatformImageState.txt. */
212363
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const C,

third_party/silabs/aws_ota_sdk/demos/ota/ota_demo_core_mqtt/demo_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/* Include header that defines log levels. */
3737
// #include "logging_levels.h"
3838

39-
#define OTA_TASK_STACK_SIZE (2*1024)
39+
#define OTA_TASK_STACK_SIZE (3*1024)
4040
#define OTA_TASK_PRIORITY 8
4141

4242
/* Logging configuration for the Demo. */

third_party/silabs/mqtt/stack/mqtt_opts.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C" {
5151
/**
5252
* Output ring-buffer size, must be able to fit largest outgoing publish message topic+payloads
5353
*/
54-
#define MQTT_OUTPUT_RINGBUF_SIZE 256
54+
#define MQTT_OUTPUT_RINGBUF_SIZE 512
5555

5656
/**
5757
* Number of bytes in receive buffer, must be at least the size of the longest incoming topic + 8

0 commit comments

Comments
 (0)