Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSA-CP]Provision SPAM #90

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 5 additions & 62 deletions examples/platform/silabs/provision/ProvisionStorageDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "AttestationKey.h"
#include "ProvisionStorage.h"
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <em_device.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
Expand All @@ -28,6 +27,7 @@
#include <platform/CHIPDeviceConfig.h>
#include <platform/silabs/MigrationManager.h>
#include <platform/silabs/SilabsConfig.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
#include <silabs_creds.h>
#ifndef NDEBUG
#if defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED) && (SL_MATTER_GN_BUILD == 0)
Expand All @@ -37,16 +37,7 @@
#ifdef OTA_ENCRYPTION_ENABLE
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
#endif // OTA_ENCRYPTION_ENABLE
#ifdef SLI_SI91X_MCU_INTERFACE
#include <sl_si91x_common_flash_intf.h>
#else
#ifdef _SILICON_LABS_32B_SERIES_2
#include <em_msc.h>
#elif defined(_SILICON_LABS_32B_SERIES_3)
#include "sl_se_manager.h"
#include "sl_se_manager_types.h"
#include <sl_se_manager_extmem.h>
#endif // _SILICON_LABS_32B_SERIES_2
#ifndef SLI_SI91X_MCU_INTERFACE
#include <psa/crypto.h>
#endif

Expand All @@ -56,16 +47,6 @@ extern void setNvm3End(uint32_t addr);
#include <sl_matter_provision_config.h>
#endif

#if defined(_SILICON_LABS_32B_SERIES_3)
// To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
#define FLASH_GENERIC_MASK 0x00FFFFFF
#define GENERIC_ADDRESS(addr) ((addr) &FLASH_GENERIC_MASK)

// Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
#define CMSIS_CONVERTED_ADDRESS(addr) (GENERIC_ADDRESS(addr) | FLASH_BASE)
sl_se_command_context_t cmd_ctx;
#endif // _SILICON_LABS_32B_SERIES_3

extern uint8_t linker_nvm_end[];

using namespace chip::Credentials;
Expand All @@ -86,42 +67,12 @@ size_t sCredentialsOffset = 0;

CHIP_ERROR ErasePage(uint32_t addr)
{
#ifdef SLI_SI91X_MCU_INTERFACE
rsi_flash_erase_sector((uint32_t *) addr);
#elif defined(_SILICON_LABS_32B_SERIES_2)
MSC_ErasePage((uint32_t *) addr);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_erase(&cmd_ctx, (void *) addr, 1); // Erase one page
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
return chip::DeviceLayer::Silabs::GetPlatform().FlashErasePage(addr);
}

CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
{
#ifdef SLI_SI91X_MCU_INTERFACE
rsi_flash_write((uint32_t *) addr, (unsigned char *) data, size);
#elif defined(_SILICON_LABS_32B_SERIES_2)
MSC_WriteWord((uint32_t *) addr, data, size);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_write(&cmd_ctx, (void *) addr, data, size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
return chip::DeviceLayer::Silabs::GetPlatform().FlashWritePage(addr, data, size);
}

size_t RoundNearest(size_t n, size_t multiple)
Expand Down Expand Up @@ -203,16 +154,8 @@ CHIP_ERROR Storage::Initialize(uint32_t flash_addr, uint32_t flash_size)
{
#ifndef SLI_SI91X_MCU_INTERFACE
base_addr = (flash_addr + flash_size - FLASH_PAGE_SIZE);

#ifdef _SILICON_LABS_32B_SERIES_2
MSC_Init();
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
status = sl_se_init();
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
status = sl_se_init_command_context(&cmd_ctx);
#endif // _SILICON_LABS_32B_SERIES
#endif // SLI_SI91X_MCU_INTERFACE
chip::DeviceLayer::Silabs::GetPlatform().FlashInit();
#ifdef SL_PROVISION_GENERATOR
setNvm3End(base_addr);
#endif
Expand Down
71 changes: 69 additions & 2 deletions src/platform/silabs/platformAbstraction/GsdkSpam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
* limitations under the License.
*/

#include <em_device.h>
#include <lib/support/CodeUtils.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#if defined(_SILICON_LABS_32B_SERIES_2)
#include "em_msc.h"
#include "em_rmu.h"
#else
#elif defined(_SILICON_LABS_32B_SERIES_3)
#include "sl_hal_emu.h"
#include "sl_se_manager.h"
#include "sl_se_manager_types.h"
#include <sl_se_manager_extmem.h>
#endif // _SILICON_LABS_32B_SERIES_2
#include "sl_system_kernel.h"

Expand Down Expand Up @@ -65,6 +70,18 @@ extern "C" {
#include "silabs_utils.h"
#endif

#if defined(_SILICON_LABS_32B_SERIES_3)
// To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
#define FLASH_GENERIC_MASK 0x00FFFFFF
#define GENERIC_ADDRESS(addr) ((addr) &FLASH_GENERIC_MASK)

// Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
#define CMSIS_CONVERTED_ADDRESS(addr) (GENERIC_ADDRESS(addr) | FLASH_BASE)
namespace {
sl_se_command_context_t cmd_ctx;
}
#endif // _SILICON_LABS_32B_SERIES_3

namespace chip {
namespace DeviceLayer {
namespace Silabs {
Expand Down Expand Up @@ -107,6 +124,56 @@ CHIP_ERROR SilabsPlatform::Init(void)
return CHIP_NO_ERROR;
}

CHIP_ERROR SilabsPlatform::FlashInit()
{
#if defined(_SILICON_LABS_32B_SERIES_2)
MSC_Init();
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
status = sl_se_init();
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
status = sl_se_init_command_context(&cmd_ctx);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}

CHIP_ERROR SilabsPlatform::FlashErasePage(uint32_t addr)
{
#if defined(_SILICON_LABS_32B_SERIES_2)
MSC_ErasePage((uint32_t *) addr);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_erase(&cmd_ctx, (void *) addr, 1); // Erase one page
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}

CHIP_ERROR SilabsPlatform::FlashWritePage(uint32_t addr, const uint8_t * data, size_t size)
{
#if defined(_SILICON_LABS_32B_SERIES_2)
MSC_WriteWord((uint32_t *) addr, data, size);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_write(&cmd_ctx, (void *) addr, data, size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}

#ifdef ENABLE_WSTK_LEDS
void SilabsPlatform::InitLed(void)
{
Expand Down
4 changes: 4 additions & 0 deletions src/platform/silabs/platformAbstraction/SilabsPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class SilabsPlatform : virtual public SilabsPlatformAbstractionBase

void StartScheduler(void) override;

CHIP_ERROR FlashInit() override;
CHIP_ERROR FlashErasePage(uint32_t addr) override;
CHIP_ERROR FlashWritePage(uint32_t addr, const uint8_t * data, size_t size) override;

private:
friend SilabsPlatform & GetPlatform(void);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class SilabsPlatformAbstractionBase
virtual bool GetLedState(uint8_t led) { return 0; }
virtual CHIP_ERROR ToggleLed(uint8_t led) { return CHIP_ERROR_NOT_IMPLEMENTED; }

// Flash
virtual CHIP_ERROR FlashInit() { return CHIP_ERROR_NOT_IMPLEMENTED; }
virtual CHIP_ERROR FlashErasePage(uint32_t addr) { return CHIP_ERROR_NOT_IMPLEMENTED; }
virtual CHIP_ERROR FlashWritePage(uint32_t addr, const uint8_t * data, size_t size) { return CHIP_ERROR_NOT_IMPLEMENTED; }

// BLE Specific Method

protected:
Expand Down
19 changes: 19 additions & 0 deletions src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
#include <sl_si91x_button_pin_config.h>
#include <sl_si91x_common_flash_intf.h>

#include <FreeRTOS.h>
#include <task.h>

#include <app/icd/server/ICDServerConfig.h>
#include <lib/support/CodeUtils.h>

#include <lib/support/CodeUtils.h>
#if SILABS_LOG_ENABLED
Expand Down Expand Up @@ -192,6 +194,23 @@ uint8_t SilabsPlatform::GetButtonState(uint8_t button)
return (button < SL_SI91x_BUTTON_COUNT) ? sButtonStates[button] : 0;
}

CHIP_ERROR SilabsPlatform::FlashInit()
{
return CHIP_NO_ERROR;
}

CHIP_ERROR SilabsPlatform::FlashErasePage(uint32_t addr)
{
rsi_flash_erase_sector((uint32_t *) addr);
return CHIP_NO_ERROR;
}

CHIP_ERROR SilabsPlatform::FlashWritePage(uint32_t addr, const uint8_t * data, size_t size)
{
rsi_flash_write((uint32_t *) addr, (unsigned char *) data, size);
return CHIP_NO_ERROR;
}

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip
Loading