Skip to content

Commit 4680960

Browse files
serhiiSalamakhapull[bot]
authored andcommitted
[Telink] Turn off the CHIP_FACTORY_RESET_ERASE_NVS by Default (#28947)
1 parent ff62881 commit 4680960

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

config/telink/chip-module/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ endif #CHIP_FACTORY_DATA_BUILD
147147
# See config/zephyr/Kconfig for full definition
148148
config CHIP_FACTORY_RESET_ERASE_NVS
149149
bool
150-
default y
150+
default n
151151

152152
config CHIP_LOG_SIZE_OPTIMIZATION
153153
bool "Disable some detailed logs to decrease flash usage"

examples/platform/telink/common/src/AppTaskCommon.cpp

+25-35
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@
3939
#include <app/InteractionModelEngine.h>
4040
#endif
4141

42-
#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
4342
#include <zephyr/fs/nvs.h>
4443
#include <zephyr/settings/settings.h>
45-
#endif
4644

4745
using namespace chip::app;
4846

@@ -103,10 +101,11 @@ Button sThreadStartButton;
103101
k_timer sFactoryResetTimer;
104102
uint8_t sFactoryResetCntr = 0;
105103

106-
bool sIsThreadProvisioned = false;
107-
bool sIsThreadEnabled = false;
108-
bool sIsThreadAttached = false;
109-
bool sHaveBLEConnections = false;
104+
bool sIsCommissioningFailed = false;
105+
bool sIsThreadProvisioned = false;
106+
bool sIsThreadEnabled = false;
107+
bool sIsThreadAttached = false;
108+
bool sHaveBLEConnections = false;
110109

111110
#if APP_SET_DEVICE_INFO_PROVIDER
112111
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
@@ -138,9 +137,10 @@ class AppCallbacks : public AppDelegate
138137
bool isComissioningStarted;
139138

140139
public:
141-
void OnCommissioningSessionEstablishmentStarted() {}
140+
void OnCommissioningSessionEstablishmentStarted() override { sIsCommissioningFailed = false; }
142141
void OnCommissioningSessionStarted() override { isComissioningStarted = true; }
143142
void OnCommissioningSessionStopped() override { isComissioningStarted = false; }
143+
void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) override { sIsCommissioningFailed = true; }
144144
void OnCommissioningWindowClosed() override
145145
{
146146
if (!isComissioningStarted)
@@ -157,51 +157,41 @@ class AppFabricTableDelegate : public FabricTable::Delegate
157157
{
158158
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
159159
{
160-
bool isBasicCommissioningMode = chip::Server::GetInstance().GetCommissioningWindowManager().GetCommissioningMode() ==
161-
Dnssd::CommissioningMode::kEnabledBasic;
162160
ChipLogProgress(DeviceLayer, "Performing erasing of settings partition");
163161

164-
#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
165-
void * storage = nullptr;
166-
int status = settings_storage_get(&storage);
167-
168-
if (status == 0)
162+
// Do FactoryReset in case of failed commissioning to allow new pairing via BLE
163+
if (sIsCommissioningFailed)
169164
{
170-
status = nvs_clear(static_cast<nvs_fs *>(storage));
165+
chip::Server::GetInstance().ScheduleFactoryReset();
171166
}
172-
173-
if (!isBasicCommissioningMode)
167+
// TC-OPCREDS-3.6 (device doesn't need to reboot automatically after the last fabric is removed) can't use FactoryReset
168+
else
174169
{
170+
void * storage = nullptr;
171+
int status = settings_storage_get(&storage);
172+
175173
if (!status)
176174
{
177-
status = nvs_mount(static_cast<nvs_fs *>(storage));
175+
status = nvs_clear(static_cast<nvs_fs *>(storage));
178176
}
179-
}
180-
181-
if (status)
182-
{
183-
ChipLogError(DeviceLayer, "Storage clearance failed: %d", status);
184-
}
185-
#else
186-
const CHIP_ERROR err = PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset();
187177

188-
if (err != CHIP_NO_ERROR)
189-
{
190-
ChipLogError(DeviceLayer, "Factory reset failed: %" CHIP_ERROR_FORMAT, err.Format());
191-
}
178+
if (!status)
179+
{
180+
status = nvs_mount(static_cast<nvs_fs *>(storage));
181+
}
192182

193-
ConnectivityMgr().ErasePersistentInfo();
194-
#endif
195-
if (isBasicCommissioningMode)
196-
{
197-
PlatformMgr().Shutdown();
183+
if (status)
184+
{
185+
ChipLogError(DeviceLayer, "Storage clearance failed: %d", status);
186+
}
198187
}
199188
}
200189
}
201190
};
202191

203192
class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate
204193
{
194+
// Disable openthread before reset to prevent writing to NVS
205195
void OnShutDown() override
206196
{
207197
if (ThreadStackManagerImpl().IsThreadEnabled())

0 commit comments

Comments
 (0)