[PATCH 2/4] ARM: copy data if there is a region overlap

Peter Rosin peda at axentia.se
Fri Sep 17 15:39:46 PDT 2021


This is a partial revert of patch
070de908da ("ARM: remove PBL_FORCE_PIGGYDATA_COPY")

Without this copy, my SAMA5D3 board fails to start.

Fixes: 070de908da ("ARM: remove PBL_FORCE_PIGGYDATA_COPY")
Signed-off-by: Peter Rosin <peda at axentia.se>
---
 arch/arm/cpu/uncompress.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index 2250b8ccd375..d725e7c2c34d 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -45,6 +45,7 @@ extern unsigned char input_data_end[];
 void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 				  void *boarddata)
 {
+	unsigned long offset;
 	uint32_t pg_len, uncompressed_len;
 	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
 	unsigned long endmem = membase + memsize;
@@ -52,6 +53,9 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	void *pg_start, *pg_end;
 	unsigned long pc = get_pc();
 
+	/* Get offset between linked address and runtime address */
+	offset = get_runtime_offset();
+
 	/* piggy data is not relocated, so determine the bounds now */
 	pg_start = input_data + global_variable_offset();
 	pg_end = input_data_end + global_variable_offset();
@@ -77,6 +81,14 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	else
 		barebox_base = TEXT_BASE;
 
+	if (offset && old_region_overlap(pg_start, pg_len, barebox_base, pg_len * 4)) {
+		/*
+		 * copy piggydata binary to its link address
+		 */
+		memcpy(&input_data, (void *)pg_start, pg_len);
+		pg_start = (uint32_t)&input_data;
+	}
+
 	setup_c();
 
 	pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize);
-- 
2.20.1





More information about the barebox mailing list