Skip to content

Commit

Permalink
[Ameba] Restructure PersistentStorage (#17047)
Browse files Browse the repository at this point in the history
* [PersistentStorage] [Commissioning] Restructure PersistentStorage configuration to fix commissioning issue
- Key-values outside of below domains are not stored in proper domains
    "chip-factory"
    "chip-config"
    "chip-counters"
- Add more domains to be registered into DCT
- Add AmebaConfig::EnsureNamespace2 to register some domains into DCT2
- Change wrong error code in AmebaWiFiDriver::Init

* [chipinterface] Revise initialization order
- Current init order faces hardfault
- Move InitOTARequestor after Server is initialized

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 25, 2023
1 parent 8cdd8d4 commit 7052453
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 13 deletions.
8 changes: 4 additions & 4 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ static void InitOTARequestor(void)

static void InitServer(intptr_t context)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -164,6 +160,10 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

if (RTW_SUCCESS != wifi_is_connected_to_ap())
{
// QR code will be used with CHIP Tool
Expand Down
8 changes: 4 additions & 4 deletions examples/lighting-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ static Identify gIdentify1 = {

static void InitServer(intptr_t context)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -185,6 +181,10 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

if (RTW_SUCCESS != wifi_is_connected_to_ap())
{
// QR code will be used with CHIP Tool
Expand Down
4 changes: 2 additions & 2 deletions examples/ota-requestor-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ static void InitOTARequestor(void)

static void InitServer(intptr_t context)
{
InitOTARequestor();

// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -144,6 +142,8 @@ static void InitServer(intptr_t context)
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

InitOTARequestor();
}

extern "C" void ChipTest(void)
Expand Down
31 changes: 28 additions & 3 deletions src/platform/Ameba/AmebaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ namespace Internal {
// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices.

// NVS namespaces used to store device configuration information.
const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory";
const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config";
const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters";
const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory";
const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config";
const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters";
const char AmebaConfig::kConfigNamespace_ChipFabric1[] = "chip-fabric-1";
const char AmebaConfig::kConfigNamespace_ChipFabric2[] = "chip-fabric-2";
const char AmebaConfig::kConfigNamespace_ChipFabric3[] = "chip-fabric-3";
const char AmebaConfig::kConfigNamespace_ChipFabric4[] = "chip-fabric-4";
const char AmebaConfig::kConfigNamespace_ChipFabric5[] = "chip-fabric-5";
const char AmebaConfig::kConfigNamespace_ChipACL[] = "chip-acl";
const char AmebaConfig::kConfigNamespace_ChipGroupMsgCounters[] = "chip-groupmsgcounters";
const char AmebaConfig::kConfigNamespace_ChipAttributes[] = "chip-attributes";
const char AmebaConfig::kConfigNamespace_ChipBindingTable[] = "chip-bindingtable";
const char AmebaConfig::kConfigNamespace_ChipOTA[] = "chip-ota";
const char AmebaConfig::kConfigNamespace_ChipDNS[] = "chip-dns";
const char AmebaConfig::kConfigNamespace_ChipOthers[] = "chip-others";

// Keys stored in the chip-factory namespace
const AmebaConfig::Key AmebaConfig::kConfigKey_SerialNum = { kConfigNamespace_ChipFactory, "serial-num" };
Expand Down Expand Up @@ -271,6 +283,19 @@ CHIP_ERROR AmebaConfig::EnsureNamespace(const char * ns)
return CHIP_NO_ERROR;
}

CHIP_ERROR AmebaConfig::EnsureNamespace2(const char * ns)
{
int32_t success = -1;

success = registerPref2(ns);
if (success != 0)
{
ChipLogError(DeviceLayer, "dct_register_module2 failed\n");
}

return CHIP_NO_ERROR;
}

CHIP_ERROR AmebaConfig::ClearNamespace(const char * ns)
{
int32_t success = -1;
Expand Down
13 changes: 13 additions & 0 deletions src/platform/Ameba/AmebaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ class AmebaConfig
static const char kConfigNamespace_ChipFactory[];
static const char kConfigNamespace_ChipConfig[];
static const char kConfigNamespace_ChipCounters[];
static const char kConfigNamespace_ChipFabric1[];
static const char kConfigNamespace_ChipFabric2[];
static const char kConfigNamespace_ChipFabric3[];
static const char kConfigNamespace_ChipFabric4[];
static const char kConfigNamespace_ChipFabric5[];
static const char kConfigNamespace_ChipACL[];
static const char kConfigNamespace_ChipGroupMsgCounters[];
static const char kConfigNamespace_ChipAttributes[];
static const char kConfigNamespace_ChipBindingTable[];
static const char kConfigNamespace_ChipOTA[];
static const char kConfigNamespace_ChipDNS[];
static const char kConfigNamespace_ChipOthers[];

// Key definitions for well-known keys.
static const Key kConfigKey_SerialNum;
Expand Down Expand Up @@ -96,6 +108,7 @@ class AmebaConfig
static bool ConfigValueExists(Key key);

static CHIP_ERROR EnsureNamespace(const char * ns);
static CHIP_ERROR EnsureNamespace2(const char * ns);
static CHIP_ERROR ClearNamespace(const char * ns);

static void RunConfigUnitTest(void);
Expand Down
24 changes: 24 additions & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipCounters);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric1);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric2);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric3);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric4);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric5);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipACL);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipGroupMsgCounters);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipAttributes);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipBindingTable);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipOTA);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipDNS);
SuccessOrExit(err);
err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipOthers);
SuccessOrExit(err);

if (AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_RebootCount))
{
Expand Down

0 comments on commit 7052453

Please sign in to comment.