Skip to content

Commit

Permalink
Pull request project-chip#1454: Cherry-picks SOC DIC AWS OTA Changes …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
Date:   Tue Dec 5 12:23:28 2023 +0000

    SOC DIC AWS OTA Changes
  • Loading branch information
KishorSilabs authored and jmartinez-silabs committed Jan 9, 2024
1 parent bc883aa commit 3e4fd52
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 8 deletions.
163 changes: 157 additions & 6 deletions third_party/silabs/aws_ota_sdk/demos/ota/common/src/pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,24 @@
#include <libgen.h>
#include <unistd.h>
#include "silabs_utils.h"

#ifdef EFR32MG24 //For efr32 NCP combos
#include "btl_interface.h"
#include "em_bus.h" // For CORE_CRITICAL_SECTION

#if (defined(EFR32MG24) && defined(WF200_WIFI))
#include "sl_wfx_host_api.h"
#include "spi_multiplex.h"
#endif // EFR32MG24 && WF200_WIFI
#else
#ifdef __cplusplus
extern "C" {
#endif
#include "sl_si91x_driver.h"
#include "sl_si91x_hal_soc_soft_reset.h"
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // EFR32MG24

#include "ota.h"
#include "pal.h"
Expand All @@ -53,6 +64,15 @@
*/
#define OTA_PLATFORM_IMAGE_STATE_FILE "PlatformImageState.txt"

#ifdef SIWX_917
#define SL_STATUS_FW_UPDATE_DONE ((sl_status_t)0x10003)
#define SL_FWUP_RPS_HEADER 1
#define SL_FWUP_RPS_CONTENT 2

static uint8_t flag = SL_FWUP_RPS_HEADER;
bool reset_flag = false;
#endif // Siwx917

/**
* @brief Specify the OTA signature algorithm we support on this platform.
*/
Expand Down Expand Up @@ -82,7 +102,8 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )

static bool bl_init_done = false;

int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
#ifdef EFR32MG24
int16_t otaPal_WriteBlock_efr32( OtaFileContext_t * const C,
uint32_t ulOffset,
uint8_t * const pcData,
uint32_t ulBlockSize )
Expand Down Expand Up @@ -112,8 +133,6 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
SILABS_LOG("otaPal_WriteBlock bootloader Init Failed %d",err);
return -1;
}

SILABS_LOG("otaPal_WriteBlock mSlotId %d ulBlockSize %d kAlignmentBytes %d", mSlotId, ulBlockSize, kAlignmentBytes);

while (blockReadOffset < ulBlockSize)
{
Expand All @@ -122,6 +141,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
blockReadOffset++;
if (writeBufOffset == kAlignmentBytes)
{
SILABS_LOG("packets mWriteOffset %d, blockReadOffset %d writeBufOffset %d", mWriteOffset, blockReadOffset, writeBufOffset);
writeBufOffset = 0;

#if (defined(EFR32MG24) && defined(WF200_WIFI))
Expand All @@ -142,7 +162,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
}
else if ((blockReadOffset == ulBlockSize) && ulBlockSize!=1024)
{
SILABS_LOG("while loop (blockReadOffset == ulBlockSize) mWriteOffset %d, blockReadOffset %d writeBufOffset %d", mWriteOffset, blockReadOffset, writeBufOffset);
SILABS_LOG("last packet mWriteOffset %d, blockReadOffset %d writeBufOffset %d", mWriteOffset, blockReadOffset, writeBufOffset);
if (writeBufOffset != 0)
{
// Account for last bytes of the image not yet written to storage
Expand Down Expand Up @@ -176,8 +196,117 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
return ( int16_t ) filerc;
}

#else
int16_t otaPal_WriteBlock_siwx917( OtaFileContext_t * const C,
uint32_t ulOffset,
uint8_t * const pcData,
uint32_t ulBlockSize )
{

int32_t status = 0;
int32_t filerc = 0;
uint32_t const kAlignmentBytes = 64;
uint8_t mSlotId;
static uint32_t mWriteOffset;
uint16_t writeBufOffset = 0;

static uint64_t downloadedBytes;

uint32_t blockReadOffset = 0;
uint8_t writeBuffer[64] = { 0 };

mSlotId = 0; // Single slot until we support multiple images
downloadedBytes = 0;

while (blockReadOffset < ulBlockSize)
{
writeBuffer[writeBufOffset] = *(pcData + blockReadOffset);
writeBufOffset++;
blockReadOffset++;
if (writeBufOffset == kAlignmentBytes)
{
SILABS_LOG("packets mWriteOffset %d, blockReadOffset %d writeBufOffset %d", mWriteOffset, blockReadOffset, writeBufOffset);
writeBufOffset = 0;
if(flag == SL_FWUP_RPS_HEADER)
{
// Send RPS header which is received as first chunk
status = sl_si91x_fwup_start(writeBuffer);

// Send RPS content
status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes);

flag = SL_FWUP_RPS_CONTENT;
}
else if(flag == SL_FWUP_RPS_CONTENT)
{
// Send RPS content
status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes);
if (status != SL_STATUS_OK) {
if (status == SL_STATUS_FW_UPDATE_DONE) {
reset_flag = true;
}
}
else
{
SILABS_LOG("ERROR: In HandleProcessBlock for middle chunk sl_si91x_fwup_load error %ld", status);
return -1;
}
}
mWriteOffset += kAlignmentBytes;
downloadedBytes += kAlignmentBytes;
filerc = ( int32_t ) ulBlockSize;
}
else if ((blockReadOffset == ulBlockSize) && ulBlockSize!=1024)
{
SILABS_LOG("last packet mWriteOffset %d, blockReadOffset %d writeBufOffset %d", mWriteOffset, blockReadOffset, writeBufOffset);
if (writeBufOffset != 0)
{
// Account for last bytes of the image not yet written to storage
downloadedBytes += writeBufOffset;

if(flag == SL_FWUP_RPS_CONTENT)
{
// Send RPS content
status = sl_si91x_fwup_load(writeBuffer, writeBufOffset);
SILABS_LOG("status: 0x%lX", status);
if (status != SL_STATUS_OK) {
if (status == SL_STATUS_FW_UPDATE_DONE) {
reset_flag = true;
}
}
else
{
SILABS_LOG("ERROR: In HandleProcessBlock for last chunk sl_si91x_fwup_load error %ld", status);
return -1;
}
}
}
mWriteOffset += writeBufOffset;
filerc = ( int32_t ) ulBlockSize;
}
}
filerc = ( int32_t ) ulBlockSize;
return ( int16_t ) filerc;
}
#endif

int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
uint32_t ulOffset,
uint8_t * const pcData,
uint32_t ulBlockSize )
{
#ifdef EFR32MG24
return otaPal_WriteBlock_efr32( C,ulOffset,pcData,ulBlockSize );
#else
return otaPal_WriteBlock_siwx917( C,ulOffset,pcData,ulBlockSize );
#endif
}


/* Return no error. POSIX implementation simply does nothing on activate. */
OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C )

#ifdef EFR32MG24
OtaPalStatus_t otaPal_ActivateNewImage_efr32( OtaFileContext_t * const C )
{
( void ) C;

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

// This reboots the device
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)

return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
}

#else
OtaPalStatus_t otaPal_ActivateNewImage_siwx917( OtaFileContext_t * const C )
{
( void ) C;
if(reset_flag){
SILABS_LOG("M4/TA/combined image update completed - reset started");
sl_si91x_soc_soft_reset();
}
return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
}
#endif

OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C )
{
#ifdef EFR32MG24
return otaPal_ActivateNewImage_efr32( C );
#else
return otaPal_ActivateNewImage_siwx917( C );
#endif
}

/* Set the final state of the last transferred (final) OTA file (or bundle).
* On POSIX, the state of the OTA image is stored in PlatformImageState.txt. */
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const C,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/* Include header that defines log levels. */
// #include "logging_levels.h"

#define OTA_TASK_STACK_SIZE (2*1024)
#define OTA_TASK_STACK_SIZE (3*1024)
#define OTA_TASK_PRIORITY 8

/* Logging configuration for the Demo. */
Expand Down
2 changes: 1 addition & 1 deletion third_party/silabs/mqtt/stack/mqtt_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern "C" {
/**
* Output ring-buffer size, must be able to fit largest outgoing publish message topic+payloads
*/
#define MQTT_OUTPUT_RINGBUF_SIZE 256
#define MQTT_OUTPUT_RINGBUF_SIZE 512

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

0 comments on commit 3e4fd52

Please sign in to comment.