Skip to content

Commit e39f5ca

Browse files
committed
[nrf toup] Saving boot reason on nRF54h20
-Use NRF_RESETINFO register to get boot reason Signed-off-by: Konrad Grucel <[email protected]>
1 parent 6c1a9c5 commit e39f5ca

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
extern int BootReason;
11+
12+
#endif

src/platform/Zephyr/DiagnosticDataProviderImpl.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,60 @@ 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+
#endif
58+
59+
#include <platform/SaveBootReasonDFUSuit.h>
60+
5561
namespace chip {
5662
namespace DeviceLayer {
5763

5864
namespace {
5965

6066
BootReasonType DetermineBootReason()
6167
{
62-
#ifdef CONFIG_HWINFO
68+
69+
#if defined(CONFIG_SOC_SERIES_NRF54HX) || defined(CONFIG_HWINFO)
6370
uint32_t reason;
71+
#endif
72+
ChipLogDetail(DeviceLayer, "Software Boot reason %d", BootReason);
73+
#ifdef CONFIG_SOC_SERIES_NRF54HX
74+
reason = nrf_resetinfo_resetreas_global_get(NRF_RESETINFO);
75+
76+
if (reason == RESETINFO_RESETREAS_GLOBAL_ResetValue)
77+
{
78+
return BootReasonType::kSoftwareReset;
79+
}
80+
81+
if (reason & RESETINFO_RESETREAS_GLOBAL_RESETPORONLY_Msk)
82+
{
83+
return BootReasonType::kBrownOutReset;
84+
}
85+
86+
if (reason & RESETINFO_RESETREAS_GLOBAL_DOG_Msk)
87+
{
88+
return BootReasonType::kHardwareWatchdogReset;
89+
}
90+
91+
if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk)) ==
92+
(RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk))
93+
{
94+
return BootReasonType::kPowerOnReboot;
95+
}
6496

97+
if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk)) ==
98+
(RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk))
99+
{
100+
if (BootReason == 5)
101+
{
102+
BootReason = 0;
103+
return BootReasonType::kSoftwareUpdateCompleted;
104+
}
105+
}
106+
#endif
107+
108+
#ifdef CONFIG_HWINFO
65109
if (hwinfo_get_reset_cause(&reason) != 0)
66110
{
67111
return BootReasonType::kUnspecified;

src/platform/nrfconnect/OTAImageProcessorImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#include <zephyr/logging/log.h>
4747
#include <zephyr/pm/device.h>
4848

49+
#include <platform/SaveBootReasonDFUSuit.h>
50+
int __noinit BootReason;
51+
4952
namespace chip {
5053
namespace {
5154
#ifdef CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE
@@ -182,6 +185,8 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
182185
PlatformMgr().HandleServerShuttingDown();
183186
k_msleep(CHIP_DEVICE_CONFIG_SERVER_SHUTDOWN_ACTIONS_SLEEP_MS);
184187
#ifdef CONFIG_DFU_TARGET_SUIT
188+
BootReason = 5;
189+
ChipLogDetail(DeviceLayer, "Software Boot reason %d", BootReason);
185190
dfu_target_suit_reboot();
186191
#else
187192
Reboot(SoftwareRebootReason::kSoftwareUpdate);

0 commit comments

Comments
 (0)