17
17
#include " AttestationKey.h"
18
18
#include " ProvisionStorage.h"
19
19
#include < credentials/examples/DeviceAttestationCredsExample.h>
20
+ #include < em_device.h>
20
21
#include < lib/support/BytesToHex.h>
21
22
#include < lib/support/CHIPMemString.h>
22
23
#include < lib/support/CodeUtils.h>
27
28
#include < platform/CHIPDeviceConfig.h>
28
29
#include < platform/silabs/MigrationManager.h>
29
30
#include < platform/silabs/SilabsConfig.h>
30
- #include < platform/silabs/platformAbstraction/SilabsPlatform.h>
31
31
#include < silabs_creds.h>
32
32
#ifndef NDEBUG
33
33
#if defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED) && (SL_MATTER_GN_BUILD == 0)
37
37
#ifdef OTA_ENCRYPTION_ENABLE
38
38
#include < platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
39
39
#endif // OTA_ENCRYPTION_ENABLE
40
- #ifndef SLI_SI91X_MCU_INTERFACE
40
+ #ifdef SLI_SI91X_MCU_INTERFACE
41
+ #include < sl_si91x_common_flash_intf.h>
42
+ #else
43
+ #ifdef _SILICON_LABS_32B_SERIES_2
44
+ #include < em_msc.h>
45
+ #elif defined(_SILICON_LABS_32B_SERIES_3)
46
+ #include " sl_se_manager.h"
47
+ #include " sl_se_manager_types.h"
48
+ #include < sl_se_manager_extmem.h>
49
+ #endif // _SILICON_LABS_32B_SERIES_2
41
50
#include < psa/crypto.h>
42
51
#endif
43
52
@@ -47,6 +56,16 @@ extern void setNvm3End(uint32_t addr);
47
56
#include < sl_matter_provision_config.h>
48
57
#endif
49
58
59
+ #if defined(_SILICON_LABS_32B_SERIES_3)
60
+ // To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
61
+ #define FLASH_GENERIC_MASK 0x00FFFFFF
62
+ #define GENERIC_ADDRESS (addr ) ((addr) &FLASH_GENERIC_MASK)
63
+
64
+ // Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
65
+ #define CMSIS_CONVERTED_ADDRESS (addr ) (GENERIC_ADDRESS(addr) | FLASH_BASE)
66
+ sl_se_command_context_t cmd_ctx;
67
+ #endif // _SILICON_LABS_32B_SERIES_3
68
+
50
69
extern uint8_t linker_nvm_end[];
51
70
52
71
using namespace chip ::Credentials;
@@ -67,12 +86,42 @@ size_t sCredentialsOffset = 0;
67
86
68
87
CHIP_ERROR ErasePage (uint32_t addr)
69
88
{
70
- return chip::DeviceLayer::Silabs::GetPlatform ().FlashErasePage (addr);
89
+ #ifdef SLI_SI91X_MCU_INTERFACE
90
+ rsi_flash_erase_sector ((uint32_t *) addr);
91
+ #elif defined(_SILICON_LABS_32B_SERIES_2)
92
+ MSC_ErasePage ((uint32_t *) addr);
93
+ #elif defined(_SILICON_LABS_32B_SERIES_3)
94
+ sl_status_t status;
95
+ uint32_t * data_start = NULL ;
96
+ size_t data_size;
97
+
98
+ status = sl_se_data_region_get_location (&cmd_ctx, (void **) &data_start, &data_size);
99
+ VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR (status));
100
+ VerifyOrReturnError (GENERIC_ADDRESS (addr) > GENERIC_ADDRESS ((uint32_t ) data_start), CHIP_ERROR_INVALID_ADDRESS);
101
+ status = sl_se_data_region_erase (&cmd_ctx, (void *) addr, 1 ); // Erase one page
102
+ VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR (status));
103
+ #endif
104
+ return CHIP_NO_ERROR;
71
105
}
72
106
73
107
CHIP_ERROR WritePage (uint32_t addr, const uint8_t * data, size_t size)
74
108
{
75
- return chip::DeviceLayer::Silabs::GetPlatform ().FlashWritePage (addr, data, size);
109
+ #ifdef SLI_SI91X_MCU_INTERFACE
110
+ rsi_flash_write ((uint32_t *) addr, (unsigned char *) data, size);
111
+ #elif defined(_SILICON_LABS_32B_SERIES_2)
112
+ MSC_WriteWord ((uint32_t *) addr, data, size);
113
+ #elif defined(_SILICON_LABS_32B_SERIES_3)
114
+ sl_status_t status;
115
+ uint32_t * data_start = NULL ;
116
+ size_t data_size;
117
+
118
+ status = sl_se_data_region_get_location (&cmd_ctx, (void **) &data_start, &data_size);
119
+ VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR (status));
120
+ VerifyOrReturnError (GENERIC_ADDRESS (addr) > GENERIC_ADDRESS ((uint32_t ) data_start), CHIP_ERROR_INVALID_ADDRESS);
121
+ status = sl_se_data_region_write (&cmd_ctx, (void *) addr, data, size);
122
+ VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR (status));
123
+ #endif
124
+ return CHIP_NO_ERROR;
76
125
}
77
126
78
127
size_t RoundNearest (size_t n, size_t multiple)
@@ -154,8 +203,16 @@ CHIP_ERROR Storage::Initialize(uint32_t flash_addr, uint32_t flash_size)
154
203
{
155
204
#ifndef SLI_SI91X_MCU_INTERFACE
156
205
base_addr = (flash_addr + flash_size - FLASH_PAGE_SIZE);
206
+
207
+ #ifdef _SILICON_LABS_32B_SERIES_2
208
+ MSC_Init ();
209
+ #elif defined(_SILICON_LABS_32B_SERIES_3)
210
+ sl_status_t status;
211
+ status = sl_se_init ();
212
+ VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
213
+ status = sl_se_init_command_context (&cmd_ctx);
214
+ #endif // _SILICON_LABS_32B_SERIES
157
215
#endif // SLI_SI91X_MCU_INTERFACE
158
- chip::DeviceLayer::Silabs::GetPlatform ().FlashInit ();
159
216
#ifdef SL_PROVISION_GENERATOR
160
217
setNvm3End (base_addr);
161
218
#endif
0 commit comments