[U-Boot] [PATCH] arm: socfpga: control reboot from SRAM via env callback

Simon Goldschmidt simon.k.r.goldschmidt at gmail.com
Fri May 3 20:08:37 UTC 2019


This moves the code that enables the Boot ROM to just jump to SRAM instead
of loading SPL from the original boot source on warm reboot.

Instead of always enabling this, an environment callback for the env var
"socfpga_reboot_from_sram" is used. This way, the behaviour can be enabled
at runtime and via saved environment.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>
---

 arch/arm/mach-socfpga/misc_gen5.c | 49 +++++++++++++++++++++++++------
 include/configs/socfpga_common.h  |  5 ++++
 2 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-socfpga/misc_gen5.c b/arch/arm/mach-socfpga/misc_gen5.c
index 9865f5b5b1..db662bb22a 100644
--- a/arch/arm/mach-socfpga/misc_gen5.c
+++ b/arch/arm/mach-socfpga/misc_gen5.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <asm/io.h>
 #include <errno.h>
+#include <environment.h>
 #include <fdtdec.h>
 #include <linux/libfdt.h>
 #include <altera.h>
@@ -182,15 +183,6 @@ int arch_early_init_r(void)
 {
 	int i;
 
-	/*
-	 * Write magic value into magic register to unlock support for
-	 * issuing warm reset. The ancient kernel code expects this
-	 * value to be written into the register by the bootloader, so
-	 * to support that old code, we write it here instead of in the
-	 * reset_cpu() function just before resetting the CPU.
-	 */
-	writel(0xae9efebc, &sysmgr_regs->romcodegrp_warmramgrp_enable);
-
 	for (i = 0; i < 8; i++)	/* Cache initial SW setting regs */
 		iswgrp_handoff[i] = readl(&sysmgr_regs->iswgrp_handoff[i]);
 
@@ -255,4 +247,43 @@ void do_bridge_reset(int enable)
 		writel(1, &nic301_regs->remap);
 	}
 }
+
+/*
+ * This function controls the reboot behaviour via an environment callback to
+ * the variable "socfpga_reboot_from_sram".
+ *
+ * Setting this variable to 1 writes a magic value into a magic register that
+ * makes the Boot ROM jump to SRAM on a warm reset. Note that this doesn't
+ * happen on cold reset, and that the SPL is not CRC protected, so if it gets
+ * overwritten before boot, something bad will happen.
+ *
+ * Given these limitations, this env callback only exists for backwards
+ * compatibility.
+ */
+static int on_socfpga_reboot_from_sram(const char *name, const char *value,
+				       enum env_op op, int flags)
+{
+	int val;
+	u32 reg;
+
+	val = simple_strtoul(value, NULL, 10);
+	if (val) {
+		/*
+		 * Write magic value into magic register to unlock support for
+		 * issuing warm reset. The ancient kernel code expects this
+		 * value to be written into the register by the bootloader, so
+		 * to support that old code, we write it here instead of in the
+		 * reset_cpu() function just before resetting the CPU.
+		 */
+		reg = 0xae9efebc;
+	} else {
+		reg = 0;
+	}
+	writel(reg, &sysmgr_regs->romcodegrp_warmramgrp_enable);
+
+	return 0;
+}
+
+U_BOOT_ENV_CALLBACK(socfpga_reboot_from_sram, on_socfpga_reboot_from_sram);
+
 #endif
diff --git a/include/configs/socfpga_common.h b/include/configs/socfpga_common.h
index d1034ac280..aae4daf5d2 100644
--- a/include/configs/socfpga_common.h
+++ b/include/configs/socfpga_common.h
@@ -273,4 +273,9 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 #endif
 #endif
 
+#ifndef CONFIG_ENV_CALLBACK_LIST_STATIC
+#define CONFIG_ENV_CALLBACK_LIST_STATIC \
+	"socfpga_reboot_from_sram:socfpga_reboot_from_sram"
+#endif
+
 #endif	/* __CONFIG_SOCFPGA_COMMON_H__ */
-- 
2.20.1



More information about the U-Boot mailing list