[PATCH] reset-source: pass reset reason to kernel via device tree

Philipp Zabel p.zabel at pengutronix.de
Mon Mar 19 04:57:14 PDT 2018


Add a device tree fixup that adds a /chosen/barebox-reset-reason string
property to the device tree chosen node. It can be read under Linux in
/sys/firmware/devicetree/base/chosen/barebox-reset-reason.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 Documentation/user/reset-reason.rst |  3 +++
 common/reset_source.c               | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/Documentation/user/reset-reason.rst b/Documentation/user/reset-reason.rst
index 26d37f86dd..26022ba6d7 100644
--- a/Documentation/user/reset-reason.rst
+++ b/Documentation/user/reset-reason.rst
@@ -45,3 +45,6 @@ The following values can help to detect the reason why the bootloader runs:
 It depends on your board/SoC and its features if the hardware is able to detect
 these reset reasons. Most of the time only ``POR`` and ``RST`` are supported
 but often ``WDG`` as well.
+
+The reset reason is passed to the kernel via the device tree property string
+``/chosen/barebox-reset-reason``.
diff --git a/common/reset_source.c b/common/reset_source.c
index 06e2ca85f5..e14ba3fc16 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -77,3 +77,25 @@ unsigned int of_get_reset_source_priority(struct device_node *node)
 
 	return priority;
 }
+
+#ifdef CONFIG_OFTREE
+static int reset_source_of_fixup(struct device_node *root, void *context)
+{
+	struct device_node *node;
+
+	node = of_create_node(root, "/chosen");
+	if (!node)
+		return -ENOMEM;
+
+	return of_property_write_string(node, "barebox-reset-reason",
+			reset_src_names[reset_source]);
+}
+
+static int reset_source_register_of_fixup(void)
+{
+	of_register_fixup(reset_source_of_fixup, NULL);
+
+	return 0;
+}
+late_initcall(reset_source_register_of_fixup);
+#endif
-- 
2.16.1




More information about the barebox mailing list