Skip to content

Commit 7e9d3e3

Browse files
Zach Van Campnashif
authored andcommitted
kernel: Add RESET_ON_FATAL_ERROR kconfig option
Add an optional reset when a hard fault occurs. Signed-off-by: Zach Van Camp <zach.vancamp@etcconnect.com>
1 parent 2210c0d commit 7e9d3e3

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

kernel/fatal.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/logging/log.h>
1414
#include <zephyr/fatal.h>
1515
#include <zephyr/debug/coredump.h>
16+
#include <zephyr/sys/reboot.h>
1617

1718
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
1819

@@ -37,10 +38,16 @@ __weak void k_sys_fatal_error_handler(unsigned int reason,
3738
const struct arch_esf *esf)
3839
{
3940
ARG_UNUSED(esf);
40-
4141
LOG_PANIC();
42-
LOG_ERR("Halting system");
42+
43+
#if CONFIG_RESET_ON_FATAL_ERROR
44+
LOG_ERR("Resetting system\n");
45+
sys_reboot(SYS_REBOOT_WARM);
46+
#else
47+
LOG_ERR("Halting system\n");
4348
arch_system_halt(reason);
49+
#endif /* CONFIG_RESET_ON_FATAL_ERROR */
50+
4451
CODE_UNREACHABLE;
4552
}
4653
/* LCOV_EXCL_STOP */

lib/os/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ config REBOOT
132132
needed to perform a "safe" reboot (e.g. to stop the system clock before
133133
issuing a reset).
134134

135+
config RESET_ON_FATAL_ERROR
136+
bool "Reset the system when a fatal error occurs after printing relevant debug output"
137+
select REBOOT
138+
help
139+
Initiate a system reset when a fatal error would normally halt the system.
140+
135141
config HAS_POWEROFF
136142
bool
137143
help

0 commit comments

Comments
 (0)