Skip to content

Commit 9bf202b

Browse files
[NXP] Fix BootReason for successful OTA (project-chip#41957)
* [nxp][platform][common] Add App nvm keys to NXPConfig * Add App keys to be used for custom application nvm values set at runtime. * Add App OTA done key. * Update ValidConfigKey to account for new keys. Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][platform][mcxw71] Add App nvm keys to K32W1Config * Add App keys to be used for custom application nvm values set at runtime. * Add App OTA done key. * Update ValidConfigKey to account for new keys. Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][platform][mcxw7x] Update DetermineBootReason for successful OTA * Add read/write ota done nvm key in order to set kSoftwareUpdateCompleted boot reason. Signed-off-by: Andrei Menzopol <[email protected]> * Restyled by clang-format * [nxp][platform][mcxw71] Resolve conversations * Added more specific messages * Don't return error when read doesn't find key * Return error when failing to write Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][platform][mcxw71] Minimize usage of err in ConfigurationManagerImpl Signed-off-by: Andrei Menzopol <[email protected]> * Restyled by clang-format --------- Signed-off-by: Andrei Menzopol <[email protected]> Co-authored-by: Restyled.io <[email protected]>
1 parent b546ea8 commit 9bf202b

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed

src/platform/nxp/common/NXPConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ bool NXPConfig::ValidConfigKey(Key key)
565565
{
566566
// Returns true if the key is in the valid CHIP Config PDM key range.
567567

568-
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVS))
568+
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_App))
569569
{
570570
return true;
571571
}

src/platform/nxp/common/NXPConfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class NXPConfig
8181
* runtime. Retained during factory reset. */
8282
static constexpr uint8_t kFileId_KVS = CATEGORY_BASE + 3; /**< Category containing KVS set at runtime.
8383
* Cleared during factory reset. */
84+
static constexpr uint8_t kFileId_App = CATEGORY_BASE + 4; /**< Category containing custom application values set at runtime.
85+
* Cleared during factory reset. */
8486

8587
using Key = uint16_t;
8688

@@ -146,6 +148,9 @@ class NXPConfig
146148
static constexpr Key kConfigKey_GroupKeyMax = config_key(kFileId_ChipConfig, 0x1E);
147149
; // Allows 16 Group Keys to be created.
148150

151+
// Application Custom Keys
152+
static constexpr Key kConfigKey_AppOTADone = config_key(kFileId_App, 0x00);
153+
149154
// Set key id limits for each group.
150155
static constexpr Key kMinConfigKey_ChipFactory = config_key(kFileId_ChipFactory, 0x00);
151156
static constexpr Key kMaxConfigKey_ChipFactory = config_key(kFileId_ChipFactory, 0x08);
@@ -155,6 +160,8 @@ class NXPConfig
155160
static constexpr Key kMaxConfigKey_ChipCounter = config_key(kFileId_ChipCounter, 0x1F); // Allows 32 Counters to be created.
156161
static constexpr Key kMinConfigKey_KVS = config_key(kFileId_KVS, 0x00);
157162
static constexpr Key kMaxConfigKey_KVS = config_key(kFileId_KVS, 0xFF);
163+
static constexpr Key kMinConfigKey_App = config_key(kFileId_App, 0x00);
164+
static constexpr Key kMaxConfigKey_App = config_key(kFileId_App, 0xFF);
158165

159166
static CHIP_ERROR Init(void);
160167

src/platform/nxp/common/NXPConfigKS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ bool NXPConfig::ValidConfigKey(Key key)
450450
{
451451
// Returns true if the key is in the valid CHIP Config PDM key range.
452452

453-
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVS))
453+
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_App))
454454
{
455455
return true;
456456
}

src/platform/nxp/common/NXPConfigNVS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ CHIP_ERROR NXPConfig::FactoryResetConfig(void)
397397
bool NXPConfig::ValidConfigKey(Key key)
398398
{
399399
// Returns true if the key is in the valid CHIP Config PDM key range.
400-
return (key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVS);
400+
return (key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_App);
401401
}
402402

403403
void NXPConfig::RunConfigUnitTest(void) {}

src/platform/nxp/mcxw71/ConfigurationManagerImpl.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,20 @@ CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint32_t reason)
6363
{
6464
bootReason = BootReasonType::kSoftwareReset;
6565
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
66-
OtaImgState_t img_state = OTA_GetImgState();
67-
if (img_state == OtaImgState_RunCandidate)
66+
CHIP_ERROR err = CHIP_NO_ERROR;
67+
bool otaDone = false;
68+
69+
err = ReadConfigValue(NXPConfig::kConfigKey_AppOTADone, otaDone);
70+
if (err != CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
71+
{
72+
SuccessOrLog(err, DeviceLayer, "Failed to read OTA completion flag");
73+
}
74+
75+
if (otaDone)
6876
{
6977
bootReason = BootReasonType::kSoftwareUpdateCompleted;
78+
ReturnErrorAndLogOnFailure(WriteConfigValue(NXPConfig::kConfigKey_AppOTADone, false), DeviceLayer,
79+
"Failed to store OTA completion flag");
7080
}
7181
#endif
7282
}
@@ -84,7 +94,9 @@ CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint32_t reason)
8494

8595
CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareUpdateCompleted()
8696
{
87-
/* Empty implementation*/
97+
ReturnErrorAndLogOnFailure(WriteConfigValue(NXPConfig::kConfigKey_AppOTADone, true), DeviceLayer,
98+
"Failed to store OTA completion flag");
99+
88100
return CHIP_NO_ERROR;
89101
}
90102

src/platform/nxp/mcxw71/K32W1Config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ CHIP_ERROR NXPConfig::MapRamStorageStatus(rsError rsStatus)
417417
bool NXPConfig::ValidConfigKey(Key key)
418418
{
419419
// Returns true if the key is in the valid CHIP Config PDM key range.
420-
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVSValue))
420+
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_App))
421421
{
422422
return true;
423423
}

src/platform/nxp/mcxw71/K32W1Config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class NXPConfig
6363
* Cleared during factory reset. */
6464
static constexpr uint8_t kFileId_KVSValue = 0x05; /**< Category containing KVS values set at runtime.
6565
* Cleared during factory reset. */
66+
static constexpr uint8_t kFileId_App = 0x06; /**< Category containing custom application values set at runtime.
67+
* Cleared during factory reset. */
6668

6769
using Key = uint16_t;
6870

@@ -98,6 +100,9 @@ class NXPConfig
98100
static constexpr Key kCounterKey_TotalOperationalHours = K32WConfigKey(kFileId_ChipCounter, 0x02);
99101
static constexpr Key kCounterKey_BootReason = K32WConfigKey(kFileId_ChipCounter, 0x03);
100102

103+
// Application Custom Keys
104+
static constexpr Key kConfigKey_AppOTADone = K32WConfigKey(kFileId_App, 0x00);
105+
101106
// Set key id limits for each group.
102107
static constexpr Key kMinConfigKey_ChipFactory = K32WConfigKey(kFileId_ChipFactory, 0x00);
103108
static constexpr Key kMaxConfigKey_ChipFactory = K32WConfigKey(kFileId_ChipFactory, 0xFF);
@@ -109,6 +114,8 @@ class NXPConfig
109114
static constexpr Key kMaxConfigKey_KVSKey = K32WConfigKey(kFileId_KVSKey, 0xFF);
110115
static constexpr Key kMinConfigKey_KVSValue = K32WConfigKey(kFileId_KVSValue, 0x00);
111116
static constexpr Key kMaxConfigKey_KVSValue = K32WConfigKey(kFileId_KVSValue, 0xFF);
117+
static constexpr Key kMinConfigKey_App = K32WConfigKey(kFileId_App, 0x00);
118+
static constexpr Key kMaxConfigKey_App = K32WConfigKey(kFileId_App, 0xFF);
112119

113120
static CHIP_ERROR Init(void);
114121

0 commit comments

Comments
 (0)