[U-Boot] [PATCH 5/5] nios2: relocate dtb for separated device tree

Thomas Chou thomas at wytron.com.tw
Fri Sep 4 05:15:26 CEST 2015


The relocation of nios2 is different. We will need to move
dtb at the end of u-boot-dtb.bin image away from BSS sections.
Otherwise it will be zeroed during startup.

Signed-off-by: Thomas Chou <thomas at wytron.com.tw>
---
 arch/nios2/cpu/fdt.c   | 20 +++++++++++++++++++-
 arch/nios2/cpu/start.S | 10 ++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/arch/nios2/cpu/fdt.c b/arch/nios2/cpu/fdt.c
index 79f72aa..83d95ba 100644
--- a/arch/nios2/cpu/fdt.c
+++ b/arch/nios2/cpu/fdt.c
@@ -11,9 +11,11 @@
  */
 
 #include <common.h>
+#include <libfdt.h>
+#include <asm/sections.h>
+#include <linux/ctype.h>
 
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
-#include <libfdt.h>
 #include <fdt_support.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -36,3 +38,19 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 	fdt_fixup_ethernet(blob);
 }
 #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */
+
+#ifdef CONFIG_OF_SEPARATE
+void relocate_dtb(ulong cur_start)
+{
+	/* This will be called from start.S .
+	 * As dtb is located at the end of u-boot-dtb.bin image,
+	 * we will need to relocate it before zeroing the bss.
+	 * The dtb is moved from _edata to _end, which is markuped
+	 * to __bss_end. Here _end will be used by fdtdec_setup().
+	 */
+	void *blob = (void *)(cur_start + (ulong)_edata - (ulong)_start);
+
+	if (fdt_magic(blob) == FDT_MAGIC)
+		memmove(_end, blob, fdt_totalsize(blob));
+}
+#endif /* CONFIG_OF_SEPARATE */
diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S
index dde80f7..58e6826 100644
--- a/arch/nios2/cpu/start.S
+++ b/arch/nios2/cpu/start.S
@@ -96,6 +96,16 @@ _reloc:
 	stw	r0, 4(sp)
 	mov	fp, sp
 
+#ifdef CONFIG_OF_SEPARATE
+	/* RELOCATE DTB -- relocate dtb in u-boot-dtb.bin image
+	 * to be used by fdtdec_setup().
+	 */
+	mov	r4, r8			/* r8 <- cur _start */
+	movhi	r2, %hi(relocate_dtb at h)
+	ori	r2, r2, %lo(relocate_dtb at h)
+	callr	r2
+#endif
+
 	/* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
 	 * and between __bss_start and __bss_end.
 	 */
-- 
2.1.4



More information about the U-Boot mailing list