-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nrfconnect] Improve SoftwareUpdateCompleted boot reason detection (#…
…21851) The existing code relies on a specific bootloader mode to detect that the last reboot was due to software update. This method will not work correctly if a user chooses a different bootloader mode, or clears the "tentative" flag in the current firmware image before the diagnostic data provider is initialized. Store the software reboot reason explicitly in one of the retention registers on nRF SOCs. Signed-off-by: Damian Krolik <[email protected]> Signed-off-by: Damian Krolik <[email protected]>
- Loading branch information
1 parent
79f7809
commit 815902c
Showing
5 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "Reboot.h" | ||
|
||
#include <lib/support/TypeTraits.h> | ||
|
||
#include <zephyr/sys/reboot.h> | ||
|
||
#ifndef CONFIG_ARCH_POSIX | ||
#include <hal/nrf_power.h> | ||
#endif | ||
|
||
namespace chip { | ||
namespace DeviceLayer { | ||
|
||
#ifdef CONFIG_ARCH_POSIX | ||
|
||
void Reboot(SoftwareRebootReason reason) | ||
{ | ||
sys_reboot(SYS_REBOOT_WARM); | ||
} | ||
|
||
SoftwareRebootReason GetSoftwareRebootReason() | ||
{ | ||
return SoftwareRebootReason::kOther; | ||
} | ||
|
||
#else | ||
|
||
using RetainedReason = decltype(nrf_power_gpregret_get(NRF_POWER)); | ||
|
||
constexpr RetainedReason EncodeReason(SoftwareRebootReason reason) | ||
{ | ||
// Set MSB to avoid collission with Zephyr's pre-defined reboot reasons. | ||
constexpr RetainedReason kCustomReasonFlag = 0x80; | ||
|
||
return static_cast<RetainedReason>(reason) | kCustomReasonFlag; | ||
} | ||
|
||
void Reboot(SoftwareRebootReason reason) | ||
{ | ||
const RetainedReason retainedReason = EncodeReason(reason); | ||
|
||
// The parameter passed to sys_reboot() is retained in GPREGRET (general-purpose | ||
// retention register) on nRF52 SOC family, but nRF53 ignores the parameter, so | ||
// set it manually. | ||
|
||
#ifdef CONFIG_SOC_SERIES_NRF53X | ||
nrf_power_gpregret_set(NRF_POWER, retainedReason); | ||
#endif | ||
|
||
sys_reboot(retainedReason); | ||
} | ||
|
||
SoftwareRebootReason GetSoftwareRebootReason() | ||
{ | ||
switch (nrf_power_gpregret_get(NRF_POWER)) | ||
{ | ||
case EncodeReason(SoftwareRebootReason::kSoftwareUpdate): | ||
nrf_power_gpregret_set(NRF_POWER, 0); | ||
return SoftwareRebootReason::kSoftwareUpdate; | ||
default: | ||
return SoftwareRebootReason::kOther; | ||
} | ||
} | ||
|
||
#endif | ||
|
||
} // namespace DeviceLayer | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace chip { | ||
namespace DeviceLayer { | ||
|
||
enum class SoftwareRebootReason : uint8_t | ||
{ | ||
kSoftwareUpdate, | ||
kOther | ||
}; | ||
|
||
[[noreturn]] void Reboot(SoftwareRebootReason reason); | ||
SoftwareRebootReason GetSoftwareRebootReason(); | ||
|
||
} // namespace DeviceLayer | ||
} // namespace chip |