Skip to content

Commit cae80de

Browse files
committed
[nrf toup] Saving boot reason on nRF54h20
-Use NRF_RESETINFO register to get boot reason Signed-off-by: Konrad Grucel <konrad.grucel@nordicsemi.no>
1 parent 6c1a9c5 commit cae80de

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

src/platform/SaveBootReasonDFUSuit.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef NRF_SAVE_BOOT_REASON_H__
8+
#define NRF_SAVE_BOOT_REASON_H__
9+
10+
inline int SoftwareBootReasonSUIT __attribute__((section(".noinit")));
11+
12+
inline int getSoftwareRebootReasonSUIT()
13+
{
14+
return SoftwareBootReasonSUIT;
15+
}
16+
17+
inline void setSoftwareRebootReasonSUIT(int reason)
18+
{
19+
SoftwareBootReasonSUIT = reason;
20+
}
21+
22+
#endif

src/platform/Zephyr/DiagnosticDataProviderImpl.cpp

+51-1
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,66 @@ const size_t kMaxHeapSize = CONFIG_SRAM_BASE_ADDRESS + KB(CONFIG_SRAM_SIZE) - PO
5252

5353
#endif
5454

55+
#ifdef CONFIG_SOC_SERIES_NRF54HX
56+
#include <hal/nrf_resetinfo.h>
57+
#include <platform/SaveBootReasonDFUSuit.h>
58+
#endif
59+
5560
namespace chip {
5661
namespace DeviceLayer {
5762

5863
namespace {
5964

6065
BootReasonType DetermineBootReason()
6166
{
62-
#ifdef CONFIG_HWINFO
67+
68+
#if defined(CONFIG_SOC_SERIES_NRF54HX) || defined(CONFIG_HWINFO)
6369
uint32_t reason;
70+
#endif
71+
72+
#ifdef CONFIG_SOC_SERIES_NRF54HX
73+
74+
bool isSoftwareBootReasonSUITInitialized = false;
75+
if (!isSoftwareBootReasonSUITInitialized)
76+
{
77+
setSoftwareRebootReasonSUIT(0);
78+
isSoftwareBootReasonSUITInitialized = true;
79+
}
80+
81+
reason = nrf_resetinfo_resetreas_global_get(NRF_RESETINFO);
82+
83+
if (reason == RESETINFO_RESETREAS_GLOBAL_ResetValue)
84+
{
85+
return BootReasonType::kSoftwareReset;
86+
}
87+
88+
if (reason & RESETINFO_RESETREAS_GLOBAL_RESETPORONLY_Msk)
89+
{
90+
return BootReasonType::kBrownOutReset;
91+
}
6492

93+
if (reason & RESETINFO_RESETREAS_GLOBAL_DOG_Msk)
94+
{
95+
return BootReasonType::kHardwareWatchdogReset;
96+
}
97+
98+
if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk)) ==
99+
(RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk))
100+
{
101+
return BootReasonType::kPowerOnReboot;
102+
}
103+
104+
if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk)) ==
105+
(RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk))
106+
{
107+
if (GetSoftwareRebootReason() == SoftwareRebootReason::kSoftwareUpdate)
108+
{
109+
return BootReasonType::kSoftwareUpdateCompleted;
110+
}
111+
}
112+
#endif
113+
114+
#ifdef CONFIG_HWINFO
65115
if (hwinfo_get_reset_cause(&reason) != 0)
66116
{
67117
return BootReasonType::kUnspecified;

src/platform/nrfconnect/OTAImageProcessorImpl.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#include <zephyr/logging/log.h>
4747
#include <zephyr/pm/device.h>
4848

49+
#ifdef CONFIG_SOC_SERIES_NRF54HX
50+
#include <platform/SaveBootReasonDFUSuit.h>
51+
#endif
52+
4953
namespace chip {
5054
namespace {
5155
#ifdef CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE
@@ -182,6 +186,7 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
182186
PlatformMgr().HandleServerShuttingDown();
183187
k_msleep(CHIP_DEVICE_CONFIG_SERVER_SHUTDOWN_ACTIONS_SLEEP_MS);
184188
#ifdef CONFIG_DFU_TARGET_SUIT
189+
SetSoftwareRebootReason(SoftwareRebootReason::kSoftwareUpdate);
185190
dfu_target_suit_reboot();
186191
#else
187192
Reboot(SoftwareRebootReason::kSoftwareUpdate);

src/platform/nrfconnect/Reboot.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include <hal/nrf_power.h>
2626
#endif
2727

28+
#include <platform/SaveBootReasonDFUSuit.h>
29+
2830
namespace chip {
2931
namespace DeviceLayer {
3032

31-
#if defined(CONFIG_ARCH_POSIX) || defined(CONFIG_SOC_SERIES_NRF54HX)
33+
#if defined(CONFIG_ARCH_POSIX)
3234

3335
void Reboot(SoftwareRebootReason reason)
3436
{
@@ -40,7 +42,7 @@ SoftwareRebootReason GetSoftwareRebootReason()
4042
return SoftwareRebootReason::kOther;
4143
}
4244

43-
#else
45+
#elif !(defined(CONFIG_SOC_SERIES_NRF54HX))
4446

4547
using RetainedReason = decltype(nrf_power_gpregret_get(NRF_POWER, 0));
4648

@@ -73,6 +75,35 @@ SoftwareRebootReason GetSoftwareRebootReason()
7375
}
7476
}
7577

78+
#else
79+
80+
using RetainedReason = decltype(getSoftwareRebootReasonSUIT());
81+
82+
constexpr RetainedReason EncodeReason(SoftwareRebootReason reason)
83+
{
84+
// Set MSB to avoid collission with Zephyr's pre-defined reboot reasons.
85+
constexpr RetainedReason kCustomReasonFlag = 0x80;
86+
87+
return static_cast<RetainedReason>(reason) | kCustomReasonFlag;
88+
}
89+
90+
void SetSoftwareRebootReason(SoftwareRebootReason reason)
91+
{
92+
const RetainedReason retainedReason = EncodeReason(reason);
93+
setSoftwareRebootReasonSUIT(retainedReason);
94+
}
95+
96+
SoftwareRebootReason GetSoftwareRebootReason()
97+
{
98+
switch (getSoftwareRebootReasonSUIT())
99+
{
100+
case EncodeReason(SoftwareRebootReason::kSoftwareUpdate):
101+
setSoftwareRebootReasonSUIT(0);
102+
return SoftwareRebootReason::kSoftwareUpdate;
103+
default:
104+
return SoftwareRebootReason::kOther;
105+
}
106+
}
76107
#endif
77108

78109
} // namespace DeviceLayer

src/platform/nrfconnect/Reboot.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum class SoftwareRebootReason : uint8_t
3030

3131
[[noreturn]] void Reboot(SoftwareRebootReason reason);
3232
SoftwareRebootReason GetSoftwareRebootReason();
33+
void SetSoftwareRebootReason(SoftwareRebootReason reason);
3334

3435
} // namespace DeviceLayer
3536
} // namespace chip

0 commit comments

Comments
 (0)