Skip to content

Commit 3ee4f98

Browse files
lpbeliveau-silabsrestyled-commitsCopilotmkardous-silabs
authored
[SL-UP] Boot reason update multi-platform (#585)
Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Mathieu Kardous <[email protected]>
1 parent 1bfa6ec commit 3ee4f98

File tree

12 files changed

+105
-37
lines changed

12 files changed

+105
-37
lines changed

examples/platform/silabs/MatterConfig.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
299299
ReturnErrorOnFailure(sWifiNetworkDriver.Init());
300300
#endif
301301

302+
// Verify if the platform is updated by reading the NVM3 config value. This needs to be done after the wifi network driver
303+
// initialization the 917 nvm is accessed through the TA and the communication between the M4 and the TA is available at this
304+
// point. For thread devices, this needs to be after InitChipStack.
305+
ReturnErrorOnFailure(GetPlatform().VerifyIfUpdated());
302306
// Stop Matter event handling while setting up resources
303307
chip::DeviceLayer::PlatformMgr().LockChipStack();
304308

src/platform/silabs/ConfigurationManagerImpl.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
6363
CHIP_ERROR err;
6464

6565
// Initialize the generic implementation base class.
66-
err = Internal::GenericConfigurationManagerImpl<SilabsConfig>::Init();
66+
err = GenericConfigurationManagerImpl<SilabsConfig>::Init();
6767
SuccessOrExit(err);
6868

6969
IncreaseBootCount();
@@ -104,8 +104,17 @@ CHIP_ERROR ConfigurationManagerImpl::IncreaseBootCount(void)
104104
CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason)
105105
{
106106
// rebootCause is obtained at bootup.
107+
uint32_t rebootCause = Silabs::GetPlatform().GetRebootCause();
108+
109+
// Before looking into the bootloader reboot cause, check if we performed a matter update
110+
if (rebootCause == to_underlying(BootReasonType::kSoftwareUpdateCompleted))
111+
{
112+
bootReason = to_underlying(BootReasonType::kSoftwareUpdateCompleted);
113+
return CHIP_NO_ERROR;
114+
}
115+
107116
BootReasonType matterBootCause;
108-
[[maybe_unused]] uint32_t rebootCause = Silabs::GetPlatform().GetRebootCause();
117+
109118
#if defined(_RMU_RSTCAUSE_MASK)
110119
if (rebootCause & RMU_RSTCAUSE_PORST || rebootCause & RMU_RSTCAUSE_EXTRST) // PowerOn or External pin reset
111120
{
@@ -155,14 +164,6 @@ CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason)
155164
matterBootCause = BootReasonType::kUnspecified;
156165
#endif
157166

158-
#if !SLI_SI91X_MCU_INTERFACE
159-
BootloaderResetCause_t testBootReason = bootloader_getResetReason();
160-
if (matterBootCause == BootReasonType::kUnspecified && testBootReason.reason == BOOTLOADER_RESET_REASON_GO &&
161-
testBootReason.signature == BOOTLOADER_RESET_SIGNATURE_VALID)
162-
{
163-
matterBootCause = BootReasonType::kSoftwareUpdateCompleted;
164-
}
165-
#endif
166167
bootReason = to_underlying(matterBootCause);
167168
return CHIP_NO_ERROR;
168169
}

src/platform/silabs/SiWx917/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static_library("SiWx917") {
6565
"${silabs_platform_dir}/SilabsConfig.cpp",
6666
"${silabs_platform_dir}/SilabsConfig.h",
6767
"${silabs_platform_dir}/SystemPlatformConfig.h",
68+
"${silabs_platform_dir}/platformAbstraction/SilabsPlatform.cpp",
6869
"${silabs_platform_dir}/platformAbstraction/SilabsPlatform.h",
6970
"${silabs_platform_dir}/platformAbstraction/SilabsPlatformBase.h",
7071
"${silabs_platform_dir}/platformAbstraction/WiseMcuSpam.cpp",

src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ extern "C" {
4444
uint8_t flag = RPS_HEADER;
4545
static chip::OTAImageProcessorImpl gImageProcessor;
4646

47+
using namespace chip::DeviceLayer;
4748
using namespace chip::DeviceLayer::Silabs;
49+
using namespace chip::DeviceLayer::Internal;
4850

4951
namespace chip {
5052

@@ -66,24 +68,24 @@ CHIP_ERROR OTAImageProcessorImpl::Init(OTADownloader * downloader)
6668

6769
CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
6870
{
69-
DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast<intptr_t>(this));
71+
PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast<intptr_t>(this));
7072
return CHIP_NO_ERROR;
7173
}
7274

7375
CHIP_ERROR OTAImageProcessorImpl::Finalize()
7476
{
75-
DeviceLayer::PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast<intptr_t>(this));
77+
PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast<intptr_t>(this));
7678
return CHIP_NO_ERROR;
7779
}
7880
CHIP_ERROR OTAImageProcessorImpl::Apply()
7981
{
80-
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
82+
PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
8183
return CHIP_NO_ERROR;
8284
}
8385

8486
CHIP_ERROR OTAImageProcessorImpl::Abort()
8587
{
86-
DeviceLayer::PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast<intptr_t>(this));
88+
PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast<intptr_t>(this));
8789
return CHIP_NO_ERROR;
8890
}
8991

@@ -101,7 +103,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)
101103
ChipLogError(SoftwareUpdate, "Cannot set block data: %" CHIP_ERROR_FORMAT, err.Format());
102104
}
103105

104-
DeviceLayer::PlatformMgr().ScheduleWork(HandleProcessBlock, reinterpret_cast<intptr_t>(this));
106+
PlatformMgr().ScheduleWork(HandleProcessBlock, reinterpret_cast<intptr_t>(this));
105107
return CHIP_NO_ERROR;
106108
}
107109

@@ -127,7 +129,7 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()
127129

128130
uint32_t currentVersion;
129131
uint32_t targetVersion = requestor->GetTargetVersion();
130-
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion));
132+
ReturnErrorOnFailure(ConfigurationMgr().GetSoftwareVersion(currentVersion));
131133
if (currentVersion != targetVersion)
132134
{
133135
ChipLogError(SoftwareUpdate, "Current software version = %" PRIu32 ", expected software version = %" PRIu32, currentVersion,
@@ -165,7 +167,7 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
165167

166168
#if CHIP_CONFIG_ENABLE_ICD_SERVER
167169
// Setting the device in high performance - no-sleep mode during OTA tranfer
168-
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
170+
WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
169171
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/
170172

171173
imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR);
@@ -204,7 +206,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
204206

205207
#if CHIP_CONFIG_ENABLE_ICD_SERVER
206208
// Setting the device back to power save mode when transfer is completed successfully
207-
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
209+
WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
208210
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/
209211

210212
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
@@ -215,21 +217,22 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
215217
ChipLogProgress(SoftwareUpdate, "OTAImageProcessorImpl::HandleApply()");
216218

217219
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
220+
PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
219221

220222
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully in HandleApply");
221223

222224
#if CHIP_CONFIG_ENABLE_ICD_SERVER
223225
// Setting the device is in high performace - no-sleepy mode before soft reset as soft reset is not happening in sleep mode
224-
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
226+
WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
225227
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/
226228

227229
if (mReset)
228230
{
229231
ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete");
230232
// send system reset request to reset the MCU and upgrade the m4 image
231233
ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!");
232-
// Reboots the device
234+
// Write that we are rebooting after a software update and reboot the device
235+
SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_MatterUpdateReboot, true);
233236
GetPlatform().SoftwareReset();
234237
}
235238
}
@@ -244,7 +247,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context)
244247

245248
#if CHIP_CONFIG_ENABLE_ICD_SERVER
246249
// Setting the device back to power save mode when transfer is aborted in the middle
247-
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
250+
WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
248251
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/
249252

250253
// Not clearing the image storage area as it is done during each write

src/platform/silabs/SilabsConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class SilabsConfig
189189
static constexpr Key kConfigKey_OpKeyMap = SilabsConfigKey(kMatterConfig_KeyBase, 0x20);
190190
static constexpr Key kConfigKey_BootCount = SilabsConfigKey(kMatterConfig_KeyBase, 0x21);
191191
static constexpr Key kConfigKey_TotalOperationalHours = SilabsConfigKey(kMatterConfig_KeyBase, 0x22);
192+
static constexpr Key kConfigKey_MatterUpdateReboot = SilabsConfigKey(kMatterConfig_KeyBase, 0x23);
192193

193194
static constexpr Key kConfigKey_GroupKeyMax =
194195
SilabsConfigKey(kMatterConfig_KeyBase, 0x1E); // Allows 16 Group Keys to be created.

src/platform/silabs/efr32/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static_library("efr32") {
6363
"${silabs_platform_dir}/SilabsConfig.h",
6464
"${silabs_platform_dir}/SystemPlatformConfig.h",
6565
"${silabs_platform_dir}/platformAbstraction/GsdkSpam.cpp",
66+
"${silabs_platform_dir}/platformAbstraction/SilabsPlatform.cpp",
6667
"${silabs_platform_dir}/platformAbstraction/SilabsPlatform.h",
6768
"${silabs_platform_dir}/platformAbstraction/SilabsPlatformBase.h",
6869
"../../FreeRTOS/SystemTimeSupport.cpp",

src/platform/silabs/efr32/OTAImageProcessorImpl.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ using TimeTraceOperation = chip::Tracing::Silabs::TimeTraceOperation;
6767

6868
static chip::OTAImageProcessorImpl gImageProcessor;
6969

70+
using namespace chip::DeviceLayer;
71+
using namespace chip::DeviceLayer::Internal;
72+
7073
namespace chip {
7174

7275
// Define static memebers
@@ -86,24 +89,24 @@ CHIP_ERROR OTAImageProcessorImpl::Init(OTADownloader * downloader)
8689

8790
CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
8891
{
89-
DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast<intptr_t>(this));
92+
PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast<intptr_t>(this));
9093
return CHIP_NO_ERROR;
9194
}
9295

9396
CHIP_ERROR OTAImageProcessorImpl::Finalize()
9497
{
95-
DeviceLayer::PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast<intptr_t>(this));
98+
PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast<intptr_t>(this));
9699
return CHIP_NO_ERROR;
97100
}
98101
CHIP_ERROR OTAImageProcessorImpl::Apply()
99102
{
100-
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
103+
PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
101104
return CHIP_NO_ERROR;
102105
}
103106

104107
CHIP_ERROR OTAImageProcessorImpl::Abort()
105108
{
106-
DeviceLayer::PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast<intptr_t>(this));
109+
PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast<intptr_t>(this));
107110
return CHIP_NO_ERROR;
108111
}
109112

@@ -122,7 +125,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)
122125
return err;
123126
}
124127

125-
DeviceLayer::PlatformMgr().ScheduleWork(HandleProcessBlock, reinterpret_cast<intptr_t>(this));
128+
PlatformMgr().ScheduleWork(HandleProcessBlock, reinterpret_cast<intptr_t>(this));
126129
return CHIP_NO_ERROR;
127130
}
128131

@@ -148,7 +151,7 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()
148151

149152
uint32_t currentVersion;
150153
uint32_t targetVersion = requestor->GetTargetVersion();
151-
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion));
154+
ReturnErrorOnFailure(ConfigurationMgr().GetSoftwareVersion(currentVersion));
152155
if (currentVersion != targetVersion)
153156
{
154157
ChipLogError(SoftwareUpdate, "Current software version = %" PRIu32 ", expected software version = %" PRIu32, currentVersion,
@@ -262,14 +265,14 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
262265
void OTAImageProcessorImpl::LockRadioProcessing()
263266
{
264267
#if !SL_WIFI && defined(_SILICON_LABS_32B_SERIES_3)
265-
DeviceLayer::ThreadStackMgr().LockThreadStack();
268+
ThreadStackMgr().LockThreadStack();
266269
#endif // SL_WIFI
267270
}
268271

269272
void OTAImageProcessorImpl::UnlockRadioProcessing()
270273
{
271274
#if !SL_WIFI && defined(_SILICON_LABS_32B_SERIES_3)
272-
DeviceLayer::ThreadStackMgr().UnlockThreadStack();
275+
ThreadStackMgr().UnlockThreadStack();
273276
#endif // SL_WIFI
274277
}
275278

@@ -281,7 +284,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
281284
SILABS_TRACE_BEGIN(TimeTraceOperation::kImageVerification);
282285

283286
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
284-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
287+
PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
285288
#if SL_BTLCTRL_MUX
286289
err = sl_wfx_host_pre_bootloader_spi_transfer();
287290
if (err != SL_STATUS_OK)
@@ -357,7 +360,8 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
357360
osDelay(100); // sl-temp: delay for uart print before reboot
358361
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
359362
LockRadioProcessing();
360-
// This reboots the device
363+
// Write that we are rebooting after a software update and reboot the device
364+
SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_MatterUpdateReboot, true);
361365
WRAP_BL_DFU_CALL(bootloader_rebootAndInstall())
362366
UnlockRadioProcessing(); // Unneccessay but for good measure
363367
}

src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context)
430430
#if (defined(_SILICON_LABS_32B_SERIES_3) || defined(SLI_SI91X_MCU_INTERFACE)) && CHIP_PROGRESS_LOGGING
431431
osDelay(500); // sl-temp: delay for uart print before reboot
432432
#endif
433-
// This reboots the device
433+
// Write that we are rebooting after a software update and reboot the device
434+
SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_MatterUpdateReboot, true);
434435
#ifdef SLI_SI91X_MCU_INTERFACE // 917 SoC reboot
435436
chip::DeviceLayer::Silabs::GetPlatform().SoftwareReset();
436437
#else // EFR reboot

src/platform/silabs/platformAbstraction/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ config("platform_abstraction_includes") {
2020

2121
source_set("common") {
2222
sources = [
23+
"${chip_root}/src/platform/silabs/platformAbstraction/SilabsPlatform.cpp",
2324
"${chip_root}/src/platform/silabs/platformAbstraction/SilabsPlatform.h",
2425
"${chip_root}/src/platform/silabs/platformAbstraction/SilabsPlatformBase.h",
2526
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// Common platform methods go here
19+
20+
#include <lib/support/CodeUtils.h>
21+
#include <platform/DiagnosticDataProvider.h>
22+
#include <platform/silabs/SilabsConfig.h>
23+
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
24+
25+
namespace chip {
26+
namespace DeviceLayer {
27+
namespace Silabs {
28+
29+
CHIP_ERROR SilabsPlatform::VerifyIfUpdated()
30+
{
31+
bool performedUpdate = false;
32+
CHIP_ERROR err =
33+
Internal::SilabsConfig::ReadConfigValue(Internal::SilabsConfig::kConfigKey_MatterUpdateReboot, performedUpdate);
34+
VerifyOrReturnLogError(CHIP_NO_ERROR == err || CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err, err);
35+
if (performedUpdate)
36+
{
37+
Internal::SilabsConfig::ClearConfigValue(Internal::SilabsConfig::kConfigKey_MatterUpdateReboot);
38+
mRebootCause = to_underlying(BootReasonType::kSoftwareUpdateCompleted);
39+
}
40+
41+
return CHIP_NO_ERROR;
42+
}
43+
44+
} // namespace Silabs
45+
} // namespace DeviceLayer
46+
} // namespace chip

0 commit comments

Comments
 (0)