[PATCH 1/2] board_f: fix use of GD_FLG_SKIP_RELOC

Peng Fan (OSS) peng.fan at oss.nxp.com
Wed Oct 13 11:54:44 CEST 2021


From: Peng Fan <peng.fan at nxp.com>

When dtb is padded in the end of U-Boot binary, dtb should always be
relocated whether GD_FLG_SKIP_RELOC set or not, otherwise dtb
maybe corrupted.

Need copy old gd contents to new_gd area, this may not needed on x86 or
arc, but needed for ARM64, because crt0_64.S points x18 to new_gd,
considering gd is a small area, and common/board_f.c also use new_gd,
so let's always copy it.

Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
 common/board_f.c                  | 8 ++++----
 include/asm-generic/global_data.h | 4 ++++
 lib/asm-offsets.c                 | 2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/common/board_f.c b/common/board_f.c
index 3dc0eaa59c..54a306df7d 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -621,13 +621,13 @@ static int init_post(void)
 static int reloc_fdt(void)
 {
 	if (!IS_ENABLED(CONFIG_OF_EMBED)) {
-		if (gd->flags & GD_FLG_SKIP_RELOC)
-			return 0;
 		if (gd->new_fdt) {
 			memcpy(gd->new_fdt, gd->fdt_blob,
 			       fdt_totalsize(gd->fdt_blob));
 			gd->fdt_blob = gd->new_fdt;
 		}
+		if (gd->flags & GD_FLG_SKIP_RELOC)
+			return 0;
 	}
 
 	return 0;
@@ -673,6 +673,8 @@ static int reloc_bloblist(void)
 
 static int setup_reloc(void)
 {
+	memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
+
 	if (gd->flags & GD_FLG_SKIP_RELOC) {
 		debug("Skipping relocation due to flag\n");
 		return 0;
@@ -691,8 +693,6 @@ static int setup_reloc(void)
 	gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
 #endif
 #endif
-	memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
-
 	debug("Relocation Offset is: %08lx\n", gd->reloc_off);
 	debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
 	      gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 16fd305a65..4a3f8be047 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -600,6 +600,10 @@ enum gd_flags {
 	GD_FLG_SMP_READY = 0x80000,
 };
 
+#else
+
+#define GD_FLG_SKIP_RELOC	0x00800
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_GENERIC_GBL_DATA_H */
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c691066332..de130574cd 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -43,5 +43,7 @@ int main(void)
 
 	DEFINE(GD_ENV_ADDR, offsetof(struct global_data, env_addr));
 
+	DEFINE(GD_FLAGS, offsetof(struct global_data, flags));
+
 	return 0;
 }
-- 
2.30.0



More information about the U-Boot mailing list