[PATCH 4/4] fdt: Optionally populate /chosen/reset-reason

A. Sverdlin alexander.sverdlin at siemens.com
Mon May 11 22:12:33 CEST 2026


From: Alexander Sverdlin <alexander.sverdlin at siemens.com>

Optionally populate /chosen/reset-reason using get_reset_reason() depending
on CONFIG_RESET_REASON_FDT option. Currently only TI K3 AM62x and AM64x
platforms provide a functional implementation.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin at siemens.com>
---
 boot/fdt_support.c | 14 ++++++++++++++
 include/init.h     |  3 ++-
 lib/Kconfig        |  9 +++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/boot/fdt_support.c b/boot/fdt_support.c
index 1c215e548db..d6745a73d01 100644
--- a/boot/fdt_support.c
+++ b/boot/fdt_support.c
@@ -9,6 +9,7 @@
 #include <dm.h>
 #include <abuf.h>
 #include <env.h>
+#include <init.h>
 #include <log.h>
 #include <mapmem.h>
 #include <net.h>
@@ -389,6 +390,19 @@ int fdt_chosen(void *fdt)
 		return err;
 	}
 
+	if (IS_ENABLED(CONFIG_RESET_REASON_FDT)) {
+		const char *reset_reason = get_reset_reason();
+
+		if (reset_reason) {
+			err = fdt_setprop_string(fdt, nodeoffset,
+						 "reset-reason",
+						 reset_reason);
+			if (err < 0)
+				printf("WARNING: could not set reset-reason %s.\n",
+				       fdt_strerror(err));
+		}
+	}
+
 	if (CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE)) {
 		/* Inject SMBIOS address when we have a valid address.
 		* This is useful for systems using booti/bootm instead of bootefi.
diff --git a/include/init.h b/include/init.h
index 3ee35130268..62c32ff6a65 100644
--- a/include/init.h
+++ b/include/init.h
@@ -243,7 +243,8 @@ int print_cpuinfo(void);
  * get_reset_reason() - return a string describing the reset cause
  *
  * Platforms can override this weak function to provide the actual
- * reset reason.
+ * reset reason. The returned string may be used to populate
+ * /chosen/reset-reason when CONFIG_RESET_REASON_FDT is enabled.
  *
  * Return: reason string, or NULL if unknown/unsupported
  */
diff --git a/lib/Kconfig b/lib/Kconfig
index 77ebc79e1db..4178e95b94b 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -1130,6 +1130,15 @@ config VPL_OF_LIBFDT_ASSUME_MASK
 	  0xff means all assumptions are made and any invalid data may cause
 	  unsafe execution. See FDT_ASSUME_PERFECT, etc. in libfdt_internal.h
 
+config RESET_REASON_FDT
+	bool "Pass reset reason to OS via device tree"
+	depends on OF_LIBFDT
+	help
+	  When enabled, U-Boot will call get_reset_reason() and store the
+	  result as a string property "reset-reason" in the /chosen node
+	  of the device tree passed to the OS. Platforms must override the
+	  weak get_reset_reason() to provide the actual reason.
+
 menu "System tables"
 	depends on (!EFI_CLIENT && !SYS_COREBOOT) || (ARM && EFI_LOADER)
 
-- 
2.52.0



More information about the U-Boot mailing list