[PATCH v1 01/17] rockchip: spl: fix reloc gd and FDT blob pointer

Johan Jonker jbx6244 at gmail.com
Sun May 8 17:08:09 CEST 2022


When the Rockchip function dram_init() is called in the spl.c
board_init_f() the variable gd->ram_base returns 0.
This is problematic for functions after the gd relocation.
Fix by adding ram.base to gd->ram_base in sdram.c.

After the function spl_relocate_stack_gd is called in crt0.S
the pointer gd might be relocated and BSS with the FDT blob is erased.
The pointer gd->fdt_blob is no longer valid when
enabled SPL_OF_REAL and SPL_MMC, SPL_USB_HOST or SPL_USB_GADGET.
This patch makes that FDT properties can be parsed
in the board_init_r() function.

Fix by setting this pointers simulair to board_f.c and
copy the FDT to it's new location at the end of DRAM.

Signed-off-by: Johan Jonker <jbx6244 at gmail.com>
---
 arch/arm/mach-rockchip/sdram.c |  1 +
 arch/arm/mach-rockchip/spl.c   | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/arch/arm/mach-rockchip/sdram.c b/arch/arm/mach-rockchip/sdram.c
index 705ec7ba..b5972269 100644
--- a/arch/arm/mach-rockchip/sdram.c
+++ b/arch/arm/mach-rockchip/sdram.c
@@ -198,6 +198,7 @@ int dram_init(void)
 		debug("Cannot get DRAM size: %d\n", ret);
 		return ret;
 	}
+	gd->ram_base = ram.base;
 	gd->ram_size = ram.size;
 	debug("SDRAM base=%lx, size=%lx\n",
 	      (unsigned long)ram.base, (unsigned long)ram.size);
diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c
index 30be6404..ceef9d91 100644
--- a/arch/arm/mach-rockchip/spl.c
+++ b/arch/arm/mach-rockchip/spl.c
@@ -10,6 +10,7 @@
 #include <image.h>
 #include <init.h>
 #include <log.h>
+#include <mapmem.h>
 #include <ram.h>
 #include <spl.h>
 #include <asm/arch-rockchip/bootrom.h>
@@ -149,6 +150,21 @@ void board_init_f(ulong dummy)
 	}
 	gd->ram_top = gd->ram_base + get_effective_memsize();
 	gd->ram_top = board_get_usable_ram_top(gd->ram_size);
+
+	/* Copy FDT blob from BSS to the end of DRAM */
+	if (gd->fdt_blob) {
+		gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32);
+		unsigned long fdt_addr = ALIGN_DOWN(gd->ram_top - gd->fdt_size, 16);
+
+		gd->new_fdt = map_sysmem(fdt_addr, gd->fdt_size);
+
+		debug("Reserved %lu bytes for FDT at: %08lx\n", gd->fdt_size, fdt_addr);
+
+		if (gd->new_fdt) {
+			memcpy(gd->new_fdt, gd->fdt_blob, fdt_totalsize(gd->fdt_blob));
+			gd->fdt_blob = gd->new_fdt;
+		}
+	}
 #endif
 	preloader_console_init();
 }
-- 
2.20.1



More information about the U-Boot mailing list