Skip to content

Commit

Permalink
[nrf toup] Saving boot reason on nRF54h20
Browse files Browse the repository at this point in the history
-Use NRF_RESETINFO register to get boot reason

Signed-off-by: Konrad Grucel <[email protected]>
  • Loading branch information
kg-nordicsemi committed Dec 10, 2024
1 parent 6c1a9c5 commit e39f5ca
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/platform/SaveBootReasonDFUSuit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef NRF_SAVE_BOOT_REASON_H__
#define NRF_SAVE_BOOT_REASON_H__

extern int BootReason;

#endif
46 changes: 45 additions & 1 deletion src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,60 @@ const size_t kMaxHeapSize = CONFIG_SRAM_BASE_ADDRESS + KB(CONFIG_SRAM_SIZE) - PO

#endif

#ifdef CONFIG_SOC_SERIES_NRF54HX
#include <hal/nrf_resetinfo.h>
#endif

#include <platform/SaveBootReasonDFUSuit.h>

namespace chip {
namespace DeviceLayer {

namespace {

BootReasonType DetermineBootReason()
{
#ifdef CONFIG_HWINFO

#if defined(CONFIG_SOC_SERIES_NRF54HX) || defined(CONFIG_HWINFO)
uint32_t reason;
#endif
ChipLogDetail(DeviceLayer, "Software Boot reason %d", BootReason);
#ifdef CONFIG_SOC_SERIES_NRF54HX
reason = nrf_resetinfo_resetreas_global_get(NRF_RESETINFO);

if (reason == RESETINFO_RESETREAS_GLOBAL_ResetValue)
{
return BootReasonType::kSoftwareReset;
}

if (reason & RESETINFO_RESETREAS_GLOBAL_RESETPORONLY_Msk)
{
return BootReasonType::kBrownOutReset;
}

if (reason & RESETINFO_RESETREAS_GLOBAL_DOG_Msk)
{
return BootReasonType::kHardwareWatchdogReset;
}

if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk)) ==
(RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk))
{
return BootReasonType::kPowerOnReboot;
}

if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk)) ==
(RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk))
{
if (BootReason == 5)
{
BootReason = 0;
return BootReasonType::kSoftwareUpdateCompleted;
}
}
#endif

#ifdef CONFIG_HWINFO
if (hwinfo_get_reset_cause(&reason) != 0)
{
return BootReasonType::kUnspecified;
Expand Down
5 changes: 5 additions & 0 deletions src/platform/nrfconnect/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include <zephyr/logging/log.h>
#include <zephyr/pm/device.h>

#include <platform/SaveBootReasonDFUSuit.h>
int __noinit BootReason;

namespace chip {
namespace {
#ifdef CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE
Expand Down Expand Up @@ -182,6 +185,8 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
PlatformMgr().HandleServerShuttingDown();
k_msleep(CHIP_DEVICE_CONFIG_SERVER_SHUTDOWN_ACTIONS_SLEEP_MS);
#ifdef CONFIG_DFU_TARGET_SUIT
BootReason = 5;
ChipLogDetail(DeviceLayer, "Software Boot reason %d", BootReason);
dfu_target_suit_reboot();
#else
Reboot(SoftwareRebootReason::kSoftwareUpdate);
Expand Down

0 comments on commit e39f5ca

Please sign in to comment.