From 3c3a7b0969780368281cad4a12a349cc2dda88a2 Mon Sep 17 00:00:00 2001
From: Piotr Kubik <piotr.kubik@iopsys.eu>
Date: Tue, 22 Mar 2022 16:16:24 +0100
Subject: [PATCH] iopsys-ramips: pstore: Enable PSTORE support

Enable pstore-fs kernel support for ex400.
Reservation a memory range at the end of
system memory (0x0ff80000-0x1000000) for PSTORE.

refs #5002
---
 iopsys-ramips/dts/mt7621_ex400.dts    |  3 +++
 iopsys-ramips/dts/mt7621_rsvdmem.dtsi | 22 ++++++++++++++++++++++
 iopsys-ramips/mt7621/config-5.4       | 10 ++++++++++
 3 files changed, 35 insertions(+)
 create mode 100644 iopsys-ramips/dts/mt7621_rsvdmem.dtsi

diff --git a/iopsys-ramips/dts/mt7621_ex400.dts b/iopsys-ramips/dts/mt7621_ex400.dts
index 84f5b7bfa..53e7028bd 100644
--- a/iopsys-ramips/dts/mt7621_ex400.dts
+++ b/iopsys-ramips/dts/mt7621_ex400.dts
@@ -18,6 +18,9 @@
 		reg = <0x0 0x10000000>;
 	};
 
+	/* memory reservations */
+	#include "mt7621_rsvdmem.dtsi"
+
 	chosen {
 		bootargs = "console=ttyS0,115200";
 	};
diff --git a/iopsys-ramips/dts/mt7621_rsvdmem.dtsi b/iopsys-ramips/dts/mt7621_rsvdmem.dtsi
new file mode 100644
index 000000000..a23c3cde9
--- /dev/null
+++ b/iopsys-ramips/dts/mt7621_rsvdmem.dtsi
@@ -0,0 +1,22 @@
+/*
+ * MT7621 reserved memory dtsi template
+ */
+
+/* Reserve 512 KiB at the end of free memory*/
+#define MT7621_MEM_END             0x10000000
+#define PSTORE_RSRVD_MEM_SIZE      0x80000
+#define PSTORE_RSRVD_MEM_ADDR (MT7621_MEM_END - PSTORE_RSRVD_MEM_SIZE)
+
+reserved-memory {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges;
+	pstore: pstore {
+		compatible = "ramoops";
+		reg = <PSTORE_RSRVD_MEM_ADDR PSTORE_RSRVD_MEM_SIZE>;
+		record-size = <0x20000>;		/* 128KiB per record */
+		console-size = <0x20000>;		/* 128KiB for console */
+		pmsg-size = <0x1000>; 			/* 4KiB for user data */
+		ecc-size = <16>;
+    };
+};
diff --git a/iopsys-ramips/mt7621/config-5.4 b/iopsys-ramips/mt7621/config-5.4
index 1c9a3784e..80acf66a8 100644
--- a/iopsys-ramips/mt7621/config-5.4
+++ b/iopsys-ramips/mt7621/config-5.4
@@ -213,6 +213,16 @@ CONFIG_POSIX_MQUEUE_SYSCTL=y
 CONFIG_POWER_RESET=y
 CONFIG_POWER_RESET_GPIO=y
 CONFIG_POWER_SUPPLY=y
+CONFIG_PSTORE=y
+# CONFIG_PSTORE_842_COMPRESS is not set
+CONFIG_PSTORE_CONSOLE=y
+# CONFIG_PSTORE_DEFLATE_COMPRESS is not set
+# CONFIG_PSTORE_LZ4HC_COMPRESS is not set
+# CONFIG_PSTORE_LZ4_COMPRESS is not set
+# CONFIG_PSTORE_LZO_COMPRESS is not set
+CONFIG_PSTORE_PMSG=y
+CONFIG_PSTORE_RAM=y
+# CONFIG_PSTORE_ZSTD_COMPRESS is not set
 CONFIG_QUEUED_RWLOCKS=y
 CONFIG_QUEUED_SPINLOCKS=y
 CONFIG_RALINK=y
-- 
GitLab